Beispiel #1
0
 public function setSession()
 {
     $this->setShared('session', function () {
         $session = new \Phalcon\Session\Adapter\Files();
         $session->start();
         return $session;
     });
 }
Beispiel #2
0
 /**
  * Register the services here to make them general or register in the ModuleDefinition to make them module-specific
  */
 protected function _registerServices()
 {
     $config = (include __DIR__ . "/../apps/config/config.php");
     $di = new \Phalcon\DI\FactoryDefault();
     $loader = new \Phalcon\Loader();
     /**
      * We're a registering a set of directories taken from the configuration file
      */
     $loader->registerDirs(array($config->application->libraryDir, $config->application->pluginDir))->register();
     //Registering a router
     $di->set('router', function () {
         $router = new \Phalcon\Mvc\Router();
         $router->setDefaultModule("frontend");
         $router->add('/:controller/:action', array('module' => 'frontend', 'controller' => 1, 'action' => 2));
         $router->add("/cats/index", array('module' => 'frontend', 'controller' => 'categories', 'action' => 'index'));
         $router->add("/cat/:params", array('module' => 'frontend', 'controller' => 'categories', 'action' => 'cat', 'params' => 1));
         $router->add("/ask/:params", array('module' => 'frontend', 'controller' => 'ask', 'action' => 'ask', 'params' => 1));
         $router->add("/admin/:controller/:action/:params", array('module' => 'backend', 'controller' => 1, 'action' => 2, 'params' => 3));
         return $router;
     });
     $di->set('db', function () use($config) {
         $mysql = new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->name));
         $mysql->query("set names 'utf8'");
         return $mysql;
     });
     $di->set('volt', function ($view, $di) use($config) {
         $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
         $volt->setOptions(array('compiledPath' => $config->volt->path, 'compiledExtension' => $config->volt->extension, 'compiledSeparator' => $config->volt->separator, 'stat' => (bool) $config->volt->stat));
         return $volt;
     });
     //Set the views cache service
     $di->set('viewCache', function () {
         //Cache data for one day by default
         $frontCache = new Phalcon\Cache\Frontend\Output(array("lifetime" => 86400));
         //Memcached connection settings
         $cache = new Phalcon\Cache\Backend\File($frontCache, array("cacheDir" => "../apps/caches/"));
         return $cache;
     });
     /**
      * If the configuration specify the use of metadata adapter use it or use memory otherwise
      */
     $di->set('modelsMetadata', function () use($config) {
         if (isset($config->models->metadata)) {
             $metaDataConfig = $config->models->metadata;
             $metadataAdapter = 'Phalcon\\Mvc\\Model\\Metadata\\' . $metaDataConfig->adapter;
             return new $metadataAdapter();
         } else {
             return new Phalcon\Mvc\Model\Metadata\Memory();
         }
     });
     //Start the session the first time some component request the session service
     $di->set('session', function () {
         $session = new Phalcon\Session\Adapter\Files();
         $session->start();
         return $session;
     });
     $this->setDI($di);
 }
Beispiel #3
0
 protected function initSession()
 {
     $di = $this->getDi();
     $di->set('session', function () {
         $session = new \Phalcon\Session\Adapter\Files();
         $session->start();
         return $session;
     }, true);
 }
