public function __construct($engineName = null) { Runtime::loadModule('mvc'); if ($engineName) { parent::__construct($engineName); } }
/** * Issues a uses() command inside a new runtime for every class given * and returns a line indicating success or failure for each of them. * * @param string[] uses * @param string decl * @return var[] an array with three elements: exitcode, stdout and stderr contents */ protected function useAllOf($uses, $decl = '') { with($out = $err = '', $p = Runtime::getInstance()->newInstance(NULL, 'class', 'xp.runtime.Evaluate', array())); $p->in->write($decl . ' ClassLoader::registerPath(\'' . strtr($this->getClass()->getClassLoader()->path, '\\', '/') . '\'); $errors= 0; foreach (array("' . implode('", "', $uses) . '") as $class) { try { uses($class); echo "+OK ", $class, "\\n"; } catch (Throwable $e) { echo "-ERR ", $class, ": ", $e->getClassName(), "\\n"; $errors++; } } exit($errors); '); $p->in->close(); // Read output while ($b = $p->out->read()) { $out .= $b; } while ($b = $p->err->read()) { $err .= $b; } // Close child process $exitv = $p->close(); return array($exitv, explode("\n", rtrim($out)), explode("\n", rtrim($err))); }
public static function create($controller, $method, $args = null, $project = null, $absolute = false) { $link = "/{$controller}/{$method}"; if (is_array($args)) { $app_params = array(); $get_params = array(); $arg_indexes = array_keys($args); foreach ($arg_indexes as $i => $key) { if ($key == (string) $i) { //numerical index //App param $app_params[] = $args[$key]; } else { //associative index //GET Param $get_params[$key] = $args[$key]; } } if (count($app_params) > 0) { $link .= '/' . implode('/', $app_params); } if (count($get_params) > 0) { $link .= '?' . http_build_query($get_params); } } if ($project) { $link = "/~{$project}" . $link; } else { if ($absolute) { $link = "/~" . Runtime::currentProject()->name . $link; } } return '/' . trim(trim(self::base(), '/') . "{$link}", '/'); }
public static function initController() { $id = Request::get('Currency', null, 'COOKIE'); $Current = new Currency(); $Default = Currency::findDefault(); $code = null; if (function_exists('geoip_record_by_name')) { $arr = @geoip_record_by_name(Request::get('REMOTE_ADDR', '', 'SERVER')); $code = isset($arr['country_code']) ? $arr['country_code'] : null; } $arr = Currency::findCurrencies(true); foreach ($arr as $i => $Currency) { if ($Currency->Id == $id) { $Current = $Currency; break; } } if (!$Current->Id && $code) { foreach ($arr as $Currency) { if ($Currency->hasCountry($code)) { $Current = $Currency; break; } } } if (!$Current->Id) { foreach ($arr as $Currency) { $Current = $Currency; break; } } Runtime::set('CURRENCY_DEFAULT', $Default); Runtime::set('CURRENCY_CURRENT', $Current); return false; }
public function newInstance() { $p = Runtime::getInstance()->getExecutable()->newInstance($this->arguments('-v')); $version = defined('HHVM_VERSION') ? 'HipHop VM ' . HHVM_VERSION : 'PHP ' . PHP_VERSION; $this->assertEquals($version, $p->out->read(strlen($version))); $p->close(); }
/** * @see \Components\Http_Scriptlet::dispatch() dispatch */ public static function dispatch(Http_Scriptlet_Context $context_, Uri $uri_) { $response = $context_->getResponse(); $content = null; try { // FIXME Temporary fix - create a explicit route for ui/scriptlet/embedded. if (Environment::isEmbedded()) { $scriptlet = new Ui_Scriptlet_Embedded(); $scriptlet->request = $context_->getRequest(); $scriptlet->response = $context_->getResponse(); $method = $scriptlet->request->getMethod(); if (false === method_exists($scriptlet, strtolower($method))) { throw new Http_Exception('ui/scriptlet', null, Http_Exception::NOT_FOUND); } $content = $scriptlet->{$method}(); } else { $content = parent::dispatch($context_, $uri_); } } catch (\Exception $e) { Runtime::addException($e); if ($e instanceof Http_Exception) { $e->sendHeader(); } } echo $content; }
/** * Setup this test case * */ public function setUp() { if (!Runtime::getInstance()->extensionAvailable('sockets')) { throw new PrerequisitesNotMetError('Sockets extension not available', NULL, array('ext/sockets')); } parent::setUp(); }
public function newInstance() { $p = Runtime::getInstance()->getExecutable()->newInstance(array('-v')); $version = 'PHP ' . phpversion(); $this->assertEquals($version, $p->out->read(strlen($version))); $p->close(); }
/** * Retrieve configuration setting from config.php * overrided with relative config mode file * * @return type */ public static function config() { // base-config file not found create with setup.php $configBaseFile = __BASE__ . '/config.php'; // if (!file_exists($configBaseFile)) { Runtime::error('file not found: ' . $configBaseFile, 101); } // $configBase = (include $configBaseFile); // if (!is_array($configBase)) { Runtime::error("empty or corrupted 'config.php' " . "run '<a href='setup.php'>setup.php</a>'", 110); } // $configModeFile = __BASE__ . '/config/' . __NAME__ . '.' . __MODE__ . '.php'; // if (!file_exists($configModeFile)) { Runtime::error('file not found: ' . $configModeFile, 102); } // $configMode = (include $configModeFile); // $configDefault = array('default' => array('code' => 'Default', 'action' => 'index')); // $config = array_replace_recursive($configDefault, $configBase, $configMode); // return Functions::arrayToObject($config); }
/** * Setup method. Ensure extension we depend on is available * */ public function setUp() { $depend = $this->extension(); if (!Runtime::getInstance()->extensionAvailable($depend)) { throw new PrerequisitesNotMetError(ucfirst($depend) . ' support not available', NULL, array('ext/' . $depend)); } }
/** * Set up test and create fixture * */ public function setUp() { if (!Runtime::getInstance()->extensionAvailable('soap')) { throw new PrerequisitesNotMetError('PHP Soap extension not available', NULL, array('ext/soap')); } $this->fixture = new NativeSoapTypeMapper(); }
/** * @GET * @POST */ public function clear() { if (false === Runtime::isManagementAccess()) { throw new Http_Exception('cache/resource', null, Http_Exception::FORBIDDEN); } Cache::clear(); clearstatcache(true); }
/** * Setup this test. Creates a 1x1 pixel image filled with white. * */ public function setUp() { if (!Runtime::getInstance()->extensionAvailable('gd')) { throw new PrerequisitesNotMetError('GD extension not available'); } $this->image = Image::create(1, 1); $this->image->fill($this->image->allocate(new Color('#ffffff'))); }
public function ls() { Runtime::loadModule('rom'); $items = array('name' => '', 'age' => '12'); $form = Validation\Validation::parse('vld', $items); $this->data->form = $form; $this->data->report = $form->validate(); $this->data->fsm = \FSM\Engine::parse('site'); }
/** * @return \Components\Text_Html_Tidy */ public function parse() { $charset = strtolower(str_replace(['-', '_'], null, $this->m_charset->name())); $config = $this->config; $config['char-encoding'] = $charset; $config['drop-proprietary-attributes'] = !$this->ignoreProprietaryAttributes; Runtime::pushRuntimeErrorHandler($this); $this->m_tidy->parseString($this->m_html, $config, $charset); Runtime::popRuntimeErrorHandler($this); return $this; }
/** * @param Runtime $runtime * @param string $channel * * @return mixed */ public function send($runtime, $channel = '') { $warnings = $runtime->getWarnings(); if (count($warnings) > 0) { switch ($channel) { case 'dump': print $this->format($warnings); break; case 'hidden': print '<!--' . $this->format($warnings) . '-->'; break; case 'none': // fall through to default // fall through to default default: // do nothing break; } } }
/** * Download an url and return or store contents. * * @param string $url * @param bool $file * * @return bool|null|string * @throws \Exception */ public static function download($url, $file = false) { if (Runtime::isCurlEnabled()) { return static::curlDownload($url, $file); } else { if (Runtime::isAllowUrlFopenEnabled()) { return static::fgetDownload($url, $file); } else { throw new \RuntimeException('No download mechanism available'); } } }
/** * Sets up test case * */ public function setUp() { parent::setUp(); $this->vendor = $this->vendorName(); // Check whether any PHP extensions are required by a specific test, // and skip if this extension is not loaded. This is done by checking // for an @ext annotation. $m = $this->getClass()->getMethod($this->name); if ($m->hasAnnotation('ext') && !Runtime::getInstance()->extensionAvailable($ext = $m->getAnnotation('ext'))) { throw new PrerequisitesNotMetError('Extension not available', NULL, array($ext)); } }
/** * Throws an deprecated exception if given version is older than * the current project version. * * If no message is given, an auto-generated message will be used * which contains type/method & location where this method has been * invoked - respectively the location of the deprecated code. * * @param string $namespace_ * @param \Components\Version $version_ * @param string $message_ * * @throws \Components\Deprecated */ public static function since($namespace_, Version $version_, $message_ = null) { // ignore for production. if (Environment::isLive()) { return; } if (0 > Runtime::version()->compareTo($version_)) { if (null === $message_) { throw static::createDefaultException($namespace_); } throw new static($namespace_, $message_, null, true); } }
/** * The function returns Captcha object. * * @static * @access public * @return object The Captcha. */ public static function getCaptcha() { if (self::$instance === null) { include_once Runtime::get('LIBS_DIR') . '/secureimage/securimage.php'; self::$instance = new Securimage(); self::$instance->code_length = 4; self::$instance->image_width = 80; self::$instance->shadow_text = true; self::$instance->line_color = '#3399ee'; self::$instance->arc_line_colors = '#3399ee'; self::$instance->text_color = '#1177cc'; } return self::$instance; }
public function buildNavigation($path) { //var_dump($path); //http://localhost/bong/index.php/controllerName/methodName/arg1/arg2/+spiritName/methodName/spiritArg1/spiritArg2/+spiritName2/methodName/args $this->navigation->controllerName = null; $this->navigation->methodName = null; $this->navigation->args = array(); $this->navigation->spirits = array(); $racks = array(); foreach ($path as $i => $urlSection) { if (strlen($urlSection) > 0 && $urlSection[0] == '+') { $racks[] = array(); } $racks[count($racks) == 0 ? count($racks) : count($racks) - 1][] = $urlSection; } foreach ($racks as $i => &$rack) { if ($i == 0) { $this->navigation->controllerName = isset($rack[0]) && !empty($rack[0]) ? $rack[0] : Conf::instance()->evaluate('default.controller'); $this->navigation->methodName = isset($rack[1]) && !empty($rack[1]) ? $rack[1] : Conf::instance()->evaluate('default.method'); for ($i = 2; $i < count($rack); ++$i) { $this->navigation->args[] = $rack[$i]; } } else { if (count($rack) > 1) { //Ignore if no MethodName is provided $spirit = new stdClass(); $spirit->spiritName = substr($rack[0], 1); //remove the + sign $spirit->methodName = $rack[1]; $spirit->args = array(); for ($i = 2; $i < count($rack); ++$i) { $spirit->args[] = $rack[$i]; } $this->navigation->spirits[] = $spirit; } } } if (is_null($this->navigation->controllerName)) { $this->navigation->controllerName = 'default'; } if (is_null($this->navigation->methodName)) { $this->navigation->methodName = 'main'; } MemPool::instance()->set('bong.mvc.controller', $this->navigation->controllerName); MemPool::instance()->set('bong.mvc.method', $this->navigation->methodName); Runtime::loadModule('mvc'); //print_r($this->navigation); }
public function ctor() { Runtime::loadModule('admin'); ControllerTray::instance()->renderLayout = false; $this->_xdo = ControllerXDO::unpack('project'); $this->_xdo->unserialize(); if (Backend::ExistsUnSessioned('explorer.' . $this->_xdo->project->name)) { $this->_backend = Backend::LoadUnSessioned('explorer.' . $this->_xdo->project->name); } else { $this->_backend = Structs\Admin\Project::create($this->_xdo->project->name); /*Create From reflection*/ } if (isset($this->_xdo->controllerName)) { $this->_controllerName = $this->_xdo->controllerName; } }
/** * @return \Components\Test_Cli */ public static function get() { $instance = new static(); $year = date('Y'); $version = (string) Runtime::version(); $instance->addOption('p', true, null, 'test root path', 'path'); $instance->addOption('b', true, null, 'build path', 'build'); $instance->addOption('c', true, null, 'configuration path', 'config'); $instance->addEmptyOption(); $instance->addOption('a', true, null, 'enable static code analyzers [emma,..]', 'analyzers'); $instance->addEmptyOption(); $instance->addOption('h', false, null, 'print command line instructions', 'help'); $instance->addOption('v', false, null, 'print program version & license', 'version'); $instance->setInfo(sprintf('%1$s%3$s%2$s%3$s', "Test Executor {$version}, net.evalcode.components", "Copyright (C) {$year} evalcode.net", Io::LINE_SEPARATOR_DEFAULT)); return $instance; }
/** * {@inheritDoc} * * Ignores everything but 'context' */ public function loadFile($file) { $context = $this->container->getParameter('kernel.context'); $config = array(); $yaml = Yaml::parse($file); foreach ($yaml as $key => $data) { if ('meta' == $key) { continue; } // context key if (Runtime::isContextMatch($key, $context)) { $config = Toolbox::arrayMergeRecursive($config, $data); } } die(var_dump(__FILE__, $yaml)); return $this->validate($config, $file); }
/** * Issues a uses() command inside a new runtime for every class given * and returns a line indicating success or failure for each of them. * * @param string[] uses * @param string src * @return var[] an array with three elements: exitcode, stdout and stderr contents */ protected function runInNewRuntime($uses, $src) { with($out = $err = '', $p = Runtime::getInstance()->newInstance(NULL, 'class', 'xp.runtime.Evaluate', array())); $uses && $p->in->write('uses("' . implode('", "', $uses) . '");'); $p->in->write($src); $p->in->close(); // Read output while ($b = $p->out->read()) { $out .= $b; } while ($b = $p->err->read()) { $err .= $b; } // Close child process $exitv = $p->close(); return array($exitv, $out, $err); }
/** * Starts server in background * * @param string protocol */ public static function startServerWith($protocol) { // Start server process with($rt = Runtime::getInstance()); self::$serverProcess = $rt->getExecutable()->newInstance(array_merge($rt->startupOptions()->asArguments(), array($rt->bootstrapScript('class')), array('net.xp_framework.unittest.peer.server.TestingServer', $protocol))); self::$serverProcess->in->close(); // Check if startup succeeded $status = self::$serverProcess->out->readLine(); if (2 != sscanf($status, '+ Service %[0-9.]:%d', self::$bindAddress[0], self::$bindAddress[1])) { try { self::shutdownServer(); } catch (IllegalStateException $e) { $status .= $e->getMessage(); } throw new PrerequisitesNotMetError('Cannot start server: ' . $status, NULL); } }
/** * Create a new runtime * * @return var[] an array with three elements: exitcode, stdout and stderr contents */ protected function run() { $runtime = Runtime::getInstance(); $options = $runtime->startupOptions()->withSetting('magic_quotes_gpc', 1)->withSetting('error_reporting', 'E_ALL'); $out = $err = ''; with($p = $runtime->newInstance($options, 'class', 'xp.runtime.Evaluate', array('return 1;'))); $p->in->close(); // Read output while ($b = $p->out->read()) { $out .= $b; } while ($b = $p->err->read()) { $err .= $b; } // Close child process $exitv = $p->close(); return array($exitv, $out, $err); }
public static function startFtpServer() { // Arguments to server process $args = array('debugServerProtocolToFile' => NULL); // Start server process self::$serverProcess = Runtime::getInstance()->newInstance(NULL, 'class', 'net.xp_framework.unittest.peer.ftp.TestingServer', array_values($args)); self::$serverProcess->in->close(); // Check if startup succeeded $status = self::$serverProcess->out->readLine(); if (1 != sscanf($status, '+ Service %[0-9.:]', self::$bindAddress)) { try { self::shutdownFtpServer(); } catch (IllegalStateException $e) { $status .= $e->getMessage(); } throw new PrerequisitesNotMetError('Cannot start FTP server: ' . $status, NULL); } }
public static function startApplicationServer() { // Arguments to server process $args = array('debugServerProtocolToFile' => NULL); // Start server process self::$serverProcess = Runtime::getInstance()->newInstance(NULL, 'class', 'net.xp_framework.unittest.remote.TestingServer', array_values($args)); self::$serverProcess->in->close(); // Check if startup succeeded $status = self::$serverProcess->out->readLine(); if (2 != sscanf($status, '+ Service %[0-9.]:%d', self::$bindAddress[0], self::$bindAddress[1])) { try { self::shutdownApplicationServer(); } catch (IllegalStateException $e) { $status .= $e->getMessage(); } throw new PrerequisitesNotMetError('Cannot start EASC server: ' . $status, NULL); } // Add classloader with CalculatorBean client classes $a = XPClass::forName(xp::nameOf(__CLASS__))->getPackage()->getPackage('deploy')->getResourceAsStream('beans.test.CalculatorBean.xar'); self::$clientClassesLoader = ClassLoader::registerLoader(new ArchiveClassLoader(new Archive($a))); }
private function modelName() { $index = -1; $modelPath = $this->model($index); switch ($index) { case 0: $modelName = ucfirst($this->navigation->controllerName) . ucfirst($this->navigation->methodName) . 'Model'; break; case 1: $modelName = ucfirst($this->navigation->controllerName) . 'Model'; break; case 2: $modelName = ucfirst(Runtime::currentProject()->name) . 'Model'; break; case 3: $modelName = 'BongAppModel'; break; default: //TODO Handle Error } return $modelName; }