Ejemplo n.º 1
0
 /**
  * @param array $config
  * @return \Phalcon\Di\FactoryDefault
  */
 public static function createMvcFrom(array $config) : \Phalcon\Di\FactoryDefault
 {
     $di = new \Phalcon\Di\FactoryDefault();
     $di->set('config', function () use($config) {
         return new Config($config);
     });
     $di->setShared('router', function () use($config) {
         return Router::createFrom($config['routes'] ?? []);
     });
     $di->setShared('dispatcher', function () use($config) {
         return Dispatcher::createMvcFrom($config['dispatcher']);
     });
     if (isset($config['view'])) {
         $di->setShared('view', function () use($config, $di) {
             return View::createFrom($config['view'] ?? [], $di);
         });
     }
     foreach ($config['services'] ?? [] as $service) {
         /** @var InjectableInterface $service */
         $service::injectTo($di);
     }
     return $di;
 }
Ejemplo n.º 2
0
        // Получаем стандартный менеджер событий с помощью DI
        $eventsManager = $di->getShared('eventsManager');
        // Инстанцируем плагин безопасности
        $security = new Core_UserCenter_Security($di);
        // Плагин безопасности слушает события, инициированные диспетчером
        $eventsManager->attach('dispatch', $security);
        $dispatcher = new Phalcon\Mvc\Dispatcher();
        // Связываем менеджер событий с диспетчером
        $dispatcher->setEventsManager($eventsManager);
        return $dispatcher;
    });
    //Setting up the view component
    $di->set('view', function () use($config) {
        $view = new Phalcon\Mvc\View();
        $view->setViewsDir('../' . $config->application->viewsDir);
        return $view;
    });
    // Сессии запустятся один раз, при первом обращении к объекту
    $di->setShared('session', function () {
        $session = new Phalcon\Session\Adapter\Files();
        $session->start();
        return $session;
    });
    //Handle the request
    $application = new \Phalcon\Mvc\Application($di);
    echo $application->handle()->getContent();
} catch (\Phalcon\Exception $e) {
    echo "PhalconException: ", $e;
} catch (Core_Exception $e) {
    echo "CoreException: ", $e->getMessage();
}
Ejemplo n.º 3
0
$container = new \Phalcon\Di\FactoryDefault();
$container->set('auth', function () {
    $auth = new \PhalconDez\Auth\Auth(new \PhalconDez\Auth\Adapter\Session());
    $auth->setCredentialsModel(new \PhalconDez\Auth\Model\Credentials());
    $auth->setSessionModel(new \PhalconDez\Auth\Model\Session());
    $auth->initialize();
    return $auth;
});
$container->set('cookies', function () {
    $cookies = new \Phalcon\Http\Response\Cookies();
    $cookies->useEncryption(false);
    return $cookies;
});
$container->setShared('session', function () {
    $session = new \Phalcon\Session\Adapter\Files();
    $session->setName('phalcon_session');
    $session->start();
    return $session;
});
$container->set('crypt', function () {
    $crypt = new \Phalcon\Crypt();
    $crypt->setMode(MCRYPT_MODE_CFB);
    $crypt->setKey('%31.1e$i86e$f!8j');
    return $crypt;
});
$container->set('security', function () {
    $security = new \Phalcon\Security();
    $security->setWorkFactor(12);
    return $security;
}, true);
$container->set('db', function () {
    return new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => 'localhost', "username" => 'root', "password" => 'root', "dbname" => 'dez-auth'));
Ejemplo n.º 4
0
            '.volt'=> 'Phalcon\Mvc\View\Engine\Volt'
        ]);
        return $view;
    });

    //Router
    $di->set('router', function(){
        $router =new \Phalcon\Mvc\Router();
        $router->mount(new GlobalRoutes());
        return $router;
    });

    //Session
    $di->setShared('session', function(){
        $session=new \Phalcon\Session\Adapter\Files();
        $session->start();
        return $session;
    });

    $di->setShared('component',function(){
        $obj=new stdClass();
        $obj->helper= new \Component\Helper();
        $obj->user=new \Component\User();
        return $obj;
    });

    $di->set('flash',function(){
        $flash=new \Phalcon\Flash\Session([
            'error'=>'alert alert-danger',
            'success'=>'alert alert-success',
            'notice'=>'alert alert-info',
<?php

use App\Constants\Services;
$di = new Phalcon\Di\FactoryDefault();
/**
 * @description Phalcon - Phalcon\Events\Manager
 */
$di->setShared(Services::EVENTS_MANAGER, new \Phalcon\Events\Manager());
/**
 * @description Phalcon - \Phalcon\Mvc\View\Simple
 */
$di->setShared(Services::VIEW, function () use($config) {
    $view = new Phalcon\Mvc\View\Simple();
    $view->setViewsDir($config->application->viewsDir);
    return $view;
});
/**
 * @description Phalcon - \Phalcon\Mvc\Router
 */
$di->set(Services::ROUTER, new \Phalcon\Mvc\Router());
/**
 * @description App - \App\Http\Response
 */
$di->setShared(Services::RESPONSE, new \App\Services\Response());
/**
 * @description Phalcon - \Phalcon\Crypt
 */
$di->set(Services::CRYPT, function () use($config) {
    $crypt = new \Phalcon\Crypt();
    $crypt->setKey($config->cryptKey);
    return $crypt;