Beispiel #4
0
 public function setSessions()
 {
     $di = $this->getDI();
     $di->set('session', function () {
         $session = new \Phalcon\Session\Adapter\Files();
         $session->start();
         return $session;
     });
     $this->setDI($di);
 }
 public function run()
 {
     $di = new \Phalcon\DI\FactoryDefault();
     // Config
     require_once APPLICATION_PATH . '/modules/Cms/Config.php';
     $config = \Cms\Config::get();
     $di->set('config', $config);
     // Registry
     $registry = new \Phalcon\Registry();
     $di->set('registry', $registry);
     // Loader
     $loader = new \Phalcon\Loader();
     $loader->registerNamespaces($config->loader->namespaces->toArray());
     $loader->registerDirs([APPLICATION_PATH . "/plugins/"]);
     $loader->register();
     require_once APPLICATION_PATH . '/../vendor/autoload.php';
     // Database
     $db = new \Phalcon\Db\Adapter\Pdo\Mysql(["host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname, "charset" => $config->database->charset]);
     $di->set('db', $db);
     // View
     $this->initView($di);
     // URL
     $url = new \Phalcon\Mvc\Url();
     $url->setBasePath($config->base_path);
     $url->setBaseUri($config->base_path);
     $di->set('url', $url);
     // Cache
     $this->initCache($di);
     // CMS
     $cmsModel = new \Cms\Model\Configuration();
     $registry->cms = $cmsModel->getConfig();
     // Отправляем в Registry
     // Application
     $application = new \Phalcon\Mvc\Application();
     $application->registerModules($config->modules->toArray());
     // Events Manager, Dispatcher
     $this->initEventManager($di);
     // Session
     $session = new \Phalcon\Session\Adapter\Files();
     $session->start();
     $di->set('session', $session);
     $acl = new \Application\Acl\DefaultAcl();
     $di->set('acl', $acl);
     // JS Assets
     $this->initAssetsManager($di);
     // Flash helper
     $flash = new \Phalcon\Flash\Session(['error' => 'ui red inverted segment', 'success' => 'ui green inverted segment', 'notice' => 'ui blue inverted segment', 'warning' => 'ui orange inverted segment']);
     $di->set('flash', $flash);
     $di->set('helper', new \Application\Mvc\Helper());
     // Routing
     $this->initRouting($application, $di);
     $application->setDI($di);
     // Main dispatching process
     $this->dispatch($di);
 }
 /**
  * @param DI $di
  */
 public function registerServices($di)
 {
     $this->registerAutoloaders();
     $di->setShared('session', function () {
         $session = new \Phalcon\Session\Adapter\Files();
         $session->start();
         return $session;
     });
     $di->set('view', function () use($di) {
         $view = new View();
         $view->setViewsDir(MINI_ADMIN_ROOT . '/views/');
         return $view;
     });
 }
Beispiel #7
0
 public function testSessionFiles()
 {
     $session = new Phalcon\Session\Adapter\Files();
     $this->assertFalse($session->start());
     $this->assertFalse($session->isStarted());
     @session_start();
     $session->set('some', 'value');
     $this->assertEquals($session->get('some'), 'value');
     $this->assertTrue($session->has('some'));
     $this->assertEquals($session->get('undefined', 'my-default'), 'my-default');
     // Automatically deleted after reading
     $this->assertEquals($session->get('some', NULL, TRUE), 'value');
     $this->assertFalse($session->has('some'));
     @session_destroy();
 }
 protected function registerDatastore()
 {
     $this->di->setShared('session', function () {
         $session = new \Phalcon\Session\Adapter\Files();
         $session->start();
         return $session;
     });
     $this->di->set('db', function () {
         $env = $this->di->get('env')->database;
         $conf = array('host' => $env->host, 'username' => $env->username, 'password' => $env->password, 'dbname' => $env->dbname);
         $adapter = new \Phalcon\Db\Adapter\Pdo\Mysql($conf);
         return $adapter;
     });
     $this->di->set('crypt', function () {
         $crypt = new \Phalcon\Crypt();
         $crypt->setKey('very-secret-key');
         return $crypt;
     });
 }
Beispiel #9
0
 private function setServices()
 {
     $loader = new \Phalcon\Loader();
     $loader->registerNamespaces(array('Common' => __DIR__ . '/../components/', 'Common\\Controllers' => __DIR__ . '/../controllers/', 'Common\\Models' => __DIR__ . '/../models/'));
     $loader->register();
     $config = new \Common\Config();
     $di = new \Phalcon\DI\FactoryDefault();
     $di->set('router', new \Common\Router());
     $di->set('url', new \Phalcon\Mvc\Url());
     $di->set('db', new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->name)));
     $di->set('session', function () {
         $session = new \Phalcon\Session\Adapter\Files();
         $session->start();
         return $session;
     });
     $di->set('modelsMetadata', new \Phalcon\Mvc\Model\Metadata\Files(array('metaDataDir' => __DIR__ . '/../cache/models/')));
     $this->setDI($di);
     $this->registerModules(['frontend' => ['className' => 'Frontend\\Module', 'path' => '../apps/frontend/components/Module.php'], 'backend' => ['className' => 'Backend\\Module', 'path' => '../apps/backend/components/Module.php']]);
 }
