/** * configurePath * * @return $this */ protected function configurePath() { $config = $this->config; $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']); return $this; }
/** * prepareExecute * * @return void */ protected function prepareExecute() { $element = $this->getArgument(1); $client = strtolower($this->getOption('c')); $class = $this->getOption('class'); if ($element) { list($type, $name, $group) = array_values(ExtensionHelper::extractElement($element)); if ($client == 'admin') { $client = 'administrator'; } if ($type == 'plugin') { $client = 'site'; } elseif ($type == 'component') { $client = 'administrator'; } } $path = JPATH_ROOT . '/resources/seeders'; $classPath = $path . '/' . $class . '.php'; if (!file_exists($classPath) && $element) { $path = PathHelper::get($element, $client); $classPath = $path . '/src/' . ucfirst($name) . '/Seed/' . $class . '.php'; } if (file_exists($classPath)) { include_once $classPath; } $className = $class; if (!class_exists($className)) { $className = sprintf('%s\\Seed\\%s', ucfirst($name), ucfirst($class)); } if (!class_exists($className)) { throw new \UnexpectedValueException('Class: ' . $class . ' not found.'); } // Auto include classes $path = dirname(ReflectionHelper::getPath($className)); $files = \JFolder::files($path, '.', false, true); /** @var \SplFileInfo $file */ foreach ($files as $file) { $file = new \SplFileInfo($file); \JLoader::register($file->getBasename('.php'), $file->getPathname()); } $this->app->set('seed.class', $className); }
/** * 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); }
/** * Execute Component. * * @param string $option Component option name. * @param string $client `admin` or `site`. * @param array $input Input object. * * @return mixed */ public static function executeComponent($option, $client = 'site', $input = array()) { $element = ExtensionHelper::extractElement($option); $input = new \JInput($input); // Prevent class conflict class_alias('JString', 'Joomla\\String\\String'); if (!defined('JPATH_COMPONENT_ADMINISTRATOR')) { define('JPATH_COMPONENT_ADMINISTRATOR', PathHelper::get($option, 'admin')); define('JPATH_COMPONENT_SITE', PathHelper::get($option, 'site')); define('JPATH_COMPONENT', PathHelper::get($option, $client)); } $_SERVER['HTTP_HOST'] = 'windwalker'; if ($client == 'admin') { $client = 'administrator'; } $appClass = 'JApplication' . ucfirst($client); $console = \JFactory::$application; \JFactory::$application = $appClass::getInstance('site', $input); $class = ucfirst($element['name']) . 'Component'; $component = new $class(ucfirst($element['name']), $input, \JFactory::$application); $result = $component->execute(); \JFactory::$application = $console; return $result; }
/** * Get search fields from form xml. * * @return array Search fields. */ public function getSearchFields() { if ($this->searchFields) { return $this->searchFields; } $file = PathHelper::get($this->option) . '/model/form/' . $this->name . '/filter.xml'; if (!is_file($file)) { return array(); } $xml = simplexml_load_file($file); $field = $xml->xpath('//fields[@name="search"]/field[@name="field"]'); $options = $field[0]->option; $fields = array(); foreach ($options as $option) { $attr = $option->attributes(); if ('*' == (string) $attr['value']) { continue; } $fields[] = (string) $attr['value']; } return $this->searchFields = $fields; }
/** * Load language from an extension. * * @param string $ext Extension element name, eg: com_content, plg_group_name. * @param string $client site or admin. * * @return boolean */ public static function loadLanguage($ext, $client = 'site') { $lang = Container::getInstance()->get('language'); return $lang->load($ext, JPATH_BASE, null, false, false) || $lang->load($ext, PathHelper::get($ext, $client), null, false, false) || $lang->load($ext, JPATH_BASE, null, true) || $lang->load($ext, PathHelper::get($ext, $client), null, true); }
/** * testException * * @expectedException InvalidArgumentException * * @return void */ public function testException() { PathHelper::get(null, null, null); }