/**
  * Constructor.
  *
  * @param   \Windwalker\DI\Container $container
  * @param   \Muse\IO\IOInterface     $io
  * @param   Structure                $config
  *
  * @throws \InvalidArgumentException
  */
 public function __construct(Container $container, IOInterface $io, Structure $config = null)
 {
     // Get item & list name
     $ctrl = $config['ctrl'] ?: $io->getArgument(1);
     $ctrl = explode('.', $ctrl);
     $inflector = StringInflector::getInstance();
     if (empty($ctrl[0])) {
         $ctrl[0] = 'item';
     }
     if (empty($ctrl[1])) {
         $ctrl[1] = $inflector->toPlural($ctrl[0]);
     }
     list($itemName, $listName) = $ctrl;
     // Prepare package name
     $class = explode('\\', str_replace('/', '\\', $config['name']));
     $name = array_pop($class);
     $class = StringNormalise::toClassNamespace(implode('\\', $class));
     $class = $class ? $class . '\\' : null;
     // Check keywords
     if (in_array(strtolower($name), static::$keywords)) {
         throw new \InvalidArgumentException('Do not use reserved keywords: ' . $name);
     }
     if (in_array(strtolower($listName), static::$keywords)) {
         throw new \InvalidArgumentException('Do not use reserved keywords: ' . $listName);
     }
     if (in_array(strtolower($itemName), static::$keywords)) {
         throw new \InvalidArgumentException('Do not use reserved keywords: ' . $itemName);
     }
     $config['package.name'] = $name;
     $config['package.namespace'] = $class;
     $this->replace = new Structure();
     $this->replace['package.namespace'] = $class;
     $this->replace['package.name.lower'] = lcfirst($name);
     $this->replace['package.name.upper'] = strtoupper($name);
     $this->replace['package.name.cap'] = ucfirst($name);
     $this->replace['controller.list.name.lower'] = strtolower($listName);
     $this->replace['controller.list.name.upper'] = strtoupper($listName);
     $this->replace['controller.list.name.cap'] = ucfirst($listName);
     $this->replace['controller.item.name.lower'] = strtolower($itemName);
     $this->replace['controller.item.name.upper'] = strtoupper($itemName);
     $this->replace['controller.item.name.cap'] = ucfirst($itemName);
     // Set replace to config.
     $config->mergeTo('replace', $this->replace);
     // Set copy dir.
     $config->set('dir.dest', WINDWALKER_SOURCE . '/' . $this->replace['package.namespace'] . $this->replace['package.name.cap']);
     $config->set('dir.tmpl', PHOENIX_TEMPLATES . '/package/' . $config['template']);
     $config->set('dir.src', $config->get('dir.tmpl'));
     // 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, $this->replace->toArray());
 }
 /**
  * Instantiate the controller.
  *
  * @param   \JInput           $input   The input object.
  * @param   \JApplicationCms  $app     The application object.
  * @param   array             $config  Alternative config.
  */
 public function __construct(\JInput $input = null, \JApplicationCms $app = null, $config = array())
 {
     parent::__construct($input, $app, $config);
     // Guess the item view as the context.
     $this->viewList = $this->viewList ?: ArrayHelper::getValue($config, 'view_list', $this->getName());
     // Guess the list view as the plural of the item view.
     $this->viewItem = $this->viewItem ?: ArrayHelper::getValue($config, 'view_item');
     if (empty($this->viewItem)) {
         $inflector = Inflector::getInstance();
         $this->viewItem = $inflector->toSingular($this->viewList);
     }
 }
Exemplo n.º 3
0
 /**
  * Method to instantiate the view.
  *
  * @param Model             $model     The model object.
  * @param Container         $container DI Container.
  * @param array             $config    View config.
  * @param \SplPriorityQueue $paths     Paths queue.
  */
 public function __construct(Model $model = null, Container $container = null, $config = array(), \SplPriorityQueue $paths = null)
 {
     parent::__construct($model, $container, $config, $paths);
     // Guess the item view as the context.
     if (empty($this->viewList)) {
         $this->viewList = $this->getName();
     }
     // Guess the list view as the plural of the item view.
     if (empty($this->viewItem)) {
         $inflector = Inflector::getInstance();
         $this->viewItem = $inflector->toSingular($this->viewList);
     }
 }
 /**
  * Class init.
  *
  * @param Input           $input
  * @param Container       $container
  * @param AbstractPackage $package
  */
 public function __construct(Input $input = null, AbstractPackage $package = null, Container $container = null)
 {
     $this->config = $this->getConfig();
     $name = $this->getName();
     // Guess name
     $inflector = StringInflector::getInstance();
     if ($this->inflection == self::SINGULAR) {
         $this->config['item_name'] = $this->itemName ?: $name;
         $this->config['list_name'] = $this->listName ?: $inflector->toPlural($this->config['item_name']);
     } elseif ($this->inflection == self::PLURAL) {
         $this->config['list_name'] = $this->listName ?: $name;
         $this->config['item_name'] = $this->itemName ?: $inflector->toSingular($this->config['list_name']);
     }
     parent::__construct($input, $package, $container);
 }