Beispiel #10
0
 public static function initSystemService()
 {
     global $di;
     //读取配置项
     $config = (require CONFIG_PATH . "/config.php");
     $di->setShared('config', function () use($config) {
         return $config;
     });
     //设置master数据库
     $di->setShared('dbMaster', function () use($config) {
         return new \Phalcon\Db\Adapter\Pdo\Mysql($config->dbMaster->toArray());
     });
     //设置slave1数据库
     $di->setShared('dbSlave1', function () use($config) {
         return new \Phalcon\Db\Adapter\Pdo\Mysql($config->dbSlave1->toArray());
     });
     //设置slave2数据库
     $di->setShared('dbSlave2', function () use($config) {
         return new \Phalcon\Db\Adapter\Pdo\Mysql($config->dbSlave2->toArray());
     });
     //设置redis缓存
     $di->setShared('redis', function () use($config) {
         $frontCache = new \Phalcon\Cache\Frontend\Data($config->cache_life->toArray());
         return new Phalcon\Cache\Backend\Redis($frontCache, $config->redis->toArray());
     });
     //设置Beanstalk队列
     $di->setShared('queue', function () use($config) {
         return new Phalcon\Queue\Beanstalk($config->beanstalk->toArray());
     });
     //设置session
     $di->setShared('session', function () {
         $session = new \Phalcon\Session\Adapter\Files();
         $session->start();
         return $session;
     });
     //设置router
     $di->set('router', function () {
         $router = new \Phalcon\Mvc\Router();
         $router->setDefaultModule("home");
         $router->add('/:module/:controller/:action', array('module' => 1, 'controller' => 2, 'action' => 3));
         return $router;
     });
 }
Beispiel #11
0
 public function setup()
 {
     static::$config = (require __DIR__ . '/../config.php');
     // append biller conf
     static::$config['biller'] = ['key' => self::API_KEY, 'custom_id' => 'id', 'custom_email' => 'email'];
     $di = new \Phalcon\DI\FactoryDefault();
     $di->set('config', static::$config);
     $di->set('db', function () {
         return new \Phalcon\Db\Adapter\Pdo\Mysql(array('host' => '127.0.0.1', 'username' => 'root', 'password' => '', 'dbname' => 'biller_tests', 'charset' => 'utf8'));
     });
     // Session manager
     $di->setShared('session', function () {
         $session = new \Phalcon\Session\Adapter\Files();
         $session->start();
         return $session;
     });
     self::authorize();
     static::$mock = new \Tests\User();
 }
Beispiel #12
0
 public function testSessionFiles()
 {
     $session = new Phalcon\Session\Adapter\Files();
     $this->assertFalse($session->start());
     $this->assertFalse($session->isStarted());
     @session_start();
     $session->set('some', 'value');
     $this->assertEquals($session->get('some'), 'value');
     $this->assertTrue($session->has('some'));
     $this->assertEquals($session->get('undefined', 'my-default'), 'my-default');
 }
