Skip to content

Commit

Permalink
Add CMSApplication interface
Browse files Browse the repository at this point in the history
  • Loading branch information
laoneo committed Jun 3, 2017
1 parent 01aa300 commit adc323a
Show file tree
Hide file tree
Showing 6 changed files with 277 additions and 85 deletions.
2 changes: 2 additions & 0 deletions libraries/src/CMS/Application/Autoconfigurable.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace Joomla\CMS\Application;

defined('JPATH_PLATFORM') or die;

use Joomla\Registry\Registry;

/**
Expand Down
91 changes: 21 additions & 70 deletions libraries/src/CMS/Application/CMSApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
use Joomla\CMS\Menu\AbstractMenu;
use Joomla\CMS\Pathway\Pathway;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Profiler\Profiler;
use Joomla\CMS\Session\Session;
use Joomla\CMS\User\User;
use Joomla\DI\Container;
use Joomla\DI\ContainerAwareInterface;
use Joomla\DI\ContainerAwareTrait;
Expand All @@ -29,74 +32,10 @@
*
* @since 3.2
*/
abstract class CMSApplication extends WebApplication implements ContainerAwareInterface
abstract class CMSApplication extends WebApplication implements ContainerAwareInterface, CMSApplicationInterface
{
use ContainerAwareTrait;

/**
* Constant defining an enqueued emergency message
*
* @var string
* @since 4.0
*/
const MSG_EMERGENCY = 'emergency';

/**
* Constant defining an enqueued alert message
*
* @var string
* @since 4.0
*/
const MSG_ALERT = 'alert';

/**
* Constant defining an enqueued critical message
*
* @var string
* @since 4.0
*/
const MSG_CRITICAL = 'critical';

/**
* Constant defining an enqueued error message
*
* @var string
* @since 4.0
*/
const MSG_ERROR = 'error';

/**
* Constant defining an enqueued warning message
*
* @var string
* @since 4.0
*/
const MSG_WARNING = 'warning';

/**
* Constant defining an enqueued notice message
*
* @var string
* @since 4.0
*/
const MSG_NOTICE = 'notice';

/**
* Constant defining an enqueued info message
*
* @var string
* @since 4.0
*/
const MSG_INFO = 'info';

/**
* Constant defining an enqueued debug message
*
* @var string
* @since 4.0
*/
const MSG_DEBUG = 'debug';

/**
* Array of options for the \JDocument object
*
Expand Down Expand Up @@ -148,7 +87,7 @@ abstract class CMSApplication extends WebApplication implements ContainerAwareIn
/**
* The profiler instance
*
* @var \JProfiler
* @var Profiler
* @since 3.2
*/
protected $profiler = null;
Expand Down Expand Up @@ -187,7 +126,7 @@ public function __construct(\JInput $input = null, Registry $config = null, WebC
// If JDEBUG is defined, load the profiler instance
if (defined('JDEBUG') && JDEBUG)
{
$this->profiler = \JProfiler::getInstance('Application');
$this->profiler = Profiler::getInstance('Application');
}

// Enable sessions by default.
Expand Down Expand Up @@ -219,7 +158,7 @@ public function afterSessionStart(SessionEvent $event)
if ($session->isNew())
{
$session->set('registry', new Registry);
$session->set('user', new \JUser);
$session->set('user', new User);
}

// TODO: At some point we need to get away from having session data always in the db.
Expand Down Expand Up @@ -1220,7 +1159,7 @@ public function toString($compress = false)
*/
public function getFormToken($forceNew = false)
{
/** @var \JSession $session */
/** @var Session $session */
$session = $this->getSession();

return $session->getFormToken();
Expand All @@ -1239,9 +1178,21 @@ public function getFormToken($forceNew = false)
*/
public function checkToken($method = 'post')
{
/** @var \JSession $session */
/** @var Session $session */
$session = $this->getSession();

return $session->checkToken($method);
}

/**
* Flag if the application instance is a CLI or web based application.
*
* @return boolean
*
* @since __DEPLOY_VERSION__
*/
public function isCli()
{
return false;
}
}
163 changes: 163 additions & 0 deletions libraries/src/CMS/Application/CMSApplicationInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<?php
/**
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/

namespace Joomla\CMS\Application;

use Joomla\CMS\User\User;
use Joomla\Session\SessionInterface;

/**
* Interface defining a Joomla! CMS Application class
*
* @since __DEPLOY_VERSION__
*/
interface CMSApplicationInterface
{
/**
* Constant defining an enqueued emergency message
*
* @var string
* @since __DEPLOY_VERSION__
*/
const MSG_EMERGENCY = 'emergency';

/**
* Constant defining an enqueued alert message
*
* @var string
* @since __DEPLOY_VERSION__
*/
const MSG_ALERT = 'alert';

/**
* Constant defining an enqueued critical message
*
* @var string
* @since __DEPLOY_VERSION__
*/
const MSG_CRITICAL = 'critical';

/**
* Constant defining an enqueued error message
*
* @var string
* @since __DEPLOY_VERSION__
*/
const MSG_ERROR = 'error';

/**
* Constant defining an enqueued warning message
*
* @var string
* @since __DEPLOY_VERSION__
*/
const MSG_WARNING = 'warning';

/**
* Constant defining an enqueued notice message
*
* @var string
* @since __DEPLOY_VERSION__
*/
const MSG_NOTICE = 'notice';

/**
* Constant defining an enqueued info message
*
* @var string
* @since __DEPLOY_VERSION__
*/
const MSG_INFO = 'info';

/**
* Constant defining an enqueued debug message
*
* @var string
* @since __DEPLOY_VERSION__
*/
const MSG_DEBUG = 'debug';

/**
* Enqueue a system message.
*
* @param string $msg The message to enqueue.
* @param string $type The message type.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function enqueueMessage($msg, $type = self::MSG_INFO);

/**
* Get the system message queue.
*
* @return array The system message queue.
*
* @since __DEPLOY_VERSION__
*/
public function getMessageQueue();

/**
* Execute the application.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function execute();

/**
* Check the client interface by name.
*
* @param string $identifier String identifier for the application interface
*
* @return boolean True if this application is of the given type client interface.
*
* @since __DEPLOY_VERSION__
*/
public function isClient($identifier);

/**
* Method to get the application session object.
*
* @return SessionInterface The session object
*
* @since __DEPLOY_VERSION__
*/
public function getSession();

/**
* Flag if the application instance is a CLI or web based application.
*
* @return boolean
*
* @since __DEPLOY_VERSION__
*/
public function isCli();

/**
* Get the application identity.
*
* @return User|null A User object or null if not set.
*
* @since __DEPLOY_VERSION__
*/
public function getIdentity();

/**
* Allows the application to load a custom or default identity.
*
* @param User $identity An optional identity object. If omitted, the factory user is created.
*
* @return $this
*
* @since __DEPLOY_VERSION__
*/
public function loadIdentity(User $identity = null);
}

0 comments on commit adc323a

Please sign in to comment.