Exemplo n.º 5
0
 /**
  * Constructor
  *
  * @param   array              $config    An array of configuration options (name, state, dbo, table_path, ignore_request).
  * @param   JoomlaContainer    $container Service container.
  * @param   \JRegistry         $state     The model state.
  * @param   \JDatabaseDriver   $db        The database adapter.
  */
 public function __construct($config = array(), JoomlaContainer $container = null, \JRegistry $state = null, \JDatabaseDriver $db = null)
 {
     parent::__construct($config, $container, $state, $db);
     if (!$this->reorderConditions) {
         $this->reorderConditions = ArrayHelper::getValue($config, 'reorder_conditions', array('catid'));
     }
     // Guess the item view as the context.
     if (empty($this->viewItem)) {
         $this->viewItem = $this->getName();
     }
     // Guess the list view as the plural of the item view.
     if (empty($this->viewList)) {
         $inflector = Inflector::getInstance();
         $this->viewList = $inflector->toPlural($this->viewItem);
     }
 }
Exemplo n.º 6
0
 /**
  * Get the path of extension.
  *
  * @param   string   $element   The extension element name, example: com_content or plg_group_name
  * @param   string   $client    Site or administrator.
  * @param   boolean  $absolute  True to return whole path.
  *
  * @return  string  The found path.
  */
 public static function get($element, $client = null, $absolute = true)
 {
     $element = strtolower($element);
     $extracted = ExtensionHelper::extractElement($element);
     $extension = $extracted['type'];
     $name = $extracted['name'];
     $group = $extracted['group'];
     // Assign name path.
     switch ($extension) {
         case 'component':
         case 'module':
             $folder = $element;
             break;
         case 'plugin':
             $folder = $group . '/' . $name;
             $client = 'site';
             break;
         case 'library':
             $client = 'site';
         default:
             $folder = $name;
             break;
     }
     // Build path
     $extension = StringInflector::getInstance()->toPlural($extension);
     $path = $extension . '/' . $folder;
     if (!$absolute) {
         return $path;
     }
     // Add absolute path.
     switch ($client) {
         case 'site':
             $path = JPATH_SITE . '/' . $path;
             break;
         case 'admin':
         case 'administrator':
             $path = JPATH_ADMINISTRATOR . '/' . $path;
             break;
         default:
             $path = JPATH_BASE . '/' . $path;
             break;
     }
     return $path;
 }
Exemplo n.º 7
0
 /**
  * guessSubmenus
  *
  * @param string $inflection
  *
  * @return array
  */
 protected function findViewMenus($inflection = self::PLURAL)
 {
     $inflector = StringInflector::getInstance();
     $viewFolder = ADMIN_ROOT . '/View';
     $views = Filesystem::folders($viewFolder);
     $menus = array();
     /** @var \SplFileInfo $view */
     foreach ($views as $view) {
         if ($view->isFile()) {
             continue;
         }
         $name = strtolower($view->getBasename());
         if ($inflection == static::PLURAL && $inflector->isPlural($name)) {
             $menus[] = $name;
         } elseif ($inflection == static::SINGULAR && $inflector->isSingular($name)) {
             $menus[] = $name;
         }
     }
     return $menus;
 }
 /**
  * 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 = StringInflector::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);
 }
Exemplo n.º 9
0
 /**
  * Constructor
  *
  * @param   array              $config    An array of configuration options (name, state, dbo, table_path, ignore_request).
  * @param   JoomlaContainer    $container Service container.
  * @param   \JRegistry         $state     The model state.
  * @param   \JDatabaseDriver   $db        The database adapter.
  */
 public function __construct($config = array(), JoomlaContainer $container = null, \JRegistry $state = null, \JDatabaseDriver $db = null)
 {
     // These need before parent constructor.
     $this->orderCol = $this->orderCol ?: ArrayHelper::getValue($config, 'order_column', null);
     // This block should be remove after 3.0, use allowFields instead
     if (!$this->filterFields) {
         $this->filterFields = ArrayHelper::getValue($config, 'filter_fields', array());
         $this->filterFields[] = '*';
     }
     if (!$this->allowFields) {
         $this->allowFields = ArrayHelper::getValue($config, 'allow_fields', array());
         $this->allowFields[] = '*';
     }
     $this->prefix = $this->getPrefix($config);
     $this->option = 'com_' . $this->prefix;
     // Guess name for container
     $this->name = $this->name ?: ArrayHelper::getValue($config, 'name', $this->getName());
     $this->container = $container ?: $this->getContainer();
     $this->container->registerServiceProvider(new GridProvider($this->name, $this));
     $this->configureTables();
     parent::__construct($config, $container, $state, $db);
     // Guess the item view as the context.
     $this->viewList = $this->viewList ?: ArrayHelper::getValue($config, 'view_list', $this->getName());
     // Guess the list view as the plural of the item view.
     $this->viewItem = $this->viewItem ?: ArrayHelper::getValue($config, 'view_item');
     if (empty($this->viewItem)) {
         $inflector = Inflector::getInstance();
         $this->viewItem = $inflector->toSingular($this->viewList);
     }
 }
Exemplo n.º 10
0
 /**
  * Method to test StringInflector::toPlural().
  *
  * @return  void
  *
  * @covers  Windwalker\String\StringInflector::toSingular
  * @since   1.2.0
  */
 public function testToSingularRetFalse()
 {
     // Assertion for already singular
     $this->assertFalse($this->StringInflector->toSingular('bus'));
     $this->assertFalse($this->StringInflector->toSingular('foo'));
 }