/** * Initializes viewer */ public function register() { $di = $this->getDi(); $key = $this->_config->application->crypt->key; $di->set('crypt', function () use($key) { $crypt = new \Phalcon\Crypt(); $crypt->setKey($key); return $crypt; }); }
protected function crypt() { //加密服务 $config = $this->_config; $this->_di->set('crypt', function () use($config) { $crypt = new \Phalcon\Crypt(); $crypt->setKey($config->crypt->key); return $crypt; }); }
public function setCrypt() { $this->set('crypt', function () { $crypt = new \Phalcon\Crypt(); $crypt->setMode(MCRYPT_MODE_CFB); $crypt->setKey('vJ4RIGAGg6vJ9lAD'); // Используйте свой собственный ключ! return $crypt; }); }
/** * @requires extension mcrypt */ public function testEncryption() { $tests = array(md5(uniqid()) => str_repeat('x', mt_rand(1, 255)), time() . time() => str_shuffle('abcdefeghijklmnopqrst'), 'le$ki12432543543543543' => null); $encrypt = new Phalcon\Crypt(); foreach (array(MCRYPT_MODE_ECB, MCRYPT_MODE_CBC, MCRYPT_MODE_CFB, MCRYPT_MODE_CFB, MCRYPT_MODE_NOFB) as $mode) { $encrypt->setMode($mode); foreach ($tests as $key => $test) { $encrypt->setKey(substr($key, 0, 16)); $encryption = $encrypt->encrypt($test); $this->assertEquals(rtrim($encrypt->decrypt($encryption), ""), $test); } foreach ($tests as $key => $test) { $encryption = $encrypt->encrypt($test, substr($key, 0, 16)); $this->assertEquals(rtrim($encrypt->decrypt($encryption, substr($key, 0, 16)), ""), $test); } } }
public function testEncryption() { $tests = array(mt_rand(0, 100) => 'Some text', md5(uniqid()) => str_repeat('x', mt_rand(1, 255)), time() => str_shuffle('abcdefeghijklmnopqrst'), 'le$ki' => null); $encrypt = new \Phalcon\Crypt(); foreach (array(MCRYPT_MODE_ECB, MCRYPT_MODE_CBC, MCRYPT_MODE_CFB, MCRYPT_MODE_CFB, MCRYPT_MODE_NOFB) as $mode) { $encrypt->setMode($mode); foreach ($tests as $key => $test) { $encrypt->setKey($key); $encryption = $encrypt->encrypt($test); $this->assertEquals($test, rtrim($encrypt->decrypt($encryption), "")); } foreach ($tests as $key => $test) { $encryption = $encrypt->encrypt($test, $key); $this->assertEquals($test, rtrim($encrypt->decrypt($encryption, $key), "")); } } }
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; }); }
/** * Component flashSession (Session keep flash messages). */ $di->setShared('flash', function () { $flash = new Phalcon\Flash\Session(['error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info']); return $flash; }); $di->setShared('cookies', function () { $cookies = new \Phalcon\Http\Response\Cookies(); $cookies->useEncryption(true); return $cookies; }); // Default component to crypt cookies values $di->set('crypt', function () { $crypt = new \Phalcon\Crypt(); $crypt->setKey($this->_config->cookieCryptKey); return $crypt; }); // Setup Hansel & Gretel breadcrumbs )) $di->set('breadcrumbs', function () { return new \Plugins\Breadcrumbs\Breadcrumbs(); }); // Component Navigation. Manage site navigation $di->setShared('navigation', function () { require_once APP_PATH . '/config/navigation.php'; if (isset($navigation[self::MODULE])) { return new \Libraries\Navigation\Navigation(new \Phalcon\Config($navigation[self::MODULE])); } }); // If the configuration specify the use of metadata adapter use it or use memory otherwise if ($this->_config->cache->metadata == true) {
<?php $di->setShared('config', function () { $config = new \Phalcon\Config\Adapter\Ini(APPLICATION_PATH . '/config/config.ini'); foreach ($config->dirs as $name => $value) { $dir = APPLICATION_PATH . $value; if (!is_dir($dir)) { $umask = umask(00); mkdir($dir, 0777, true); umask($umask); } $config->dirs->{$name} = realpath($dir); } return $config; }); $di->setShared('crypt', function () use($di) { $crypt = new Phalcon\Crypt(); $crypt->setKey($di->getConfig()->application->secret); // Use your own key! return $crypt; }); $di->setShared('cookies', function () { $cookies = new Phalcon\Http\Response\Cookies(); $cookies->useEncryption(true); return $cookies; });
/** * 初始化crypt */ protected function initCrypt() { $config = $this->config; $this->di['crypt'] = function () use($config) { $crypt = new \Phalcon\Crypt(); $cryptKey = $config->application->offsetExists('cryptKey') ? $config->application->cryptKey : 'a2e957d1517c0bba66f861b525d87a53'; $crypt->setKey($cryptKey); return $crypt; }; }
/** * The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework */ $di = new FactoryDefault(); //inject config $di->set('config', $config, true); /** * set crypt, 在cookies使用时候可以进行加密 */ $di->set('crypt', function () { $crypt = new Phalcon\Crypt(); /** * 别用PADDING_DEFAULT影响cookies的取值 */ $crypt->setPadding(\Phalcon\Crypt::PADDING_ZERO); $crypt->setKey('?.aX/^~j1V$#1dj7'); // crypt string 必须为 16 , 24 ,32 三种长度 return $crypt; }); /** * 设置cookies和加密模式 */ $di->setShared('cookies', function () { $cookies = new Phalcon\Http\Response\Cookies(); // $cookies->useEncryption(false); //如果为true则使用下面的crypt加密 , 如果使用加密那速度非常慢 return $cookies; }); /** * The URL component is used to generate all kind of urls in the application */ $di->setShared('url', function () use($config) {
defined('SITENAME') || define('SITENAME', ucfirst($sitename)); /** * Registering a set of directories taken from the configuration file */ $loader = new \Phalcon\Loader(); $loader->registerNamespaces(array('Lininliao\\Library' => ROOT . DS . 'library', 'Lininliao\\Models' => ROOT . DS . 'models', 'Lininliao\\Plugins' => ROOT . DS . 'plugins')); /** * Loader registe directories */ $loader->registerDirs(array(ROOT . DS . 'library', ROOT . DS . 'models', ROOT . DS . 'plugins'))->register(); /** * Set the global encryption key. */ $di->set('crypt', function () use($config) { $crypt = new \Phalcon\Crypt(); $crypt->setKey($config->cookie->crypt); return $crypt; }, true); /** * Database connection is created based in the parameters defined in the configuration file */ $di->set('db', function () use($config) { $db_config = $config->database[ENVIRONMENT]; return new DbAdapter(array('host' => $db_config->dbhost, 'username' => $db_config->dbusername, 'password' => $db_config->dbpassword, 'dbname' => $db_config->dbname)); }, true); /** * Start the session the first time some component request the session service */ $di->set('cookies', function () use($config) { $cookies = new \Phalcon\Http\Response\Cookies(); $cookies->useEncryption(true);
/** * 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(); }); $di->set('crypt', function () { $crypt = new \Phalcon\Crypt(); $crypt->setCipher('blowfish'); $crypt->setKey('vmS"TG<'); return $crypt; }, true); /** * Start the session the first time some component request the session service */ $di->setShared('session', function () { $session = new SessionAdapter(); $session->start(); return $session; }); $di->set('cookie', function () { $cookies = new Cookies(); $cookies->useEncryption(true); return $cookies; }, true);
$security->setWorkFactor(12); return $security; }, true); /* * 设置 cookies */ $di->set('cookies', function () { $cookies = new Cookies(); $cookies->useEncryption(false); return $cookies; }, true); // $di->set('crypt', function () use($di) { $crypt = new \Phalcon\Crypt(); //这里需要设置16位密码,或者24位、32位 $crypt->setKey('myCryptKey024025'); return $crypt; }, true); /* * 设置 Flash */ $di->set('flash', function () { //使用bootstrap的css设置 $flash = new Phalcon\Flash\Session(['error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info', 'warning' => 'alert alert-warning']); return $flash; }); /* * 设置路由 * 以下的路由的设置好处是能够看清楚全部的路由信息! */ $di->set('router', function () {
public static function load(&$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->application->baseUri); return $url; }, true); /** * Setting up the view component */ $di->set('view', function () use($config) { $view = new View(); $view->setViewsDir($config->application->viewsDir); return $view; }, true); /** * Database connection is created based in the parameters defined in the configuration file */ $di->set('db', function () use($config) { $db = new DbAdapter((array) $config->database); $db->timeout = $config->database->timeout; $db->start = time(); $eventsManager = new \Phalcon\Events\Manager(); $eventsManager->attach('db', function ($event, $db) { if ($event->getType() == 'beforeQuery') { $idle = time() - $db->start; if ($idle > $db->timeout) { $db->connect(); $db->start = time(); } } return true; }); return $db; }); /** * If the configuration specify the use of metadata adapter use it or use memory otherwise */ $di->set('modelsMetadata', function () { return new MetaDataAdapter(); }); /** * Start the session the first time some component request the session service */ $di->set('session', function () { $session = new SessionAdapter(); $session->start(); return $session; }); /** * Set encryption */ $di->set('crypt', function () { $crypt = new Phalcon\Crypt(); $crypt->setKey('&fhm8.2$m62$/,1@'); return $crypt; }, true); /** * Set security component to validate / generate tokens */ $di->set('secure', function () { return new SecurityComponent(); }); }
/** * Start the session the first time some component request the session service */ $di->setShared('session', function () { $session = new SessionAdapter(); $session->start(); return $session; }); $di->set('cookies', function () { $cookies = new Phalcon\Http\Response\Cookies(); $cookies->useEncryption(false); return $cookies; }); $di->set('crypt', function () { $crypt = new Phalcon\Crypt(); $crypt->setKey('#_+//*(*&eA|;76$'); return $crypt; }); $di->set('dispatcher', function () use($di) { //Obtain the standard eventsManager from the DI $eventsManager = $di->getShared('eventsManager'); //Instantiate the Security plugin $security = new Security($di); //Listen for events produced in the dispatcher using the Security plugin $eventsManager->attach('dispatch', $security); $dispatcher = new Phalcon\Mvc\Dispatcher(); //Bind the EventsManager to the Dispatcher $dispatcher->setEventsManager($eventsManager); return $dispatcher; }, true); //$di->set('crypt', function () {
************************/ $di->setShared('session', function () { $session = new Phalcon\Session\Adapter\Files(); $session->start(); return $session; }); /************************ * Cookies * Cookies are encrypted * in Phalcon by default, * but need to set an * encryption key * ************************/ $di->set('crypt', function () { $crypt = new Phalcon\Crypt(); $crypt->setKey('@NNPAN$h0kupanCURRYP@Nb@!k1nMAN'); return $crypt; }); /************************ * View Cache * ************************/ $di->setShared('viewCache', function () use($config) { //Cache data for one day by default $frontCache = new Phalcon\Cache\Frontend\Output(array("lifetime" => 2592000)); //File backend settings $cache = new Phalcon\Cache\Backend\File($frontCache, array("cacheDir" => __DIR__ . "/../../data/cache/", "prefix" => "page_")); return $cache; }); /************************ * Asset Manager *
$dispatcher->setEventsManager($eventsManager); return $dispatcher; }); /*//flash info in the page $di->set('flash',function () { return new Phalcon\Flash\Session(array( 'error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info' )); });*/ //cookie crypt $di->set('crypt', function () { $crypt = new Phalcon\Crypt(); $crypt->setKey('sify21'); //Use your own key! return $crypt; }); //cookie $di->set("cookies", function () { $cookies = new Phalcon\Http\Response\Cookies(); return $cookies; }); /*//generate html tags through calling functions $di->set('tag',function(){ return new Phalcon\Tag(); });*/ //Handle the request $app = new \Phalcon\Mvc\Application($di); echo $app->handle()->getContent();
/** * Start the session the first time some component request the session service */ $di->set('session', function () { $session = new SessionAdapter(); $session->start(); return $session; }); //Register the flash service with custom CSS classes $di->set('flash', function () { return new \Phalcon\Flash\Direct(array('error' => 'alert alert-error', 'success' => 'alert alert-success', 'notice' => 'alert alert-info')); }); //Set up encryption key $di->set('crypt', function () use($config) { $crypt = new Phalcon\Crypt(); $crypt->setKey($config->application->encryptKey); return $crypt; }); //Dispatcher $di->set('dispatcher', function () use($di) { $eventsManager = $di->getShared('eventsManager'); $security = new Security($di); $eventsManager->attach('dispatch', $security); $dispatcher = new Phalcon\Mvc\Dispatcher(); $dispatcher->setEventsManager($eventsManager); return $dispatcher; }); //Load config into the di $di->set('config', $config); //Logging $di->set('pingLogger', function () use($config) {
}); /** * URL */ $di->set('url', function () { $url = new \Phalcon\Mvc\Url(); $url->setBaseUri('/'); $url->setStaticBaseUri('/'); return $url; }); /** * Encryption */ $di->set('crypt', function () use($config) { $crypt = new Phalcon\Crypt(); $crypt->setKey($config->encryption->key); return $crypt; }); /** * Cookie */ $di->set('cookies', function () { $cookies = new Phalcon\Http\Response\Cookies(); $cookies->useEncryption(false); return $cookies; }); /** * Database */ $di->set('mongo', function () use($config) { $mongo = new MongoClient('mongodb://127.0.0.1:27017/');
<?php $di->set('encryption', function () { $encryption = new Phalcon\Crypt(); //Set a global encryption key $encryption->setKey('311e86effdada283219971cca5ad5a19'); return $encryption; }, true);
/** * Set the crypt service * * @return void */ protected function crypt() { $config = $this->_config; $this->_di->set('crypt', function () use($config) { $crypt = new \Phalcon\Crypt(); $crypt->setKey($config->crypt->key); $crypt->setPadding(\Phalcon\Crypt::PADDING_ZERO); return $crypt; }); }
$routers = new \Phalcon\Config\Adapter\Ini('../config/router.ini'); $di = new \Phalcon\DI\FactoryDefault(); $loader = new \Phalcon\Loader(); if (!empty($config->library)) { foreach ($config->library as $name => $patch) { $namespace[$name] = '../' . $config->app->library . $patch; } } $loader->registerNamespaces($namespace); $loader->register(); $di->setShared('config', function () use($config) { return $config; }); $di->setShared('crypt', function () use($config) { $crypt = new \Phalcon\Crypt(); $crypt->setKey($config->auth->cookie_hash); return $crypt; }); $di->setShared('cookies', function () { $cookies = new \Phalcon\Http\Response\Cookies(); return $cookies; }); $di->setShared('session', function () { $session = new \Phalcon\Session\Adapter\Files(); $session->start(); return $session; }); //Specify routes for modules $di->setShared('router', function () use($config, $routers) { $router = new \Phalcon\Mvc\Router(false); $router->clear();
<?php $di->set('crypt', function () { $crypt = new Phalcon\Crypt(); $crypt->setKey('#1dj8$=dp?.ak//j1V$'); //Use your own key! return $crypt; });
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); //加密配置 $di->setShared('crypt', function () use($di) { $crypt = new \Phalcon\Crypt(); $crypt->setMode(MCRYPT_MODE_CFB); $crypt->setKey(Config('CRYPT_KEY')); return $crypt; }); //安全组件 $di->set('security', function () { $security = new \Phalcon\Security(); $security->setWorkFactor(12); return $security; }, true); //volt组件 $di->set('volt', function ($view, $di) use($config) { $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di); $volt->setOptions(['compiledPath' => function ($templatePath) use($config) { //$dirName = str_replace('\\', '_', str_replace('/', '_', dirname(trim($templatePath, APP_PATH)))); $dirName = str_replace('\\', '_', str_replace('/', '_', dirname(str_replace(FRONTEND_PUBLIC_PATH . 'views/default/', '', $templatePath)))); return $config->application->voltDir . '/' . $dirName . '_' . basename($templatePath) . '.php';
return array("config" => $config->resource_strings->path); }); $di->set('faker', function () use($config) { return array("config" => $config->faker->path); }); $di->set('lang', function () use($config) { return array("default_lang" => $config->lang->default); }); $di->set('cookies', function () { $cookies = new Phalcon\Http\Response\Cookies(); $cookies->useEncryption(false); return $cookies; }); $di->set('crypt', function () { $crypt = new Phalcon\Crypt(); $crypt->setKey('secret'); //Use your own key! return $crypt; }); //Connect from DB $di->set('db', function () use($config) { return new \Phalcon\Db\Adapter\Pdo\Postgresql(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('dispatcher', function () use($di) { $eventsManager = $di->getShared('eventsManager'); $security = new Security($di);
/** * add routing capabilities * 参考:http://docs.phalconphp.com/zh/latest/reference/routing.html#defining-routes */ $di->set('router', function () { $router = new \Phalcon\Mvc\Router(); //设置默认路由(如果同nginx,可以不用设置) $router->add("/", array('controller' => 'index', 'action' => 'index')); //Set 404 paths $router->notFound(array("controller" => "index", "action" => "route404")); return $router; }); /** * 配置对称加密服务(Setting up an Encryption service) */ $di->set('crypt', function () { $crypt = new Phalcon\Crypt(); //设置全局加密密钥 $crypt->setKey('%31.1e$i86e$f!8jz'); return $crypt; }, true); /** * Redis connection is created based in the parameters defined in the configuration file */ $di->set('redis', function () use($config) { $host = $config->redis->host; $port = $config->redis->port; $redis = new Redis(); $redis->connect($host, $port); return $redis; });
$volt = new VoltEngine($view, $di); $volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_')); return $volt; }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php')); return $view; }, true); /** * Database connection is created based in the parameters defined in the configuration file */ $di->set('db', function () use($config) { return new DbAdapter(array('host' => $config->database->host, 'username' => $config->database->username, 'password' => $config->database->password, 'dbname' => $config->database->dbname)); }); /** * If the configuration specify the use of metadata adapter use it or use memory otherwise */ $di->set('modelsMetadata', function () { return new MetaDataAdapter(); }); /** * Start the session the first time some component request the session service */ $di->set('session', function () { $session = new SessionAdapter(); $session->start(); return $session; }); $di->set('crypt', function () { $crypt = new \Phalcon\Crypt(); $crypt->setKey('FLK#F#apf3NKfw32'); return $crypt; });
$cookies = new Phalcon\Http\Response\Cookies(); $cookies->useEncryption(true); return $cookies; }); $di->setShared('session', function () use($di) { $session = new Phalcon\Session\Adapter\Files(array('uniqueId' => 'banners')); session_name("bannerssessid"); $session->start(); return $session; }); $di->setShared('auth', function () { return new \App\Library\Auth(); }); $di->set('crypt', function () use($config) { $crypt = new Phalcon\Crypt(); $crypt->setKey($config->crypt->key); return $crypt; }); $di->setShared('flashSession', function () { $flash = new \Phalcon\Flash\Session(array('warning' => 'alert alert-warning', 'notice' => 'alert alert-info', 'success' => 'alert alert-success', 'error' => 'alert alert-danger', 'dismissable' => 'alert alert-dismissable')); return $flash; }); $di->set("request", 'Phalcon\\Http\\Request'); require '../app/config/vars.php'; $di->setShared('vars', $vars); if (ENVIRONMENT == ENVIRONMENT_PRODUCTION) { $di->set('modelsMetadata', function () use($config) { $metaData = new \Phalcon\Mvc\Model\MetaData\Files(array("lifetime" => 86400, "prefix" => "banners", 'metaDataDir' => APPLICATION_PATH . $config->app->cacheDir . 'metadata/')); return $metaData; }); } else {
/** * If the configuration specify the use of metadata adapter use it or use memory otherwise */ $di->set('modelsMetadata', function () { return new MetaDataAdapter(); }); /** * Start the session the first time some component request the session service */ $di->setShared('session', function () { $session = new SessionAdapter(); $session->start(); //TODO set Expire infinity return $session; }); /** * set flash component */ $di->setShared('flashSession', function () use($di) { $di->getShared('session'); $flashSession = new \Phalcon\Flash\Session(array('error' => 'alert alert-error', 'success' => 'alert alert-success', 'notice' => 'alert alert-info')); return $flashSession; }); /** * Set Crypt Component use to Cookies */ $di->set('crypt', function () { $crypt = new Phalcon\Crypt(); $crypt->setKey('car_mate_local_favour'); return $crypt; });
}); /** * Custom mail component */ $di->set('acl', function () { return new Acl(); }); /** * Set up the security service */ $di->set('security', function () { $security = new Security(); //Set the password hashing factor to 12 rounds $security->setWorkFactor(12); return $security; }, true); /** * Set the encryption service * Key: 7}T/~"4%[GW*7O-)!"nU */ $di->setShared('crypt', function () { $crypt = new \Phalcon\Crypt(); $crypt->setMode(MCRYPT_MODE_CFB); $crypt->setKey('7}T/~"4%[GW*7O-)!"nU'); return $crypt; }); /** * Set global access to config, excluding db settings */ $di->set('config', $config); $di->get('auth');