/** * @param RelationInterface * @param null|callable $constraints * @param Loader|EagerLoad $parent */ public function __construct(Relation $relation, callable $constraints = NULL, $parent) { if (static::$isPhalcon2 === NULL) { static::$isPhalcon2 = version_compare(\Phalcon\Version::get(), '2.0.0') >= 0; } $this->relation = $relation; $this->constraints = $constraints; $this->parent = $parent; }
/** * @param RelationInterface * @param null|callable $constraints * @param Loader|EagerLoad $parent */ public function __construct(Relation $relation, $constraints, $parent) { if (static::$isPhalcon2 === null) { static::$isPhalcon2 = version_compare(\Phalcon\Version::get(), '2.0.0') >= 0; } $this->relation = $relation; $this->constraints = is_callable($constraints) ? $constraints : null; $this->parent = $parent; }
/** * Tests the Debug::getVersion * * @issue 12215 * @author Serghei Iakovlev <*****@*****.**> * @since 2016-09-25 */ public function testShouldGetVersion() { $this->specify("The getVersion doesn't work as expected", function () { $debug = new Debug(); $target = '"_new"'; $uri = '"https://docs.phalconphp.com/en/' . Version::getPart(Version::VERSION_MAJOR) . '.0.0/"'; $version = Version::get(); expect($debug->getVersion())->equals("<div class='version'>Phalcon Framework <a href={$uri} target={$target}>{$version}</a></div>"); }); }
/** * @expectedException \Phalcon\Acl\Exception * @expectedExceptionMessage Invalid value for accessList */ public function testFactoryShouldThrowExceptionIfActionsKeyIsMissing() { if (version_compare(\Phalcon\Version::get(), '2.0.0', '=')) { $this->markTestSkipped('Fails due to a bug in Phalcon. See https://github.com/phalcon/cphalcon/pull/10226'); } $config = new \Phalcon\Config\Adapter\Ini(__DIR__ . '/_fixtures/acl.ini'); unset($config->acl->resource->index->actions); unset($config->acl->role->guest->allow->index->actions[0]); $factory = new \Phalcon\Acl\Factory\Memory(); $acl = $factory->create($config->get('acl')); }
/** * @return bool|void */ public function beforeExecuteRoute() { $this->registerOptions(); if (!parent::beforeExecuteRoute()) { return false; } $this->_currentVersion = join('.', sscanf(\Phalcon\Version::get(), '%d.%d.%d')); if (!$this->dispatcher->getParam('overwrite') && $this->db->tableExists((new Models\Versions())->getSource())) { $hasRecords = (bool) Models\Versions::count(['conditions' => 'version = ?0', 'bind' => [$this->_currentVersion]]); if ($hasRecords && !$this->confirm('Docs are already presents in the database. Do you want to overwrite it?')) { return false; } } }
public function onConstruct() { if (!($release = $this->cacheData->get('gh_release'))) { $options = [CURLOPT_RETURNTRANSFER => true, CURLOPT_AUTOREFERER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => 20, CURLOPT_HEADER => true, CURLOPT_PROTOCOLS => CURLPROTO_HTTP | CURLPROTO_HTTPS, CURLOPT_REDIR_PROTOCOLS => CURLPROTO_HTTP | CURLPROTO_HTTPS, CURLOPT_USERAGENT => 'Phalcon HTTP/' . \Phalcon\Version::get() . ' (Curl)', CURLOPT_CONNECTTIMEOUT => 30, CURLOPT_TIMEOUT => 30, CURLOPT_URL => 'https://api.github.com/repos/phalcon/cphalcon/releases/latest', CURLOPT_HTTPGET => true, CURLOPT_CUSTOMREQUEST => 'GET']; $ch = curl_init(); curl_setopt_array($ch, $options); $content = curl_exec($ch); $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $body = substr($content, $headerSize); if ($errno = curl_errno($ch)) { error_log("Get GitHub release error: " . curl_error($ch)); } curl_close($ch); $response = json_decode($body); if (JSON_ERROR_NONE !== json_last_error()) { error_log("Decode GitHub response error: " . json_last_error_msg()); } if (isset($response->tag_name)) { $release = str_replace('phalcon-v', '', strtolower(trim($response->tag_name))); $this->cacheData->save('gh_release', $release, 60 * 60); } } $this->view->setVar('release', $release ? ' v.' . $release : ''); }
public static function get() { return parent::get(); }
try { $extensionLoaded = true; if (!extension_loaded('phalcon')) { $extensionLoaded = false; include dirname(__FILE__) . '/scripts/Phalcon/Script.php'; throw new Exception(sprintf("Phalcon extension isn't installed, follow these instructions to install it: %s", Script::DOC_INSTALL_URL)); } $loader = new Loader(); $loader->registerDirs(array(__DIR__ . '/scripts/'))->registerNamespaces(array('Phalcon' => __DIR__ . '/scripts/'))->register(); if (Version::getId() < Script::COMPATIBLE_VERSION) { throw new Exception(sprintf("Your Phalcon version isn't compatible with Developer Tools, download the latest at: %s", Script::DOC_DOWNLOAD_URL)); } if (!defined('TEMPLATE_PATH')) { define('TEMPLATE_PATH', __DIR__ . '/templates'); } $vendor = sprintf('Phalcon DevTools (%s)', Version::get()); print PHP_EOL . Color::colorize($vendor, Color::FG_GREEN, Color::AT_BOLD) . PHP_EOL . PHP_EOL; $eventsManager = new EventsManager(); $eventsManager->attach('command', new CommandsListener()); $script = new Script($eventsManager); $commandsToEnable = array('\\Phalcon\\Commands\\Builtin\\Enumerate', '\\Phalcon\\Commands\\Builtin\\Controller', '\\Phalcon\\Commands\\Builtin\\Model', '\\Phalcon\\Commands\\Builtin\\AllModels', '\\Phalcon\\Commands\\Builtin\\Project', '\\Phalcon\\Commands\\Builtin\\Scaffold', '\\Phalcon\\Commands\\Builtin\\Migration', '\\Phalcon\\Commands\\Builtin\\Webtools'); foreach ($commandsToEnable as $command) { $script->attach(new $command($script, $eventsManager)); } $script->run(); } catch (PhalconException $e) { print Color::error($e->getMessage()) . PHP_EOL; } catch (Exception $e) { if ($extensionLoaded) { print Color::error($e->getMessage()) . PHP_EOL; } else {
<?php /** * Скрипт формирует файлы примеров для компонентов * * * php scripts/gen-examples.php */ define('ROOT_DIR', '/home/boston/www/phalcon-docs/en/api'); $version = \Phalcon\Version::get(); $versionPieces = explode(' ', $version); $phalconVersion = $versionPieces[0]; define('EXAMPLES_ROOT', sprintf("%s/%s", dirname(__DIR__), 'examples')); define('EXAMPLES_DIR', sprintf("%s/%s", EXAMPLES_ROOT, $phalconVersion)); class ExamplesGenerator { protected $_docs = array(); private $template; public function __construct($directory) { $this->template = file_get_contents(EXAMPLES_ROOT . '/template.php'); $this->_scanSources($directory); } protected function _scanSources($directory) { $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory, FilesystemIterator::SKIP_DOTS)); foreach ($iterator as $item) { $file = $item->getPathname(); if ($item->getExtension() == 'rst' && !strpos($file, 'Interface') && !strpos($file, 'index')) { $this->createFile($file); }
/** * Returns the current framework version. * * @return string */ public function getVersion() { if (class_exists("\\Phalcon\\Version")) { $version = \Phalcon\Version::get(); } else { $version = "git-master"; } $parts = explode(' ', $version); return '<div class="version"> Phalcon Framework <a target="_new" href="http://docs.phalconphp.com/en/' . $parts[0] . '/">' . $version . '</a> </div>'; }
/** * Tests the getId() translation to get() * * @author Nikos Dimopoulos <*****@*****.**> * @since 2012-11-29 */ public function testGetIdToGet() { $id = Version::getId(); $major = intval($id[0]); $med = intval($id[1] . $id[2]); $min = intval($id[3] . $id[4]); $special = $this->_numberToSpecial($id[5]); $specialNo = $special ? $id[6] : ''; $expected = trim("{$major}.{$med}.{$min} {$special} {$specialNo}"); $actual = Version::get(); $this->assertEquals($actual, $expected, "Version getId to get does not translate properly"); }
return $url; }); /** * Setting the View and View Engines */ $di->setShared('view', function () use($config, $di, $eventsManager) { $view = new View(); $view->registerEngines(['.volt' => function ($view, $di) use($config) { $volt = new Volt($view, $di); $path = APPLICATION_ENV == APP_TEST ? DOCROOT . 'tests/_cache/' : DOCROOT . $config->get('volt')->cacheDir; $options = ['compiledPath' => $path, 'compiledExtension' => $config->get('volt')->compiledExt, 'compiledSeparator' => $config->get('volt')->separator, 'compileAlways' => APPLICATION_ENV !== APP_PRODUCTION]; $volt->setOptions($options); $volt->getCompiler()->addFunction('strtotime', 'strtotime')->addFunction('sprintf', 'sprintf')->addFunction('str_replace', 'str_replace')->addFunction('is_a', 'is_a'); return $volt; }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php']); $view->setVar('version', Version::get())->setViewsDir(DOCROOT . $config->get('application')->viewsDir); $eventsManager->attach('view', function ($event, $view) use($di, $config) { /** * @var \Phalcon\Events\Event $event * @var \Phalcon\Mvc\View $view */ if ($event->getType() == 'notFoundView') { $message = sprintf('View not found - %s', $view->getActiveRenderPath()); throw new Exception($message); } }); $view->setEventsManager($eventsManager); return $view; }); /** * Database connection is created based in the parameters defined in the configuration file
<?php /** * Created by PhpStorm. * User: rcmonitor * Date: 07.07.15 * Time: 15:46 */ use Phalcon\Di; use Phalcon\Events\Manager; use Phalcon\Mvc\Dispatcher; use Phalcon\Mvc\Router; use Phalcon\Version; $di = new Di\FactoryDefault(); $oRouter = new Router(false); $oRouter->setDI($di); $oRouter->add('/:controller', array('controller' => 1, 'action' => 'index')); $oEventManager = new Manager(); $oEventManager->attach('dispatch:beforeDispatch', function () { return false; }); $oDispatcher = new Dispatcher(); $oDispatcher->setDI($di); $oDispatcher->setEventsManager($oEventManager); $oRouter->handle('/test'); $oDispatcher->setControllerName($oRouter->getControllerName()); $oDispatcher->setActionName($oRouter->getActionName()); $oDispatcher->dispatch(); echo $oDispatcher->getControllerClass() . PHP_EOL; echo Version::get() . PHP_EOL;
public function testModuleLoaded() { $this->assertTrue(in_array('phalcon', get_loaded_extensions()), 'Phalcon extension not properly loaded'); $this->assertGreaterThanOrEqual(2, Version::getPart(Version::VERSION_MAJOR), 'Invalid Phalcon version: "' . Version::get() . '"'); }
/** * Returns the major framework's version * * @return string */ public function getMajorVersion() { $parts = explode(' ', Version::get()); return (string) $parts[0]; }