Beispiel #13
0
 /**
  * Register the services here to make them general or register in
  * the ModuleDefinition to make them module-specific.
  */
 protected function _registerServices()
 {
     $loader = new \Phalcon\Loader();
     /**
      * We're a registering a set of directories taken from the configuration file
      */
     /*
     $loader->registerDirs(
             array(
                     __DIR__ . '/../library/',
                     __DIR__ . '/../vendor/',
             )
     )->register();
     */
     // Init a DI
     $di = new \Phalcon\DI\FactoryDefault();
     // Registering a router:
     $defaultModule = self::DEFAULT_MODULE;
     $modules = self::$modules;
     $di->set('router', function () use($defaultModule, $modules) {
         $router = new \Phalcon\Mvc\Router();
         $router->setDefaultModule($defaultModule);
         foreach ($modules as $moduleName => $module) {
             // do not route default module
             if ($defaultModule == $moduleName) {
                 continue;
             }
             $router->add('#^/' . $moduleName . '(|/)$#', array('module' => $moduleName, 'controller' => 'index', 'action' => 'index'));
             $router->add('#^/' . $moduleName . '/([a-zA-Z0-9\\_]+)[/]{0,1}$#', array('module' => $moduleName, 'controller' => 1));
             $router->add('#^/' . $moduleName . '[/]{0,1}([a-zA-Z0-9\\_]+)/([a-zA-Z0-9\\_]+)(/.*)*$#', array('module' => $moduleName, 'controller' => 1, 'action' => 2, 'params' => 3));
         }
         return $router;
     });
     /**
      * The URL component is used to generate all kind of urls in the application
      */
     $di['url'] = function () {
         $url = new \Phalcon\Mvc\Url();
         $url->setBaseUri('/');
         return $url;
     };
     /**
      * Start the session the first time some component request the session service
      */
     $di['session'] = function () {
         $session = new \Phalcon\Session\Adapter\Files();
         $session->start();
         return $session;
     };
     $this->setDI($di);
 }
 /**
  * Initialize testing object
  *
  * @uses Auth
  * @uses \ReflectionClass
  */
 public function setUp()
 {
     $this->di = new FactoryDefault();
     $this->di->reset();
     // Setup DI
     $this->di = new DI();
     $this->di->setShared('session', function () {
         $session = new \Phalcon\Session\Adapter\Files();
         $session->start();
         return $session;
     });
     $this->di->set('tag', function () {
         $tag = new \Phalcon\Tag();
         return $tag;
     });
     $this->di->set('escaper', function () {
         $escaper = new \Phalcon\Escaper();
         return $escaper;
     });
     DI::setDefault($this->di);
     $this->reflection = new \ReflectionClass('ULogin\\Auth');
     $this->auth = new Auth();
 }
Beispiel #15
0
 /**
  * Set the session service
  *
  * @return void
  */
 protected function session()
 {
     $this->_di->set('session', function () {
         $session = new \Phalcon\Session\Adapter\Files();
         $session->start();
         return $session;
     });
 }
Beispiel #16
0
 public function testSessionFilesWriteMagicMethods()
 {
     $session_path = __DIR__ . '/cache';
     ini_set('session.save_handler', 'files');
     ini_set('session.save_path', $session_path);
     ini_set('session.serialize_handler', 'php');
     // Write
     $session = new Phalcon\Session\Adapter\Files();
     $session->start();
     @session_start();
     $session->some = 'write-magic-value';
     $this->assertEquals($session->some, 'write-magic-value');
     $this->assertTrue(isset($session->some));
     $session_id = $session->getId();
     @session_write_close();
     unset($session);
     // Check session file
     $session_file = $session_path . '/sess_' . $session_id;
     $this->assertTrue(is_file($session_file));
     $this->assertNotEmpty(@file_get_contents($session_file));
     // Read
     $session = new Phalcon\Session\Adapter\Files();
     $session->start();
     @session_start();
     $session->setId($session_id);
     $this->assertTrue(isset($session->some));
     $this->assertEquals($session->some, 'write-magic-value');
     unset($session->some);
     $this->assertFalse(isset($session->some));
     @session_write_close();
     unset($session);
     // Check session file
     $this->assertTrue(is_file($session_file));
     $this->assertEmpty(@file_get_contents($session_file));
     @unlink($session_file);
 }
