initial commit
This commit is contained in:
commit
e869a1cab4
107 changed files with 9029 additions and 0 deletions
12
app/config/conf.app.yml
Normal file
12
app/config/conf.app.yml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
application:
|
||||
controllersDir : ../app/controllers/
|
||||
modelsDir : ../app/models/
|
||||
migrationsDir : ../app/migrations/
|
||||
viewsDir : ../app/views/
|
||||
pluginsDir : ../app/plugins/
|
||||
libraryDir : ../app/library/
|
||||
formsDir : ../app/forms/
|
||||
cacheDir : ../app/cache/
|
||||
sessionDir : ../app/data/sessions/
|
||||
baseUri : /
|
||||
25
app/config/conf.local.sample.yml
Normal file
25
app/config/conf.local.sample.yml
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
application:
|
||||
debug: false
|
||||
|
||||
# Database
|
||||
database:
|
||||
adapter: Mysql
|
||||
host: localhost
|
||||
username: user
|
||||
password: password
|
||||
dbname: httpcb
|
||||
charset: utf8
|
||||
|
||||
# OAuth
|
||||
#oauth:
|
||||
#security_salt: value
|
||||
#debug: 1
|
||||
|
||||
#Strategy:
|
||||
# Google:
|
||||
# client_id: value
|
||||
# client_secret: value
|
||||
# GitHub:
|
||||
# client_id: value
|
||||
# client_secret: value
|
||||
15
app/config/config.php
Normal file
15
app/config/config.php
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
use Phalcon\Config\Adapter\Yaml as Config;
|
||||
|
||||
$config = new Config(APP_PATH . '/app/config/conf.app.yml');
|
||||
|
||||
try {
|
||||
$local = new Config(APP_PATH . '/app/config/conf.local.yml');
|
||||
|
||||
$config->merge($local);
|
||||
} catch(Phalcon\Config\Exception $e) {
|
||||
// Sometime went wrong.
|
||||
}
|
||||
|
||||
return $config;
|
||||
21
app/config/loader.php
Normal file
21
app/config/loader.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
$loader = new \Phalcon\Loader();
|
||||
|
||||
/**
|
||||
* We're a registering a set of directories taken from the configuration file
|
||||
*/
|
||||
$loader->registerDirs(
|
||||
array(
|
||||
$config->application->controllersDir,
|
||||
$config->application->libraryDir,
|
||||
$config->application->pluginsDir
|
||||
)
|
||||
)->register();
|
||||
|
||||
$loader->registerNamespaces(array(
|
||||
'Model' => $config->application->modelsDir,
|
||||
'Form' => $config->application->formsDir,
|
||||
));
|
||||
|
||||
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||
330
app/config/services.php
Normal file
330
app/config/services.php
Normal file
|
|
@ -0,0 +1,330 @@
|
|||
<?php
|
||||
/**
|
||||
* Services are globally registered in this file
|
||||
*
|
||||
* @var \Phalcon\Config $config
|
||||
*/
|
||||
|
||||
use Phalcon\Di\FactoryDefault;
|
||||
use Phalcon\Mvc\View;
|
||||
use Phalcon\Assets\Manager as AssetsManager;
|
||||
use Phalcon\Mvc\Url as UrlResolver;
|
||||
use Phalcon\Mvc\View\Engine\Volt as VoltEngine;
|
||||
use Navigation\Navigation;
|
||||
use Phalcon\Flash\Direct as FlashDirect;
|
||||
use Phalcon\Mvc\Model\Metadata\Memory as MemoryMetaData;
|
||||
use Phalcon\Mvc\Model\MetaData\Apc as ApcMetaData;
|
||||
use Phalcon\Cache\Frontend\Data as FrontendDataCache;
|
||||
use Phalcon\Cache\Backend\Apc as BackendApcCache;
|
||||
use Phalcon\Translate\Adapter\NativeArray as TranslateAdapter;
|
||||
use Phalcon\Logger;
|
||||
use Phalcon\Logger\Adapter\Firephp as FirephpAdapter;
|
||||
use Phalcon\Session\Adapter\Files as SessionAdapter;
|
||||
use Phalcon\Mvc\Router;
|
||||
|
||||
/**
|
||||
* The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework
|
||||
*/
|
||||
$di = new FactoryDefault();
|
||||
|
||||
/**
|
||||
* Setup logging
|
||||
*/
|
||||
$di->setShared('logger', function() {
|
||||
|
||||
//return new Phalcon\Logger\Adapter\Firephp("");
|
||||
return new Phalcon\Logger\Adapter\File(APP_PATH . "/app/log.txt");
|
||||
});
|
||||
|
||||
$di->setShared('dispatcher', function() use ($di, $config) {
|
||||
|
||||
$eventsManager = new Phalcon\Events\Manager();
|
||||
|
||||
$eventsManager->attach("dispatch", function($event, $dispatcher) {
|
||||
$actionName = Phalcon\Text::camelize($dispatcher->getActionName());
|
||||
$dispatcher->setActionName($actionName);
|
||||
});
|
||||
|
||||
if ($config->application->debug == false) {
|
||||
$eventsManager->attach('dispatch:beforeException', new \ExceptionHandlerPlugin());
|
||||
}
|
||||
|
||||
$eventsManager->attach('dispatch:beforeExecuteRoute', new \AclPlugin());
|
||||
|
||||
$dispatcher = new \Phalcon\Mvc\Dispatcher();
|
||||
$dispatcher->setEventsManager($eventsManager);
|
||||
|
||||
return $dispatcher;
|
||||
});
|
||||
|
||||
/**
|
||||
* The URL component is used to generate all kind of urls in the application
|
||||
*/
|
||||
$di->setShared('url', function() use ($config) {
|
||||
$url = new UrlResolver();
|
||||
$url->setBaseUri($config->application->baseUri);
|
||||
|
||||
return $url;
|
||||
});
|
||||
|
||||
$di->setShared('router', function() {
|
||||
|
||||
// Create the router
|
||||
$router = new Router();
|
||||
$router->removeExtraSlashes(true);
|
||||
|
||||
$router->add('/', array(
|
||||
'controller' => 'index',
|
||||
'action' => 'index'
|
||||
))->setName('home-route');
|
||||
|
||||
// Route about page to index controller
|
||||
$router->add('/about', array(
|
||||
'controller' => 'index',
|
||||
'action' => 'about'
|
||||
))->setName('about-route');
|
||||
|
||||
$router->add('/callback/created/{id}', array(
|
||||
'controller' => 'callback',
|
||||
'action' => 'created',
|
||||
))->setName('cb-created');
|
||||
|
||||
// Route callback endpoints to callback controller.
|
||||
$router->add('/cb/{id}', array(
|
||||
'controller' => 'callback',
|
||||
'action' => 'endpoint',
|
||||
))->setName('cb-endpoint');
|
||||
|
||||
// Login routes.
|
||||
$router->add('/login', array(
|
||||
'controller' => 'auth',
|
||||
'action' => 'index',
|
||||
))->setName('login');
|
||||
|
||||
$router->add('/logout', array(
|
||||
'controller' => 'auth',
|
||||
'action' => 'logout',
|
||||
))->setName('logout');
|
||||
|
||||
$router->add('/oauth/{strategy:([a-z]+)}/:params', array(
|
||||
'controller' => 'auth',
|
||||
'action' => 'oauth'
|
||||
))->setName('oauth');
|
||||
|
||||
$router->add('/user', array(
|
||||
'controller' => 'user',
|
||||
'action' => 'profile',
|
||||
))->setName('profile');
|
||||
|
||||
return $router;
|
||||
});
|
||||
|
||||
$di->setShared('viewHelper', '\ViewHelper\Service');
|
||||
|
||||
/**
|
||||
* Setting up the view component
|
||||
*/
|
||||
$di->setShared('view', function () use ($di, $config) {
|
||||
|
||||
$view = new View();
|
||||
|
||||
$view->setViewsDir($config->application->viewsDir);
|
||||
$view->setLayoutsDir('_layouts/');
|
||||
$view->setPartialsDir('_partials/');
|
||||
|
||||
$view->registerEngines(array(
|
||||
'.volt' => function ($view, $di) use ($config) {
|
||||
|
||||
$volt = new VoltEngine($view, $di);
|
||||
|
||||
$volt->setOptions(array(
|
||||
'compiledPath' => $config->application->cacheDir,
|
||||
'compiledSeparator' => '_',
|
||||
'compileAlways' => true,
|
||||
));
|
||||
|
||||
// Register view helpers
|
||||
$compiler = $volt->getCompiler();
|
||||
$compiler->addExtension(new \ViewHelper\Volt\Extension($di));
|
||||
|
||||
return $volt;
|
||||
},
|
||||
'.phtml' => 'Phalcon\Mvc\View\Engine\Php'
|
||||
));
|
||||
|
||||
// Set default main layout.
|
||||
$view->setMainView('layout');
|
||||
|
||||
return $view;
|
||||
});
|
||||
|
||||
$di->setShared('assets', function () {
|
||||
|
||||
$manager = new AssetsManager();
|
||||
|
||||
// CSS
|
||||
$manager->collection('css')
|
||||
->setPrefix('css/')
|
||||
->addCss('application.min.css');
|
||||
|
||||
// Javascript
|
||||
$manager->collection('js')
|
||||
->setPrefix('js/')
|
||||
->addJs('jquery-3.0.0.min.js')
|
||||
->addJs('bootstrap.min.js');
|
||||
|
||||
return $manager;
|
||||
});
|
||||
|
||||
/**
|
||||
* Database connection is created based in the parameters defined in the configuration file
|
||||
*/
|
||||
$di->setShared('db', function () use ($di, $config) {
|
||||
$dbConfig = $config->database->toArray();
|
||||
$adapter = $dbConfig['adapter'];
|
||||
unset($dbConfig['adapter']);
|
||||
|
||||
$class = 'Phalcon\Db\Adapter\Pdo\\' . $adapter;
|
||||
|
||||
$db = new $class($dbConfig);
|
||||
|
||||
$logger = $di->get('logger');
|
||||
|
||||
$eventsManager = new Phalcon\Events\Manager();
|
||||
$eventsManager->attach('db', function ($event, $connection) use ($di, $logger) {
|
||||
|
||||
if ($event->getType() == 'beforeQuery') {
|
||||
$logger->log($connection->getRealSQLStatement(), Logger::INFO);
|
||||
}
|
||||
});
|
||||
|
||||
$db->setEventsManager($eventsManager);
|
||||
|
||||
return $db;
|
||||
});
|
||||
|
||||
/**
|
||||
* If the configuration specify the use of metadata adapter use it or use memory otherwise
|
||||
*/
|
||||
$di->setShared('modelsMetadata', function () use ($config) {
|
||||
|
||||
// Use adapter and options from config if defined.
|
||||
if (isset($config->cache->metadata)) {
|
||||
$mdConfig = $config->cache->metadata->toArray();
|
||||
$options = $mdConfig['options'];
|
||||
$adapter = $mdConfig['adapter'];
|
||||
|
||||
$class = 'Phalcon\Mvc\Model\MetaData\\' . $adapter;
|
||||
|
||||
$metadata = new $class($options);
|
||||
}
|
||||
// Otherwise, default to Memory.
|
||||
else {
|
||||
$metadata = new Phalcon\Mvc\Model\MetaData\Memory();
|
||||
}
|
||||
|
||||
return $metadata;
|
||||
});
|
||||
|
||||
// Set the models cache service
|
||||
/*
|
||||
$di->set('modelsCache', function () {
|
||||
|
||||
// Cache data for one day by default
|
||||
$frontCache = new FrontendDataCache(
|
||||
array(
|
||||
"lifetime" => 86400
|
||||
)
|
||||
);
|
||||
|
||||
// Memcached connection settings
|
||||
$cache = new BackendApcCache(
|
||||
$frontCache,
|
||||
array(
|
||||
'prefix' => 'httpcb_'
|
||||
)
|
||||
);
|
||||
|
||||
return $cache;
|
||||
});*/
|
||||
|
||||
/**
|
||||
* Start the session the first time some component request the session service
|
||||
*/
|
||||
$di->set('session', function () use ($config) {
|
||||
|
||||
// Set session directory if defined.
|
||||
if (isset($config->application->sessionDir)) {
|
||||
session_save_path($config->application->sessionDir);
|
||||
}
|
||||
|
||||
// Create and start session.
|
||||
$session = new SessionAdapter();
|
||||
$session->start();
|
||||
|
||||
return $session;
|
||||
});
|
||||
|
||||
$di->setShared('flash', function () {
|
||||
return new Phalcon\Flash\Session();
|
||||
});
|
||||
|
||||
$di->set('oauth', function() use ($config) {
|
||||
return new OAuth($config);
|
||||
});
|
||||
|
||||
$di->set('auth', function() use ($config) {
|
||||
return new Auth\Auth($config);
|
||||
});
|
||||
|
||||
$di->set('acl', function() {
|
||||
return new Acl\Acl();
|
||||
});
|
||||
|
||||
$di->set('menu', function() use ($di) {
|
||||
|
||||
$config = array(
|
||||
'home' => array(
|
||||
'caption' => 'Home',
|
||||
'route' => 'home-route',
|
||||
'controller' => 'index',
|
||||
'action' => 'index',
|
||||
),
|
||||
'create-new ' => array(
|
||||
'caption' => 'Create new',
|
||||
'resource' => 'callback',
|
||||
'controller' => 'callback',
|
||||
'action' => 'new',
|
||||
),
|
||||
'my-callbacks' => array(
|
||||
'caption' => 'List callbacks',
|
||||
'resource' => 'callback',
|
||||
'controller' => 'callback',
|
||||
'action' => 'list',
|
||||
'children' => array(
|
||||
'show' => array(
|
||||
'resource' => 'callback',
|
||||
'controller' => 'callback',
|
||||
'action' => 'show',
|
||||
),
|
||||
),
|
||||
),
|
||||
'about' => array(
|
||||
'route' => 'about-route',
|
||||
'caption' => 'About',
|
||||
'controller' => 'index',
|
||||
'action' => 'about'
|
||||
),
|
||||
);
|
||||
|
||||
$navigation = new Navigation($config);
|
||||
|
||||
$menu = new Menu($navigation);
|
||||
$menu->setMenuClass(null);
|
||||
if ($di->get('auth')->hasIdentity()) {
|
||||
$menu->setAclRole(Acl\Acl::ROLE_USER);
|
||||
} else {
|
||||
$menu->setAclRole(Acl\Acl::ROLE_GUEST);
|
||||
}
|
||||
return $menu;
|
||||
});
|
||||
Reference in a new issue