public function fire() { $clearAll = true; if ($this->input->getOption('config-only')) { $clearAll = false; Config::clearCache(); $this->info('Config cache cleared.'); } if ($this->input->getOption('meta-only')) { $clearAll = false; Db::clearMetadata(); $this->info('Model metadata cleared.'); } if ($this->input->getOption('locale-only')) { $clearAll = false; I18n::clearCache(); $this->info('Locale cache cleared.'); } if ($this->input->getOption('assets-only')) { $clearAll = false; View::clearAssetsCache(); $this->info('Assets cache cleared.'); } if ($clearAll) { Cache::flush(); Config::clearCache(); $this->info('Cache cleared.'); } Events::fire('cache:after_clear', $this); }
public function initialize() { parent::initialize(); $this->addPageTitle(__(Config::get('view.admin.title_suffix'))); $this->view->setLayout(Config::get('view.admin.layout')); $this->view->isAdmin(true); }
public static function register(Di $di) { $environment = isset($_SERVER['PHWOOLCON_ENV']) ? $_SERVER['PHWOOLCON_ENV'] : 'production'; // @codeCoverageIgnoreStart if (is_file($cacheFile = storagePath('cache/config-' . $environment . '.php'))) { static::$config = (include $cacheFile); Config::get('app.cache_config') or static::clearCache(); return; } // @codeCoverageIgnoreEnd $defaultFiles = glob($_SERVER['PHWOOLCON_CONFIG_PATH'] . '/*.php'); $environmentFiles = glob($_SERVER['PHWOOLCON_CONFIG_PATH'] . '/' . $environment . '/*.php'); $config = new PhalconConfig(static::loadFiles($defaultFiles)); $environmentSettings = static::loadFiles($environmentFiles); $environmentSettings['environment'] = $environment; $environmentConfig = new PhalconConfig($environmentSettings); $config->merge($environmentConfig); $di->remove('config'); $di->setShared('config', $config); static::$config = $config->toArray(); Config::get('database.default') and static::loadDb($config); // @codeCoverageIgnoreStart if (Config::get('app.cache_config')) { is_dir($cacheDir = dirname($cacheFile)) or mkdir($cacheDir, 0777, true); fileSaveArray($cacheFile, static::$config, function ($content) { $replacement = <<<'EOF' $_SERVER['PHWOOLCON_ROOT_PATH'] . ' EOF; return str_replace("'{$_SERVER['PHWOOLCON_ROOT_PATH']}", $replacement, $content); }); } // @codeCoverageIgnoreEnd }
public static function register(Di $di) { static::$di = $di; static::$config = Config::get('auth'); $di->setShared('auth', function () { $di = static::$di; $config = static::$config; $class = $config['adapter']; $options = $config['options']; strpos($class, '\\') === false and $class = 'Phwoolcon\\Auth\\Adapter\\' . $class; if ($di->has($class)) { $class = $di->getRaw($class); } if (!class_exists($class)) { throw new Exception('Admin auth adapter class should implement ' . AdapterInterface::class); } /* @var Security $hasher */ $hasher = static::$di->getShared('security'); $hasher->setDefaultHash($options['security']['default_hash']); $hasher->setWorkFactor($options['security']['work_factor']); $adapter = new $class($options, $hasher, $di); if (!$adapter instanceof AdapterInterface) { throw new Exception('Auth adapter class should implement ' . AdapterInterface::class); } return $adapter; }); static::addPhwoolconJsOptions(); }
public function __construct($options) { $this->options = $options; $this->table = $options['table']; $this->db = Db::connection($options['connection']); $this->db->tableExists($this->table) or $this->createTable(); Config::runningUnitTest() and $this->db->delete($this->table); }
protected static function createConfigTable() { $db = Db::connection(); $db->createTable('config', null, ['columns' => [new Column('key', ['type' => Column::TYPE_VARCHAR, 'size' => 32, 'notNull' => true, 'primary' => true]), new Column('value', ['type' => Column::TYPE_TEXT])]]); if (PhwoolconConfig::runningUnitTest()) { static::saveConfig('_testing', ['k' => 'v']); } }
public static function register(Di $di) { if ($aliases = Config::get('app.class_aliases')) { foreach ($aliases as $alias => $class) { class_exists($alias, false) or class_alias($class, $alias); } } }
public static function register(Di $di) { $app = new Application(Config::get('app.name'), Config::get('app.version')); foreach (Config::get('commands') as $name => $class) { $app->add(new $class($name, $di)); } return $app; }
public static function register(Di $di) { static::$di = $di; $di->remove('payment'); static::$instance = null; $di->setShared('payment', function () { return new static(Config::get('payment')); }); }
public function setUp() { $_SERVER['SCRIPT_NAME'] = '/index.php'; $this->di = Di::getDefault(); Cache::flush(); Config::clearCache(); PHPUnit_Framework_TestCase::setUp(); $class = get_class($this); Log::debug("Running {$class}::{$this->getName()}() ..."); }
public function cleanMigrationsTable() { // @codeCoverageIgnoreStart if (!Config::runningUnitTest()) { return; } // @codeCoverageIgnoreEnd $this->db = Db::connection(); $this->db->dropTable($this->table); $this->checkMigrationsTable(); }
protected function submitConfig($key, $data) { if (is_string($data)) { $data = json_decode($data, true); if (json_last_error() != JSON_ERROR_NONE) { throw new ValidationException(json_last_error_msg(), json_last_error()); } } $value = $this->filterConfig($key, $data); ConfigModel::saveConfig($key, $value); Config::clearCache(); return $value; }
public function testUrl() { $baseUrl = Config::get('app.url'); $uri = 'test/done'; $expected = rtrim($baseUrl, '/') . '/' . ltrim($uri, '/'); $this->assertEquals($expected, url($uri), 'Bad url() result'); $expected = rtrim($baseUrl, '/') . '/' . ltrim($uri, '/') . '?k=v'; $this->assertEquals($expected, url($uri, ['k' => 'v']), 'Bad url() result on queries'); Config::set('app.enable_https', true); $expected = str_replace('http:', 'https:', rtrim($baseUrl, '/')) . '/' . ltrim($uri, '/') . '?k=v'; $this->assertEquals($expected, url($uri, ['k' => 'v'], true), 'Bad url() result on https'); $expected = $uri = 'http://test.com'; $this->assertEquals($expected, url($uri), 'Bad url() result on external links'); }
public function __construct($options) { parent::__construct($options); $cacheType = Config::get('cache.default'); if ($cacheType == 'redis' || $cacheType == 'memcached') { $realAdapter = Cache::class; $this->realOptions = Config::get('counter.drivers.cache.options'); } else { $realAdapter = Rds::class; $this->realOptions = Config::get('counter.drivers.rds.options'); } // @codeCoverageIgnoreEnd $this->realCounter = new $realAdapter($this->realOptions); }
public static function register(Di $di) { static::$di = $di; $di->remove('counter'); static::$adapter = null; $di->setShared('counter', function () { $default = Config::get('counter.default'); $config = Config::get('counter.drivers.' . $default); $class = $config['adapter']; $options = $config['options']; strpos($class, '\\') === false and $class = 'Phwoolcon\\Util\\Counter\\' . $class; return new $class($options); }); }
public function fire() { $this->checkMigrationsTable(); if ($lastMigration = $this->getLastMigration()) { $file = $lastMigration['file']; $runAt = $lastMigration['run_at']; $this->comment(sprintf(' You are going to revert migration "%s" which was run at %s', $file, $runAt)); if (Config::runningUnitTest() || $this->confirm('please confirm', false)) { $this->revertMigration($file); } } else { $this->info('No migrations to be reverted.'); } // @codeCoverageIgnoreEnd }
public function __construct() { parent::__construct(false); static::$runningUnitTest = Config::runningUnitTest(); // @codeCoverageIgnoreStart if ($this->_sitePathPrefix = Config::get('app.site_path')) { $this->_uriSource = self::URI_SOURCE_GET_URL; $this->_sitePathLength = strlen($this->_sitePathPrefix); } // @codeCoverageIgnoreEnd $this->removeExtraSlashes(true); $routes = is_file($file = $_SERVER['PHWOOLCON_ROOT_PATH'] . '/app/routes.php') ? include $file : []; is_array($routes) and $this->addRoutes($routes); $this->cookies = static::$di->getShared('cookies'); $this->response = static::$di->getShared('response'); $this->response->setStatusCode(200); }
public static function register(Di $di) { static::$hostname = gethostname(); $di->remove('log'); static::$logger = null; $di->setShared('log', function () { $filePath = storagePath('logs'); is_dir($filePath) or mkdir($filePath, 0777, true); $filePath .= '/' . Config::get('app.log.file', 'phwoolcon.log'); $logger = new File($filePath); $formatter = $logger->getFormatter(); if ($formatter instanceof Line) { $formatter->setDateFormat('Y-m-d H:i:s'); $formatter->setFormat('[%date%]{host}[%type%] {request} %message%'); } return $logger; }); }
public static function register(Di $di) { static::$di = $di; $di->remove('cache'); static::$cache = null; $di->setShared('cache', function () { $frontend = new Data(['lifetime' => static::TTL_ONE_DAY]); $default = Config::get('cache.default'); $config = Config::get('cache.drivers.' . $default); $class = $config['adapter']; $options = $config['options']; strpos($class, '\\') === false and $class = 'Phalcon\\Cache\\Backend\\' . $class; isset($options['cacheDir']) and $options['cacheDir'] = storagePath($options['cacheDir']) . '/'; /* @var Backend $backend */ $backend = new $class($frontend, $options); return $backend; }); }
public static function register(Di $di) { static::$di = $di; $di->set('Phalcon\\Http\\Cookie', 'Phwoolcon\\Http\\Cookie'); static::$cookies = static::$di->getShared('cookies'); static::$cookies->reset(); static::$options = $options = Config::get('cookies'); static::$cookies->useEncryption($encrypt = $options['encrypt']); $encrypt and static::$di->getShared('crypt')->setKey($options['encrypt_key'])->setPadding(Crypt::PADDING_ZERO); /* @var \Phalcon\Http\Response $response */ if ($response = $di->getShared('response')) { $response->setCookies(static::$cookies); } Events::attach('view:generatePhwoolconJsOptions', function (Event $event) { $options = $event->getData() ?: []; $options['cookies'] = ['domain' => static::$options['domain'], 'path' => static::$options['path']]; $event->setData($options); return $options; }); }
public function testBeanstalkdQueueJobsOperation() { Config::set('queue.queues.default_queue.connection', 'beanstalkd'); Queue::register($this->di); /* @var Queue\Adapter\Beanstalkd $queue */ $queue = Queue::connection(); $data = 'Test raw data'; // Push $jobId = $queue->pushRaw($data); $this->assertTrue(is_numeric($jobId)); $attempts = 0; // Pop /* @var Queue\Adapter\Beanstalkd\Job $job */ $job = $queue->pop(); ++$attempts; $this->assertEquals($data, $job->getRawJob()->getData()); $this->assertEquals($jobId, $job->getJobId()); // Release $job->release(); // Bury $job = $queue->pop(); ++$attempts; $this->assertEquals($data, $job->getRawJob()->getData()); $this->assertEquals($jobId, $job->getJobId()); $job->bury(); // Pop empty $job = $queue->pop(); $this->assertNull($job); // Kick $this->assertTrue(is_numeric($queue->getConnection()->kick(1))); // Attempts $job = $queue->pop(); ++$attempts; $this->assertEquals($jobId, $job->getJobId()); $this->assertEquals($attempts, $job->attempts()); // Delete $this->assertFalse($job->isDeleted()); $job->delete(); $this->assertTrue($job->isDeleted()); }
public function testGetCurrentConfig() { $key = 'white_listed'; $currentConfig = $this->configTrait->getCurrentConfig($key); // foo should be visible because it is in white list $this->assertEquals(fnGet($currentConfig, 'foo'), Config::get($key . '.foo')); // hello should be invisible because it is not in white list $this->assertNotEquals(fnGet($currentConfig, 'hello'), Config::get($key . '.hello')); $key = 'black_listed'; $currentConfig = $this->configTrait->getCurrentConfig($key); // foo should be invisible because it is in black list $this->assertNotEquals(fnGet($currentConfig, 'foo'), Config::get($key . '.foo')); // hello should be visible because it is not in black list $this->assertEquals(fnGet($currentConfig, 'hello'), Config::get($key . '.hello')); $e = false; $key = 'protected'; try { $this->configTrait->getCurrentConfig($key); } catch (Exception $e) { } $this->assertInstanceOf(ValidationException::class, $e); }
public function setUp() { $_SERVER['SCRIPT_NAME'] = '/index.php'; $_SERVER['PHWOOLCON_PHALCON_VERSION'] = Version::getId(); /* @var Di $di */ $di = $this->di = Di::getDefault(); Events::register($di); DiFix::register($di); Db::register($di); Cache::register($di); Log::register($di); Config::register($di); Counter::register($this->di); Aliases::register($di); I18n::register($di); Cookies::register($di); Session::register($di); Cache::flush(); Config::clearCache(); parent::setUp(); $class = get_class($this); Log::debug("================== Running {$class}::{$this->getName()}() ... =================="); Timer::start(); }
public function testAvailableLocales() { $this->assertEquals(Config::get('i18n.available_locales'), I18n::getAvailableLocales(), 'Bad locales list'); }
public function __construct(array $options = []) { $options = array_merge(Config::get('cache.drivers.memcached.options'), $options); parent::__construct($options); }
public static function register(Di $di) { static::$di = $di; static::$runningUnitTest = Config::runningUnitTest(); $di->setShared('view', function () { return new static(Config::get('view')); }); }
public function initialize() { $this->pageTitles = [__(Config::get('view.title_suffix'))]; isset($this->view) and $this->view->reset(); }
use Phwoolcon\Aliases; use Phwoolcon\Cache; use Phwoolcon\Config; use Phwoolcon\Cookies; use Phwoolcon\Db; use Phwoolcon\DiFix; use Phwoolcon\Events; use Phwoolcon\I18n; use Phwoolcon\Log; use Phwoolcon\Queue; use Phwoolcon\Router; use Phwoolcon\Session; use Phwoolcon\Util\Counter; use Phwoolcon\View; $_SERVER['PHWOOLCON_PHALCON_VERSION'] = Version::getId(); Events::register($di); DiFix::register($di); Db::register($di); Cache::register($di); Log::register($di); Config::register($di); Counter::register($di); Aliases::register($di); Router::register($di); I18n::register($di); Cookies::register($di); Session::register($di); View::register($di); Queue::register($di); $loader->registerNamespaces(Config::get('app.autoload.namespaces', []), true);
public function tearDown() { Config::set('counter.default', 'auto'); parent::tearDown(); }
public function testSessionCsrfToken() { Config::set('session.default', 'native'); Session::register($this->di); Session::start(); $this->assertNotEmpty($csrf = Session::generateCsrfToken(), 'Unable to generate CSRF token'); $this->assertEquals($csrf, Session::getCsrfToken(), 'Unable to check CSRF token'); Session::clear(); $this->assertNotEmpty($newCsrf = Session::getCsrfToken(), 'Unable to regenerate CSRF token'); $this->assertNotEquals($csrf, $newCsrf, 'Unable to regenerate unique CSRF token'); Session::end(); }