Beispiel #17
0
 /**
  * Регистрация сервисов модуля
  */
 public function registerServices(\Phalcon\DiInterface $di)
 {
     $config = new \Phalcon\Config\Adapter\Ini(__DIR__ . '/config/config.ini');
     // Set site config
     $di->set('config', $config);
     // Setting up mongo
     $di->set('mongo', function () use($config) {
         $mongo = new \MongoClient($config->database->host);
         return $mongo->selectDb($config->database->name);
     }, true);
     // Registering the collectionManager service
     $di->set('collectionManager', function () {
         $modelsManager = new \Phalcon\Mvc\Collection\Manager();
         return $modelsManager;
     }, true);
     // Start the session the first time when some component request the session service
     $di->set('session', function () use($config) {
         if (isset($config->session->adapter)) {
             switch ($config->session->adapter) {
                 case 'mongo':
                     $mongo = new \Mongo($config->session->mongoHost);
                     $session = new \Phalcon\Session\Adapter\Mongo(array('collection' => $mongo->kladrapiSession->data));
                     break;
                 case 'file':
                     $session = new \Phalcon\Session\Adapter\Files();
                     break;
             }
         } else {
             $session = new \Phalcon\Session\Adapter\Files();
         }
         $session->start();
         return $session;
     });
     // Setting up dispatcher
     $di->set('dispatcher', function () use($di) {
         $evManager = $di->getShared('eventsManager');
         $evManager->attach("dispatch:beforeException", function ($event, $dispatcher, $exception) {
             switch ($exception->getCode()) {
                 case \Phalcon\Mvc\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                 case \Phalcon\Mvc\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                     $dispatcher->forward(array('controller' => 'index', 'action' => 'show404'));
                     return false;
             }
         });
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setDefaultNamespace("Kladr\\Frontend\\Controllers");
         $dispatcher->setEventsManager($evManager);
         return $dispatcher;
     });
     // Register an user component
     $di->set('elements', function () {
         return new Library\Elements();
     });
     // Register key tools
     $di->set('keyTools', function () {
         return new Plugins\KeyTools();
     });
     // Register the flash service with custom CSS classes
     $di->set('flash', function () {
         $flash = new \Phalcon\Flash\Direct();
         return $flash;
     });
     // Setting up the view component
     $di->set('view', function () {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir('../apps/frontend/views/');
         return $view;
     });
 }
Beispiel #18
0
 public static function run()
 {
     if (in_array(APPLICATION_ENV, array('development'))) {
         $debug = new \Phalcon\Debug();
         $debug->listen();
     }
     $di = new \Phalcon\DI\FactoryDefault();
     $config = (include APPLICATION_PATH . '/config/application.php');
     $di->set('config', $config);
     $loader = new \Phalcon\Loader();
     $loader->registerNamespaces($config->loader->namespaces->toArray());
     $loader->register();
     $loader->registerDirs(array(APPLICATION_PATH . "/plugins/"));
     $db = new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname, "charset" => $config->database->charset));
     $di->set('db', $db);
     $view = new View();
     /* $view->disableLevel(array(
        View::LEVEL_BEFORE_TEMPLATE => true,
        View::LEVEL_LAYOUT          => true,
        View::LEVEL_AFTER_TEMPLATE  => true
        )); */
     define('MAIN_VIEW_PATH', '../../../views/');
     $view->setMainView(MAIN_VIEW_PATH . 'main');
     $view->setLayoutsDir(MAIN_VIEW_PATH . '/layouts/');
     $view->setPartialsDir(MAIN_VIEW_PATH . '/partials/');
     $volt = new \Application\Mvc\View\Engine\Volt($view, $di);
     $volt->setOptions(array('compiledPath' => APPLICATION_PATH . '/cache/volt/'));
     $volt->initCompiler();
     $viewEngines = array(".volt" => $volt);
     $view->registerEngines($viewEngines);
     $di->set('view', $view);
     $viewSimple = new \Phalcon\Mvc\View\Simple();
     $viewSimple->registerEngines($viewEngines);
     $di->set('viewSimple', $viewSimple);
     $url = new \Phalcon\Mvc\Url();
     $url->setBasePath('/');
     $url->setBaseUri('/');
     $application = new \Phalcon\Mvc\Application();
     $application->registerModules($config->modules->toArray());
     $router = new \Application\Mvc\Router\DefaultRouter();
     foreach ($application->getModules() as $module) {
         $className = str_replace('Module', 'Routes', $module['className']);
         if (class_exists($className)) {
             $class = new $className();
             $router = $class->init($router);
         }
     }
     $di->set('router', $router);
     $eventsManager = new \Phalcon\Events\Manager();
     $dispatcher = new \Phalcon\Mvc\Dispatcher();
     $eventsManager->attach("dispatch:beforeException", function ($event, $dispatcher, $exception) {
         new ExceptionPlugin($dispatcher, $exception);
     });
     $eventsManager->attach("dispatch:beforeDispatchLoop", function ($event, $dispatcher) {
         new LocalizationPlugin($dispatcher);
     });
     $eventsManager->attach("acl", function ($event, $acl) {
         if ($event->getType() == 'beforeCheckAccess') {
             echo $acl->getActiveRole(), $acl->getActiveResource(), $acl->getActiveAccess();
         }
     });
     $dispatcher->setEventsManager($eventsManager);
     $di->set('dispatcher', $dispatcher);
     $session = new \Phalcon\Session\Adapter\Files();
     $session->start();
     $di->set('session', $session);
     $acl = new \Application\Acl\DefaultAcl();
     $acl->setEventsManager($eventsManager);
     $di->set('acl', $acl);
     $assets = new \Phalcon\Assets\Manager();
     $di->set('assets', $assets);
     $flash = new \Phalcon\Flash\Session(array('error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info', 'warning' => 'alert alert-warning'));
     $di->set('flash', $flash);
     $di->set('helper', new \Application\Mvc\Helper());
     $application->setDI($di);
     echo $application->handle()->getContent();
 }
Beispiel #19
0
/**
* The DI is our direct injector.  It will store pointers to all of our services
* and we will insert it into all of our controllers.
* @var DefaultDI
*/
$di = new Phalcon\DI\FactoryDefault();
/**
* Return array of the Collections, which define a group of routes, from
* routes/collections.  These will be mounted into the app itself later.
*/
$di->set('collections', function () {
    return include './Routes/RouteLoader.php';
});
// As soon as we request the session service, it will be started.
$di->setShared('session', function () {
    $session = new \Phalcon\Session\Adapter\Files();
    $session->start();
    $session->set('language', 'id');
    return $session;
});
$di->set('modelsCache', function () {
    //Cache data for one day by default
    $frontCache = new \Phalcon\Cache\Frontend\Data(array('lifetime' => 3600));
    //File cache settings
    $cache = new \Phalcon\Cache\Backend\File($frontCache, array('cacheDir' => __DIR__ . '/Cache/'));
    return $cache;
});
/**
* Database connection is created based in the parameters defined in the configuration file
*/
$di->set('db', function () use($config) {
Beispiel #20
0
 */
//设置网站的基本url
$di->set('url', function () use($config) {
    $url = new \Phalcon\Mvc\Url();
    $url->setBaseUri($config->application->baseUri);
    return $url;
});
//注册路由
$di->set('router', function () use($di, $modules) {
    return include __DIR__ . '/routers.php';
}, true);
//注册配置
$di->set('config', $config, true);
//session配置
$di->set('session', function () {
    $session = new \Phalcon\Session\Adapter\Files();
    if (!$session->isStarted()) {
        $session->start();
    }
    return $session;
}, true);
//设置cookie
$di->set('cookies', function () {
    $cookies = new Phalcon\Http\Response\Cookies();
    if (DEBUG and version_compare(PHP_VERSION, '5.6', '>=')) {
        $cookies->useEncryption(false);
        //不加密
    }
    return $cookies;
}, true);
//加密配置
Beispiel #21
0
 /**
  * Gestor de sesiones
  * @return DI object
  */
 private function setSessionManager()
 {
     $this->di->setShared('session', function () {
         $session = new \Phalcon\Session\Adapter\Files(array('uniqueId' => 'sayvot'));
         $session->start();
         return $session;
     });
 }
Beispiel #22
0
include_once '../vendor/autoload.php';
$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);
Beispiel #23
0
 public function testSessionName()
 {
     $session = new Phalcon\Session\Adapter\Files();
     $session->setName('NAMEFOO');
     $this->assertEquals('NAMEFOO', $session->getName());
     $this->assertEquals('NAMEFOO', session_name());
     session_name('NAMEBAR');
     $this->assertEquals('NAMEBAR', $session->getName());
 }
<?php

/*<!--Check auth-->*/
$session = new \Phalcon\Session\Adapter\Files();
$session->start();
$auth = $session->get('auth');
if (!$auth) {
    return false;
} elseif ($auth->admin_session !== true) {
    return false;
}
/*<!--/Check auth-->*/
error_reporting(0);
// Set E_ALL for debuging
include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'elFinderConnector.class.php';
include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'elFinder.class.php';
include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'elFinderVolumeDriver.class.php';
include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'elFinderVolumeLocalFileSystem.class.php';
// Required for MySQL storage connector
// include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeMySQL.class.php';
// Required for FTP connector support
// include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeFTP.class.php';
/**
 * # Dropbox volume driver need "dropbox-php's Dropbox" and "PHP OAuth extension" or "PEAR's HTTP_OAUTH package"
 * * dropbox-php: http://www.dropbox-php.com/
 * * PHP OAuth extension: http://pecl.php.net/package/oauth
 * * PEAR's HTTP_OAUTH package: http://pear.php.net/package/http_oauth
 *  * HTTP_OAUTH package require HTTP_Request2 and Net_URL2
 */
// Required for Dropbox.com connector support
// include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeDropbox.class.php';
 protected function initSession()
 {
     $config = $this->di['config'];
     $this->di->set('session', function () use($config) {
         if ($config->session->adapter === 'redis') {
             $session = new \Phalcon\Session\Adapter\Redis(['path' => sprintf('tcp://%s:%s?weight=1&prefix=%s', $config->redis->session->host, $config->redis->session->port, $config->redis->session->prefix), 'name' => $config->session->name, 'lifetime' => $config->session->lifetime, 'cookie_lifetime' => $config->session->cookieLifetime]);
         } else {
             $session = new \Phalcon\Session\Adapter\Files();
         }
         $session->start();
         return $session;
     }, TRUE);
 }
<?php

$session = new Phalcon\Session\Adapter\Files(array('uniqueId' => 'my-private-app'));
$session->start();
$session->set('var', 'some-value');
echo $session->get('var');
Beispiel #27
0
- Layouts
- add CSS / JS based on controller / action
- if Dev, if file.LESS newer than file.css, compile LESS
- headlink / headscript, with optional merger / minifier
*/
define('BASE_DIR', dirname(__DIR__));
define('APP_DIR', BASE_DIR . '/app');
try {
    $config = new \Phalcon\Config\Adapter\Ini(APP_DIR . '/config/config.ini');
    //Register an autoloader
    $loader = new \Phalcon\Loader();
    $loader->registerNamespaces(["Watchlist\\Controllers" => BASE_DIR . '/' . $config->application->controllersDir, "Watchlist\\Views" => BASE_DIR . '/' . $config->application->viewsDir, "Watchlist\\Models" => BASE_DIR . '/' . $config->application->modelsDir, "Watchlist" => BASE_DIR . '/' . $config->application->appLibDir, "Phalcore" => BASE_DIR . '/' . $config->application->librariesDir . "phalcore/"])->register();
    //Create a DI
    $config["di"] = new \Phalcon\DI\FactoryDefault();
    $config["di"]->set('session', function () {
        $session = new \Phalcon\Session\Adapter\Files();
        $session->start();
        return $session;
    });
    //Setup the view component
    $config["di"]->set('view', function () use($config) {
        $view = new \Phalcon\Mvc\View();
        $view->setViewsDir(BASE_DIR . '/' . $config->application->viewsDir);
        return $view;
    });
    $config["di"]->set('dispatcher', function () {
        $dispatcher = new \Phalcon\Mvc\Dispatcher();
        $dispatcher->setDefaultNamespace('Watchlist\\Controllers');
        return $dispatcher;
    });
    //Setup the flash service
Beispiel #28
0
 public function run()
 {
     $di = new \Phalcon\DI\FactoryDefault();
     $config = (include APPLICATION_PATH . '/config/application.php');
     $di->set('config', $config);
     $registry = new \Phalcon\Registry();
     $loader = new \Phalcon\Loader();
     $loader->registerNamespaces($config->loader->namespaces->toArray());
     $loader->register();
     $loader->registerDirs(array(APPLICATION_PATH . "/plugins/"));
     $db = new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname, "charset" => $config->database->charset));
     $di->set('db', $db);
     $view = new \Phalcon\Mvc\View();
     define('MAIN_VIEW_PATH', '../../../views/');
     $view->setMainView(MAIN_VIEW_PATH . 'main');
     $view->setLayoutsDir(MAIN_VIEW_PATH . '/layouts/');
     $view->setPartialsDir(MAIN_VIEW_PATH . '/partials/');
     $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
     $volt->setOptions(array('compiledPath' => APPLICATION_PATH . '/cache/volt/'));
     $phtml = new \Phalcon\Mvc\View\Engine\Php($view, $di);
     $viewEngines = array(".volt" => $volt, ".phtml" => $phtml);
     $registry->viewEngines = $viewEngines;
     $view->registerEngines($viewEngines);
     if (isset($_GET['_ajax']) && $_GET['_ajax']) {
         $view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_LAYOUT);
     }
     $di->set('view', $view);
     $viewSimple = new \Phalcon\Mvc\View\Simple();
     $viewSimple->registerEngines($viewEngines);
     $di->set('viewSimple', $viewSimple);
     $url = new \Phalcon\Mvc\Url();
     $url->setBasePath('/');
     $url->setBaseUri('/');
     $cacheFrontend = new \Phalcon\Cache\Frontend\Data(array("lifetime" => 60, "prefix" => HOST_HASH));
     switch ($config->cache) {
         case 'file':
             $cache = new \Phalcon\Cache\Backend\File($cacheFrontend, array("cacheDir" => __DIR__ . "/cache/backend/"));
             break;
         case 'memcache':
             $cache = new \Phalcon\Cache\Backend\Memcache($cacheFrontend, array("host" => "localhost", "port" => "11211"));
             break;
     }
     $di->set('cache', $cache);
     $di->set('modelsCache', $cache);
     switch ($config->metadata_cache) {
         case 'memory':
             $modelsMetadata = new \Phalcon\Mvc\Model\Metadata\Memory();
             break;
         case 'apc':
             $modelsMetadata = new \Phalcon\Mvc\Model\MetaData\Apc(array("lifetime" => 60, "prefix" => HOST_HASH));
             break;
     }
     $di->set('modelsMetadata', $modelsMetadata);
     /**
      * CMS Конфигурация
      */
     $cmsModel = new \Cms\Model\Configuration();
     $cms = $cmsModel->getConfig();
     // @todo Будет отдельный раздел конфигурации для управления языками. Пока заглушка.
     $cms['languages'] = [['name' => 'Русский', 'iso' => 'ru', 'locale' => 'ru_RU'], ['name' => 'English', 'iso' => 'en', 'locale' => 'en_EN']];
     $registry->cms = $cms;
     // Отправляем в Registry
     $application = new \Phalcon\Mvc\Application();
     $application->registerModules($config->modules->toArray());
     $router = new \Application\Mvc\Router\DefaultRouter();
     foreach ($application->getModules() as $module) {
         $className = str_replace('Module', 'Routes', $module['className']);
         if (class_exists($className)) {
             $class = new $className();
             $router = $class->init($router);
         }
     }
     $di->set('router', $router);
     $eventsManager = new \Phalcon\Events\Manager();
     $dispatcher = new \Phalcon\Mvc\Dispatcher();
     $eventsManager->attach("dispatch:beforeDispatchLoop", function ($event, $dispatcher, $di) use($di) {
         new LocalizationPlugin($dispatcher);
         new AclPlugin($di->get('acl'), $dispatcher);
     });
     $profiler = new \Phalcon\Db\Profiler();
     $eventsManager->attach('db', function ($event, $db) use($profiler) {
         if ($event->getType() == 'beforeQuery') {
             $profiler->startProfile($db->getSQLStatement());
         }
         if ($event->getType() == 'afterQuery') {
             $profiler->stopProfile();
         }
     });
     $db->setEventsManager($eventsManager);
     $di->set('profiler', $profiler);
     $dispatcher->setEventsManager($eventsManager);
     $di->set('dispatcher', $dispatcher);
     $session = new \Phalcon\Session\Adapter\Files();
     $session->start();
     $di->set('session', $session);
     $acl = new \Application\Acl\DefaultAcl();
     $di->set('acl', $acl);
     $assets = new \Phalcon\Assets\Manager();
     $di->set('assets', $assets);
     $flash = new \Phalcon\Flash\Session(array('error' => 'ui red inverted segment', 'success' => 'ui green inverted segment', 'notice' => 'ui blue inverted segment', 'warning' => 'ui orange inverted segment'));
     $di->set('flash', $flash);
     $di->set('helper', new \Application\Mvc\Helper());
     $di->set('registry', $registry);
     $assetsManager = new \Phalcon\Assets\Manager();
     $di->set('assets', $assetsManager);
     $application->setDI($di);
     $this->dispatch($di);
 }