/** * render * * @return AbstractFileProcessor */ public function render() { $this->prepareGlobals($this->getData()); $file = $this->findPaths(); if ($file === null) { throw new \UnexpectedValueException('Layout: ' . $this->getLayout() . ' not found'); } $processor = AbstractFileProcessor::getInstance($file->getExtension(), $file, $this->path, $this->config->get('layout.folder')); $processor->setData($this->getData()); $processor->render(); return $processor; }
/** * Set a registry value. * * @param string $path Registry Path (e.g. joomla.content.showauthor) * @param mixed $value Value of entry * @param string $separator The key separator * * @return mixed The value of the that has been set. * * @since 1.0 */ public function set($path, $value, $separator = '.') { $bak = $this->registry->getSeparator(); $this->registry->setSeparator($separator); $this->registry->set($path, $value); $this->registry->setSeparator($bak); return $this->registry->get($path); }
/** * Render view. * * @return string|void */ public function doRender() { // Init some API objects // ================================================================================ $container = $this->getContainer(); $input = $container->get('input'); $config = new Registry($this->config); // Set E_ALL for debugging error_reporting($config->get('error_reporting', 0)); $elfinder_path = WINDWALKER . '/src/Elfinder/Connect/'; include_once $elfinder_path . 'elFinderConnector.class.php'; include_once $elfinder_path . 'elFinder.class.php'; include_once $elfinder_path . 'elFinderVolumeDriver.class.php'; /** * Simple function to demonstrate how to control file access using "accessControl" callback. * This method will disable accessing files/folders starting from '.' (dot) * * @param string $attr attribute name (read|write|locked|hidden) * @param string $path file path relative to volume root directory started with directory separator * * @return bool|null */ function access($attr, $path) { // If file/folder begins with '.' (dot). Set read+write to false, other (locked+hidden) set to true if (strpos(basename($path), '.') === 0) { return !($attr == 'read' || $attr == 'write'); } else { return null; } } // Get Some Request $root = $input->getPath('root', '/'); $start_path = $input->getPath('start_path', '/'); $this->createFolder($root); $this->createFolder($root . '/' . $start_path); $opts = array('roots' => array(array('driver' => 'LocalFileSystem', 'path' => JPath::clean(JPATH_ROOT . '/' . $root, '/'), 'startPath' => JPath::clean(JPATH_ROOT . '/' . $root . '/' . $start_path . '/'), 'URL' => JPath::clean(JURI::root(true) . '/' . $root . '/' . $start_path, '/'), 'tmbPath' => JPath::clean(JPATH_ROOT . '/cache/windwalker-finder-thumb'), 'tmbURL' => JURI::root(true) . '/cache/windwalker-finder-thumb', 'tmp' => JPath::clean(JPATH_ROOT . '/tmp/windwalker-finder-temp'), 'accessControl' => 'access', 'uploadDeny' => array('text/x-php'), 'disabled' => array('archive', 'extract', 'rename', 'mkfile'), 'quarantine' => JPATH_ROOT . '/tmp/.quarantine'))); $opts = (array) $config->get('option') ?: $opts; foreach ($opts['roots'] as $driver) { include_once $elfinder_path . 'elFinderVolume' . $driver['driver'] . '.class.php'; } // Run elFinder $connector = new elFinderConnector(new elFinder($opts)); $connector->run(); exit; }
/** * getTwig * * @param bool $new * * @return \Twig_Environment */ public function getEngine($new = false) { if (!$this->engine instanceof \Twig_Environment || $new) { $this->engine = new \Twig_Environment($this->getLoader(), $this->config->toArray()); foreach (GlobalContainer::getExtensions() as $extension) { $this->engine->addExtension(clone $extension); } foreach ($this->extensions as $extension) { $this->engine->addExtension($extension); } foreach (GlobalContainer::getGlobals() as $name => $value) { $this->engine->addGlobal($name, $value); } if ($this->config->get('debug')) { $this->engine->addExtension($this->getDebugExtension()); } } return $this->engine; }
/** * Constructor. * * @param \Windwalker\DI\Container $container * @param \Muse\IO\IOInterface $io * @param Registry $config */ public function __construct(Container $container, IOInterface $io, Registry $config = null) { // Get item & list name $ctrl = $config['ctrl'] ?: $io->getArgument(1); $ctrl = explode('.', $ctrl); $inflector = \JStringInflector::getInstance(); if (empty($ctrl[0])) { $ctrl[0] = 'item'; } if (empty($ctrl[1])) { $ctrl[1] = $inflector->toPlural($ctrl[0]); } list($itemName, $listName) = $ctrl; $replace['extension.element.lower'] = strtolower($config['element']); $replace['extension.element.upper'] = strtoupper($config['element']); $replace['extension.element.cap'] = ucfirst($config['element']); $replace['extension.name.lower'] = strtolower($config['name']); $replace['extension.name.upper'] = strtoupper($config['name']); $replace['extension.name.cap'] = ucfirst($config['name']); $replace['controller.list.name.lower'] = strtolower($listName); $replace['controller.list.name.upper'] = strtoupper($listName); $replace['controller.list.name.cap'] = ucfirst($listName); $replace['controller.item.name.lower'] = strtolower($itemName); $replace['controller.item.name.upper'] = strtoupper($itemName); $replace['controller.item.name.cap'] = ucfirst($itemName); // Set replace to config. foreach ($replace as $key => $val) { $config->set('replace.' . $key, $val); } // Set copy dir. $config->set('dir.dest', PathHelper::get(strtolower($config['element']), $config['client'])); $config->set('dir.tmpl', GENERATOR_BUNDLE_PATH . '/Template/' . $config['extension'] . '/' . $config['template']); $config->set('dir.src', $config->get('dir.tmpl') . '/' . $config['client']); // Replace DS $config['dir.dest'] = Path::clean($config['dir.dest']); $config['dir.tmpl'] = Path::clean($config['dir.tmpl']); $config['dir.src'] = Path::clean($config['dir.src']); // Push container $this->container = $container; parent::__construct($io, $config, $replace); }
/** * Get a property. * * @param mixed $offset Offset key. * * @throws \InvalidArgumentException * @return mixed The value to return. */ public function offsetGet($offset) { return $this->state->get($offset); }
/** * Get config. * * @param string $key Config key. * @param string $default Default value if not exists. * * @return mixed */ public function get($key, $default) { return $this->config->get($key, $default); }
/** * Reset cache position. * * @return void */ public function resetCachePosition() { if ($this->extension) { $params = ExtensionHelper::getParams($this->extension); } else { $params = new Registry(); } $this->config = new Registry(); $this->config['path.cache'] = Path::clean(JPATH_ROOT . $params->get('thumb.cache-path', '/cache/thumbs/cache')); $this->config['path.temp'] = Path::clean(JPATH_ROOT . $params->get('thumb.temp-path', '/cache/thumbs/temp')); $this->config['url.cache'] = $params->get('thumb.cache-url', '/cache/thumbs/cache'); $this->config['url.temp'] = $params->get('thumb.temp-url', '/cache/thumbs/cache'); }
/** * Method to test set(). * * @return void * * @covers Windwalker\Registry\Registry::set * @TODO Implement testSet(). */ public function testSet() { $this->instance->set('tree.bird', 'sleeping'); $this->assertEquals($this->instance->get('tree.bird'), 'sleeping'); }
/** * Execute the controller. * * @return boolean True if controller finished execution, false if the controller did not * finish execution. A controller might return false if some precondition for * the controller to run has not been satisfied. * * @throws \LogicException * @throws \RuntimeException */ public function execute() { $package = $this->io->getArgument(0, new ValidatePrompter('Enter package name: ')); $class = $this->io->getArgument(1, new ValidatePrompter('Enter class name: ')); $class = StringNormalise::toClassNamespace($class); $target = $this->io->getArgument(2, $package . '\\' . $class . 'Test'); $target = StringNormalise::toClassNamespace($target); $package = ucfirst($package); if (!class_exists($class)) { $class = 'Windwalker\\' . $package . '\\' . $class; } if (!class_exists($class)) { $this->out('Class not exists: ' . $class); exit; } $replace = $this->replace; $ref = new \ReflectionClass($class); $replace['origin.class.dir'] = dirname($ref->getFileName()); $replace['origin.class.file'] = $ref->getFileName(); $replace['origin.class.name'] = $ref->getName(); $replace['origin.class.shortname'] = $ref->getShortName(); $replace['origin.class.namespace'] = $ref->getNamespaceName(); $replace['test.dir'] = WINDWALKER_ROOT . DIRECTORY_SEPARATOR . 'test'; $replace['test.class.name'] = 'Windwalker\\Test\\' . $target; $replace['test.class.file'] = Path::clean($replace['test.dir'] . DIRECTORY_SEPARATOR . $target . '.php'); $replace['test.class.dir'] = dirname($replace['test.class.file']); $replace['test.class.shortname'] = $this->getShortname(StringNormalise::toClassNamespace($replace['test.class.name'])); $replace['test.class.namespace'] = $this->getNamespace($replace['test.class.name']); $this->replace = $replace; $config = new Registry(); // Set replace to config. foreach ($this->replace as $key => $val) { $config->set('replace.' . $key, $val); } $methods = $ref->getMethods(\ReflectionMethod::IS_PUBLIC); $methodTmpl = file_get_contents(GENERATOR_BUNDLE_PATH . '/Template/test/testMethod.php'); $methodCodes = array(); foreach ($methods as $method) { $config['replace.origin.method'] = $method->getName(); $config['replace.test.method'] = ucfirst($method->getName()); $methodCodes[] = StringHelper::parseVariable($methodTmpl, $config->get('replace')); } $config['replace.test.methods'] = implode("", $methodCodes); $this->replace = $config->get('replace'); $this->config = $config; $this->doAction(new GenClassAction()); $this->out('Generate test class: ' . $replace['test.class.name'] . ' to file: ' . $replace['test.class.file'])->out(); return true; }
/** * Modifies a property of the object, creating it if it does not already exist. * * @param string $key The name of the property. * @param mixed $value The value of the property to set (optional). * * @return mixed Previous value of the property * * @since 2.0 */ public function set($key, $value = null) { $previous = $this->config->get($key); $this->config->set($key, $value); return $previous; }
/** * prepareSystemPath * * @param Registry $config * * @return void */ public static function prepareSystemPath(Registry $config) { $config['path.root'] = WINDWALKER_ROOT; $config['path.bin'] = WINDWALKER_BIN; $config['path.cache'] = WINDWALKER_CACHE; $config['path.etc'] = WINDWALKER_ETC; $config['path.logs'] = WINDWALKER_LOGS; $config['path.resources'] = WINDWALKER_RESOURCES; $config['path.source'] = WINDWALKER_SOURCE; $config['path.temp'] = WINDWALKER_TEMP; $config['path.vendor'] = WINDWALKER_VENDOR; $config['path.public'] = WINDWALKER_PUBLIC; $config['path.migrations'] = WINDWALKER_MIGRATIONS; $config['path.seeders'] = WINDWALKER_SEEDERS; $config['path.languages'] = WINDWALKER_LANGUAGES; switch ($config['mode']) { case 'test': $root = WINDWALKER_ROOT; break; default: $env = new Environment(); $root = $env->server->getWorkingDirectory(); $root = $root ?: WINDWALKER_ROOT; break; } $data = $config->get('outer_project') ? $root . '/.vaseman' : $root; $config['path.templates'] = $data . '/layouts'; $config->set('project.path.root', $root); $config->set('project.path.data', $data); $config->set('project.path.entries', WINDWALKER_ROOT . '/entries'); $config->set('project.path.layouts', WINDWALKER_ROOT . '/layouts'); }
/** * Writes a configuration button and invokes a cancel operation (eg a checkin). * * @param string $component The name of the component, eg, com_content. * @param string $alt The name of the button. * @param string $path An alternative path for the configuation xml relative to JPATH_SITE. * * @return void */ public function preferences($component = null, $alt = 'JToolbar_Options', $path = '') { $component = $component ?: $this->config->get('option', Container::getInstance()->get('input')->get('option')); $component = urlencode($component); JToolbarHelper::preferences($component, $alt, $path); }
use Windwalker\Registry\Registry; use League\Route\RouteCollection; //use Symfony\Component\HttpFoundation\RedirectResponse as Redirect; $router = new RouteCollection(); $request = Request::createFromGlobals(); $registry = new Registry(); $registry->set('config.posibile-hoteluri', ['perla', 'parc']); $registry->set('config.string_hotel_identifier_limit', 3); /** * Helpers */ $registry->set('helper.generator-hotel-item-body', function ($identifier) use($registry) { return ['identifier' => $identifier, 'name' => 'Hotel ' . ucwords($identifier) . ' ' . str_repeat('*', strlen($identifier)), 'mobile' => '0421.000.000', 'country' => 'Romania', 'geo' => ['lat' => '41.222', 'lon' => '26.222'], '@self' => '/hotel/' . $identifier, '@rooms' => '/rooms?hotel=' . $identifier]; }); $registry->set('helper.generator-room-number', function ($args) use($registry) { $charLimit = $registry->get('config.string_hotel_identifier_limit'); $prefix = strtoupper(substr(md5($args['hotelIdentifier']), 0, $charLimit)); $padding = str_pad($args['number'], 5, 0); return $prefix . $padding . $args['number']; }); $registry->set('helper.generator-room-item-body', function ($roomIdentifier, $hotelIdentifier) use($registry) { $charLimit = $registry->get('config.string_hotel_identifier_limit'); return ['identifier' => $roomIdentifier, 'name' => 'Room ' . substr($roomIdentifier, $charLimit + 1), '@self' => '/room/' . $roomIdentifier, '@hotel' => '/hotel/' . $hotelIdentifier]; }); $registry->set('helper.find-hotel-by-room-identifier', function ($roomIdentifier) use($registry) { $demoList = $registry->get('config.posibile-hoteluri'); /** @var Closure $roomNumberGenerator */ $roomNumberGenerator = $registry->get('helper.generator-room-number'); $roomIdentifier = strtoupper($roomIdentifier); foreach ($demoList as $hotelIdentifier) { $roomsPerHotel = strlen($hotelIdentifier);
/** * testUnshift * * @return void * * @covers Windwalker\Registry\Registry::unshift */ public function testUnshift() { $registry = new Registry(); $registry->set('foo', array('var1', 'var2', 'var3')); $registry->unshift('foo', 'var4'); $this->assertEquals('var4', $registry->get('foo.0')); $registry->unshift('foo', 'var5', 'var6'); $this->assertEquals('var5', $registry->get('foo.0')); $this->assertEquals('var6', $registry->get('foo.1')); $registry->setRaw('foo2', (object) array('var1', 'var2', 'var3')); $b = $registry->get('foo2'); $this->assertTrue(is_object($b)); $registry->unshift('foo2', 'var4'); $b = $registry->get('foo2'); $this->assertTrue(is_array($b)); }