JController::factory() and createEnvironmentArray() as discussed in joomla-dev-cms group #193

Closed
wants to merge 1 commit into from

2 participants

@dgasparri

Added to JController the following methods:

1) factory()
2) createEnvironmentArray()
3) setTask($task)

Changed execute($task) that if no task is passed, it executes the
$this->task (which is set also by the factory method)

See discussion https://groups.google.com/forum/?fromgroups#!topic/joomla-dev-cms/7tjVkzc08Ks (Object oriented components , any plan?)

2012-04-19 by Duccio Gasparri duccio.gasparri@gmail.com
Change-Id: I2a4ded062856670e364128f3cb74716b84b23eea

Duccio Gasparri Added to JController the methods:
1) factory()
2) createEvenrinmentArray()
3) setTask($task)

Changed execute($task) that if no task is passed, it executes the
$this->task (which is set also by the factory method)

2012-04-19 by Duccio Gasparri <duccio.gasparri@gmail.com>
Change-Id: I2a4ded062856670e364128f3cb74716b84b23eea
9fbbf63
@dgasparri

getInstance() should also be cleaned and simplified, as it does stuff proper of a factory pattern and factory method (choosing which class to load). Not knowing if there was backward compatibility issues, I left it like that.

Part of the "reasoning" in getInstance() about the environment variables ($_REQUEST task, controller, option, and so on) are left intact in the getInstance(), but were duplicated cleared and streamlined into the createEnvironmentArray() method.

@realityking realityking commented on the diff Apr 22, 2012
libraries/joomla/application/component/controller.php
+ *
+ * @param string|null $option $_REQUEST['option'] e.g. 'com_example'
+ * @param string|null $component the component base name e.g. 'example'
+ * @param string|false|null $controller the controller (false if it should not look for controllers)
+ * @param string|null $task the task to execute
+ * @param string|null $format the format (default html)
+ * @param string|null $basePath the base path of the component
+ *
+ * @return array
+ *
+ * @since 11.4
+ */
+ public static function createEnvironmentArray($option = null, $component = null, $controller = null, $task = null, $format = null, $basePath = null)
+ {
+
+ $jinput = JApplication::getInput();
@realityking
Joomla! member

That method doesn't exist. Correct would be JFactory::getApplication()->input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@realityking realityking commented on the diff Apr 22, 2012
libraries/joomla/application/component/controller.php
+ * @param string|null $task the task to execute
+ * @param string|null $format the format (default html)
+ * @param string|null $basePath the base path of the component
+ *
+ * @return array
+ *
+ * @since 11.4
+ */
+ public static function createEnvironmentArray($option = null, $component = null, $controller = null, $task = null, $format = null, $basePath = null)
+ {
+
+ $jinput = JApplication::getInput();
+
+ if(is_null($option))
+ {
+ $option = $jinput->get('option', null);
@realityking
Joomla! member

The default is already null, don't need to pass that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@realityking realityking commented on the diff Apr 22, 2012
libraries/joomla/application/component/controller.php
+ $component = $environmentArray['component'];
+ $controller = $environmentArray['controller'];
+ $task = $environmentArray['task'];
+ $basePath = $environmentArray['basePath'];
+ $format = $environmentArray['format'];
+ $classname = false;
+
+ if (!empty($component) && !empty($controller))
+ {
+
+ $classname = ucfirst($component) . 'Controller' . ucfirst($controller);
+
+ if (!class_exists($classname))
+ {
+ $file = self::createFileName('controller', array('name' => $controller, 'format' => $format));
+ $filepath = $environmentArray['basePath'] . DS . self::CONTROLLER_DIR . DS . $file;
@realityking
Joomla! member

We don't use DS anymore (it's deprecated and removed in the current platform). You should either use / or if you absolutely have to DIRECTORY_SEPARATOR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@phproberto
Joomla! member

I'm closing this as it's not mergeable and 1 year old. Feel free to open if you update it and are still interested in get it merged.

Thanks for contributing.

@phproberto phproberto closed this Oct 3, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment