Permalink
Browse files

Adds new platform MVC classes to provide forward compatibilty for ext…

…ension developers.
  • Loading branch information...
1 parent 9ea5f46 commit d8f42713dfa548c8ed242f317bcda35031289035 @eddieajau committed May 13, 2012
@@ -0,0 +1,150 @@
+<?php
+/**
+ * @package Joomla.Platform
+ * @subpackage Controller
+ *
+ * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE
+ */
+
+defined('JPATH_PLATFORM') or die;
+
+/**
+ * Joomla Platform Base Controller Class
+ *
+ * @package Joomla.Platform
+ * @subpackage Controller
+ * @since 12.1
+ */
+abstract class JControllerBase
+{
+ /**
+ * The application object.
+ *
+ * @var JApplicationBase
+ * @since 12.1
+ */
+ protected $app;
+
+ /**
+ * The input object.
+ *
+ * @var JInput
+ * @since 12.1
+ */
+ protected $input;
+
+ /**
+ * Instantiate the controller.
+ *
+ * @param JInput $input The input object.
+ * @param JApplicationBase $app The application object.
+ *
+ * @since 12.1
+ */
+ public function __construct(JInput $input = null, JApplicationBase $app = null)
+ {
+ // Setup dependencies.
+ $this->app = isset($app) ? $app : $this->loadApplication();
+ $this->input = isset($input) ? $input : $this->loadInput();
+ }
+
+ /**
+ * 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.
+ *
+ * @since 12.1
+ * @throws LogicException
+ * @throws RuntimeException
+ */
+ abstract public function execute();
+
+ /**
+ * Get the application object.
+ *
+ * @return JApplicationBase The application object.
+ *
+ * @since 12.1
+ */
+ public function getApplication()
+ {
+ return $this->app;
+ }
+
+ /**
+ * Get the input object.
+ *
+ * @return JInput The input object.
+ *
+ * @since 12.1
+ */
+ public function getInput()
+ {
+ return $this->input;
+ }
+
+ /**
+ * Serialize the controller.
+ *
+ * @return string The serialized controller.
+ *
+ * @since 12.1
+ */
+ public function serialize()
+ {
+ return serialize($this->input);
+ }
+
+ /**
+ * Unserialize the controller.
+ *
+ * @param string $input The serialized controller.
+ *
+ * @return JController Supports chaining.
+ *
+ * @since 12.1
+ * @throws UnexpectedValueException if input is not the right class.
+ */
+ public function unserialize($input)
+ {
+ // Setup dependencies.
+ $this->app = $this->loadApplication();
+
+ // Unserialize the input.
+ $this->input = unserialize($input);
+
+ if (!($this->input instanceof JInput))
+ {
+ throw new UnexpectedValueException(sprintf('%s::unserialize would not accept a `%s`.', get_class($this), gettype($this->input)));
+ }
+
+ return $this;
+ }
+
+ /**
+ * Load the application object.
+ *
+ * @return JApplicationBase The application object.
+ *
+ * @since 12.1
+ */
+ protected function loadApplication()
+ {
+ return JFactory::getApplication();
+ }
+
+ /**
+ * Load the input object.
+ *
+ * @return JInput The input object.
+ *
+ * @since 12.1
+ */
+ protected function loadInput()
+ {
+ return $this->app->input;
+ }
+}
@@ -0,0 +1,79 @@
+<?php
+/**
+ * @package Joomla.Platform
+ * @subpackage Model
+ *
+ * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE
+ */
+
+defined('JPATH_PLATFORM') or die;
+
+/**
+ * Joomla Platform Base Model Class
+ *
+ * @package Joomla.Platform
+ * @subpackage Model
+ * @since 12.1
+ */
+abstract class JModelBase
+{
+ /**
+ * The model state.
+ *
+ * @var JRegistry
+ * @since 12.1
+ */
+ protected $state;
+
+ /**
+ * Instantiate the model.
+ *
+ * @param JRegistry $state The model state.
+ *
+ * @since 12.1
+ */
+ public function __construct(JRegistry $state = null)
+ {
+ // Setup the model.
+ $this->state = isset($state) ? $state : $this->loadState();
+ }
+
+ /**
+ * Get the model state.
+ *
+ * @return JRegistry The state object.
+ *
+ * @since 12.1
+ */
+ public function getState()
+ {
+ return $this->state;
+ }
+
+ /**
+ * Set the model state.
+ *
+ * @param JRegistry $state The state object.
+ *
+ * @return void
+ *
+ * @since 12.1
+ */
+ public function setState(JRegistry $state)
+ {
+ $this->state = $state;
+ }
+
+ /**
+ * Load the model state.
+ *
+ * @return JRegistry The state object.
+ *
+ * @since 12.1
+ */
+ protected function loadState()
+ {
+ return new JRegistry;
+ }
+}
@@ -0,0 +1,82 @@
+<?php
+/**
+ * @package Joomla.Platform
+ * @subpackage Model
+ *
+ * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE
+ */
+
+defined('JPATH_PLATFORM') or die;
+
+/**
+ * Joomla Platform Database Model Class
+ *
+ * @package Joomla.Platform
+ * @subpackage Model
+ * @since 12.1
+ */
+abstract class JModelDatabase extends JModelBase
+{
+ /**
+ * The database driver.
+ *
+ * @var JDatabaseDriver
+ * @since 12.1
+ */
+ protected $db;
+
+ /**
+ * Instantiate the model.
+ *
+ * @param JRegistry $state The model state.
+ * @param JDatabaseDriver $db The database adpater.
+ *
+ * @since 12.1
+ */
+ public function __construct(JRegistry $state = null, JDatabaseDriver $db = null)
+ {
+ parent::__construct($state);
+
+ // Setup the model.
+ $this->db = isset($db) ? $db : $this->loadDb();
+ }
+
+ /**
+ * Get the database driver.
+ *
+ * @return JDatabaseDriver The database driver.
+ *
+ * @since 12.1
+ */
+ public function getDb()
+ {
+ return $this->db;
+ }
+
+ /**
+ * Set the database driver.
+ *
+ * @param JDatabaseDriver $db The database driver.
+ *
+ * @return void
+ *
+ * @since 12.1
+ */
+ public function setDb(JDatabaseDriver $db)
+ {
+ $this->db = $db;
+ }
+
+ /**
+ * Load the database driver.
+ *
+ * @return JDatabaseDriver The database driver.
+ *
+ * @since 12.1
+ */
+ protected function loadDb()
+ {
+ return JFactory::getDbo();
+ }
+}
@@ -0,0 +1,66 @@
+<?php
+/**
+ * @package Joomla.Platform
+ * @subpackage View
+ *
+ * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE
+ */
+
+defined('JPATH_PLATFORM') or die;
+
+/**
+ * Joomla Platform Base View Class
+ *
+ * @package Joomla.Platform
+ * @subpackage View
+ * @since 12.1
+ */
+abstract class JViewBase
+{
+ /**
+ * The model object.
+ *
+ * @var JModel
+ * @since 12.1
+ */
+ protected $model;
+
+ /**
+ * Method to instantiate the view.
+ *
+ * @param JModel $model The model object.
+ *
+ * @since 12.1
+ */
+ public function __construct(JModel $model)
+ {
+ // Setup dependencies.
+ $this->model = $model;
+ }
+
+ /**
+ * Method to escape output.
+ *
+ * @param string $output The output to escape.
+ *
+ * @return string The escaped output.
+ *
+ * @see JView::escape()
+ * @since 12.1
+ */
+ public function escape($output)
+ {
+ return $output;
+ }
+
+ /**
+ * Method to render the view.
+ *
+ * @return string The rendered view.
+ *
+ * @since 12.1
+ * @throws RuntimeException
+ */
+ abstract public function render();
+}
Oops, something went wrong.

0 comments on commit d8f4271

Please sign in to comment.