}, true); $di->set('cookies', function () { $cookies = new Cookies(); $cookies->useEncryption(false); return $cookies; }, true); $di->set('crypt', function () use($di) { $crypt = new Crypt(); $crypt->setKey($di->get('config')->application->cryptSalt); //Use your own key! return $crypt; }); $di->set('security', function () { $security = new Security(); //Set the password hashing factor to 12 rounds $security->setWorkFactor(12); return $security; }, true); //Set the models cache service $di->set('modelsCache', function () { // Cache data for one day by default $frontCache = new Data(['lifetime' => 86400]); // Memcached connection settings $cache = new Memcache($frontCache, ['host' => 'localhost', 'port' => 11211]); return $cache; }); //Set mail swift $di->set('mail', function () { return new Mail(); }); //Markdown renderer
/** * * @param type $options */ protected function initSecurity($options = []) { $this->_di->setShared('security', function () { $security = new Security(); $security->setWorkFactor(12); return $security; }); }
/** * Initializes the Security component * * @param array $options */ public function initSecurity($options = []) { $this->di->setShared('security', function () { $security = new PhSecurity(); $security->setWorkFactor(10); return $security; }); }
/** * Init Services * * @param mixed $config * @param \Phalcon\DiInterface $di */ public function _initServices($di, $config) { /** * The URL component is used to generate all kind of urls in the application */ $di->set('url', function () use($config) { $url = new UrlResolver(); $url->setBaseUri($config->website->baseUri); return $url; }, true); /** * Start the session the first time some component request the session service */ $di->set('session', function () use($config) { $session = new ZSession(['uniqueId' => $config->auth->salt]); $session->start(); return $session; }, true); /** * Set view cache */ $di->set('viewCache', function () use($config) { //Cache data for one day by default $frontCache = new FrontendOutput(['lifetime' => $config->viewCache->lifetime]); //File backend settings $cache = new CacheFile($frontCache, ['cacheDir' => ROOT_PATH . $config->viewCache->dir]); return $cache; }); if ($config->modelMetadataCache->status) { /** * Set models metadata */ $di->set('modelsMetadata', function () use($config) { if ($config->modelMetadataCache->type == 'apc') { return new MetaDataApc(['lifetime' => $config->modelMetadataCache->lifetime, 'prefix' => $config->modelMetadataCache->prefix]); } else { return new MetadataFiles(['metaDataDir' => ROOT_PATH . '/cache/metadata/', 'lifetime' => $config->modelMetadataCache->lifetime]); } }); } /** * Crypt service */ $di->set('crypt', function () use($config) { $crypt = ZCrypt::getInstance(); $crypt->setKey($config->crypt->key); return $crypt; }); /** * Set security */ $di->set('security', function () { $security = new Security(); $security->setWorkFactor(8); return $security; }); /** * Set up database connection */ $di->set('db', function () use($config) { $adapter = 'Phalcon\\Db\\Adapter\\Pdo\\' . $config->database->adapter; /** * @var \Phalcon\Db\Adapter\Pdo\Postgresql $db */ if ($config->database->adapter == 'Mysql') { $db = new $adapter($config->database->toArray()); } else { $db = new $adapter(array('host' => $config->database->host, 'username' => $config->database->username, 'password' => $config->database->password, 'dbname' => $config->database->dbname)); } if ($config->database->log) { $eventsManager = new EventsManager(); if (!file_exists(ROOT_PATH . '/cache/logs/db.log')) { file_put_contents(ROOT_PATH . '/cache/logs/db.log', ''); } $logger = new FileLogger(ROOT_PATH . '/cache/logs/db.log'); //Listen all the database events $eventsManager->attach('db', function ($event, $db) use($logger) { /** * @var \Phalcon\Events\Event $event */ if ($event->getType() == 'beforeQuery') { /** * @var \Phalcon\Db\Adapter\Pdo\Postgresql $db */ $logger->log($db->getSQLStatement(), Logger::INFO); } }); //Assign the eventsManager to the db adapter instance $db->setEventsManager($eventsManager); } return $db; }); /** * Set a models manager */ $di->set('modelsManager', new ModelsManager()); /** * Set up model cache for Phalcon model */ $di->set('modelsCache', function () { return ZCache::getInstance('_ZCMS_MODEL'); }); /** * Set up asset add css, js */ $di->set('assets', new ZAssets()); /** * Loading routes from the routes.php file */ $di->set('router', function () { return require APP_DIR . '/config/router.php'; }); $di->set('acl', ZAcl::getInstance()); /** * Set up the flash service (custom with bootstrap) */ $di->set('flashSession', function () { $flashSession = new FlashSession(['warning' => 'alert alert-warning', 'notice' => 'alert alert-info', 'success' => 'alert alert-success', 'error' => 'alert alert-danger']); return $flashSession; }); /** * Set up cache */ $di->set('cache', ZCache::getInstance('_ZCMS_GLOBAL')); }
/** * Init security. * * @param DI $di Dependency Injection. * * @return void */ protected function _initSecurity($di) { $di->set('security', function () { $security = new PhSecurity(); $security->setWorkFactor(10); return $security; }); }
/** * Database connection is created based in the parameters defined in the configuration file */ $di->set('db', function () use($config) { return new DbAdapter($config->database->toArray()); }); /** * If the configuration specify the use of metadata adapter use it or use memory otherwise */ $di->set('modelsMetadata', function () { return new MetaDataAdapter(); }); /** * Start Flash */ $di->set('flash', function () { return new FlashSession(array('error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info')); }); $di->set('security', function () { $security = new Security(); $security->setWorkFactor(6); return $security; }, true); /** * Start the session the first time some component request the session service */ $di->setShared('session', function () { $session = new SessionAdapter(); $session->start(); return $session; });