primo commit
This commit is contained in:
53
libraries/fof30/Factory/Magic/BaseFactory.php
Normal file
53
libraries/fof30/Factory/Magic/BaseFactory.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* @package FOF
|
||||
* @copyright Copyright (c)2010-2021 Nicholas K. Dionysopoulos / Akeeba Ltd
|
||||
* @license GNU General Public License version 2, or later
|
||||
*/
|
||||
|
||||
namespace FOF30\Factory\Magic;
|
||||
|
||||
defined('_JEXEC') || die;
|
||||
|
||||
use FOF30\Container\Container;
|
||||
|
||||
abstract class BaseFactory
|
||||
{
|
||||
/**
|
||||
* @var Container|null The container where this factory belongs to
|
||||
*/
|
||||
protected $container = null;
|
||||
|
||||
/**
|
||||
* Section used to build the namespace prefix.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $section = 'auto';
|
||||
|
||||
/**
|
||||
* Public constructor
|
||||
*
|
||||
* @param Container $container The container we belong to
|
||||
*/
|
||||
public function __construct(Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSection()
|
||||
{
|
||||
return $this->section;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $section
|
||||
*/
|
||||
public function setSection($section)
|
||||
{
|
||||
$this->section = $section;
|
||||
}
|
||||
}
|
||||
76
libraries/fof30/Factory/Magic/ControllerFactory.php
Normal file
76
libraries/fof30/Factory/Magic/ControllerFactory.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* @package FOF
|
||||
* @copyright Copyright (c)2010-2021 Nicholas K. Dionysopoulos / Akeeba Ltd
|
||||
* @license GNU General Public License version 2, or later
|
||||
*/
|
||||
|
||||
namespace FOF30\Factory\Magic;
|
||||
|
||||
defined('_JEXEC') || die;
|
||||
|
||||
use FOF30\Controller\DataController;
|
||||
use FOF30\Factory\Exception\ControllerNotFound;
|
||||
|
||||
/**
|
||||
* Creates a DataController object instance based on the information provided by the fof.xml configuration file
|
||||
*/
|
||||
class ControllerFactory extends BaseFactory
|
||||
{
|
||||
/**
|
||||
* Create a new object instance
|
||||
*
|
||||
* @param string $name The name of the class we're making
|
||||
* @param array $config The config parameters which override the fof.xml information
|
||||
*
|
||||
* @return DataController A new DataController object
|
||||
*/
|
||||
public function make($name = null, array $config = [])
|
||||
{
|
||||
if (empty($name))
|
||||
{
|
||||
throw new ControllerNotFound($name);
|
||||
}
|
||||
|
||||
$appConfig = $this->container->appConfig;
|
||||
$name = ucfirst($name);
|
||||
|
||||
$defaultConfig = [
|
||||
'name' => $name,
|
||||
'default_task' => $appConfig->get("views.$name.config.default_task", 'main'),
|
||||
'autoRouting' => $appConfig->get("views.$name.config.autoRouting", 1),
|
||||
'csrfProtection' => $appConfig->get("views.$name.config.csrfProtection", 2),
|
||||
'viewName' => $appConfig->get("views.$name.config.viewName", null),
|
||||
'modelName' => $appConfig->get("views.$name.config.modelName", null),
|
||||
'taskPrivileges' => $appConfig->get("views.$name.acl"),
|
||||
'cacheableTasks' => $appConfig->get("views.$name.config.cacheableTasks", [
|
||||
'browse',
|
||||
'read',
|
||||
]),
|
||||
'taskMap' => $appConfig->get("views.$name.taskmap"),
|
||||
];
|
||||
|
||||
$config = array_merge($defaultConfig, $config);
|
||||
|
||||
$className = $this->container->getNamespacePrefix($this->getSection()) . 'Controller\\DefaultDataController';
|
||||
|
||||
if (!class_exists($className, true))
|
||||
{
|
||||
$className = 'FOF30\\Controller\\DataController';
|
||||
}
|
||||
|
||||
$controller = new $className($this->container, $config);
|
||||
|
||||
$taskMap = $config['taskMap'];
|
||||
|
||||
if (is_array($taskMap) && !empty($taskMap))
|
||||
{
|
||||
foreach ($taskMap as $virtualTask => $method)
|
||||
{
|
||||
$controller->registerTask($virtualTask, $method);
|
||||
}
|
||||
}
|
||||
|
||||
return $controller;
|
||||
}
|
||||
}
|
||||
43
libraries/fof30/Factory/Magic/DispatcherFactory.php
Normal file
43
libraries/fof30/Factory/Magic/DispatcherFactory.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* @package FOF
|
||||
* @copyright Copyright (c)2010-2021 Nicholas K. Dionysopoulos / Akeeba Ltd
|
||||
* @license GNU General Public License version 2, or later
|
||||
*/
|
||||
|
||||
namespace FOF30\Factory\Magic;
|
||||
|
||||
defined('_JEXEC') || die;
|
||||
|
||||
use FOF30\Dispatcher\Dispatcher;
|
||||
|
||||
/**
|
||||
* Creates a Dispatcher object instance based on the information provided by the fof.xml configuration file
|
||||
*/
|
||||
class DispatcherFactory extends BaseFactory
|
||||
{
|
||||
/**
|
||||
* Create a new object instance
|
||||
*
|
||||
* @param array $config The config parameters which override the fof.xml information
|
||||
*
|
||||
* @return Dispatcher A new Dispatcher object
|
||||
*/
|
||||
public function make(array $config = [])
|
||||
{
|
||||
$appConfig = $this->container->appConfig;
|
||||
$defaultConfig = $appConfig->get('dispatcher.*');
|
||||
$config = array_merge($defaultConfig, $config);
|
||||
|
||||
$className = $this->container->getNamespacePrefix($this->getSection()) . 'Dispatcher\\DefaultDispatcher';
|
||||
|
||||
if (!class_exists($className, true))
|
||||
{
|
||||
$className = '\\FOF30\\Dispatcher\\Dispatcher';
|
||||
}
|
||||
|
||||
$dispatcher = new $className($this->container, $config);
|
||||
|
||||
return $dispatcher;
|
||||
}
|
||||
}
|
||||
86
libraries/fof30/Factory/Magic/ModelFactory.php
Normal file
86
libraries/fof30/Factory/Magic/ModelFactory.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* @package FOF
|
||||
* @copyright Copyright (c)2010-2021 Nicholas K. Dionysopoulos / Akeeba Ltd
|
||||
* @license GNU General Public License version 2, or later
|
||||
*/
|
||||
|
||||
namespace FOF30\Factory\Magic;
|
||||
|
||||
defined('_JEXEC') || die;
|
||||
|
||||
use FOF30\Factory\Exception\ModelNotFound;
|
||||
use FOF30\Model\DataModel;
|
||||
use FOF30\Model\TreeModel;
|
||||
|
||||
/**
|
||||
* Creates a DataModel/TreeModel object instance based on the information provided by the fof.xml configuration file
|
||||
*/
|
||||
class ModelFactory extends BaseFactory
|
||||
{
|
||||
/**
|
||||
* Create a new object instance
|
||||
*
|
||||
* @param string $name The name of the class we're making
|
||||
* @param array $config The config parameters which override the fof.xml information
|
||||
*
|
||||
* @return TreeModel|DataModel A new TreeModel or DataModel object
|
||||
*/
|
||||
public function make($name = null, array $config = [])
|
||||
{
|
||||
if (empty($name))
|
||||
{
|
||||
throw new ModelNotFound($name);
|
||||
}
|
||||
|
||||
$appConfig = $this->container->appConfig;
|
||||
$name = ucfirst($name);
|
||||
|
||||
$defaultConfig = [
|
||||
'name' => $name,
|
||||
'use_populate' => $appConfig->get("models.$name.config.use_populate"),
|
||||
'ignore_request' => $appConfig->get("models.$name.config.ignore_request"),
|
||||
'tableName' => $appConfig->get("models.$name.config.tbl"),
|
||||
'idFieldName' => $appConfig->get("models.$name.config.tbl_key"),
|
||||
'knownFields' => $appConfig->get("models.$name.config.knownFields", null),
|
||||
'autoChecks' => $appConfig->get("models.$name.config.autoChecks"),
|
||||
'contentType' => $appConfig->get("models.$name.config.contentType"),
|
||||
'fieldsSkipChecks' => $appConfig->get("models.$name.config.fieldsSkipChecks", []),
|
||||
'aliasFields' => $appConfig->get("models.$name.field", []),
|
||||
'behaviours' => $appConfig->get("models.$name.behaviors", []),
|
||||
'fillable_fields' => $appConfig->get("models.$name.config.fillable_fields", []),
|
||||
'guarded_fields' => $appConfig->get("models.$name.config.guarded_fields", []),
|
||||
'relations' => $appConfig->get("models.$name.relations", []),
|
||||
];
|
||||
|
||||
$config = array_merge($defaultConfig, $config);
|
||||
|
||||
// Get the default class names
|
||||
$dataModelClassName = $this->container->getNamespacePrefix($this->getSection()) . 'Model\\DefaultDataModel';
|
||||
|
||||
if (!class_exists($dataModelClassName, true))
|
||||
{
|
||||
$dataModelClassName = '\\FOF30\\Model\\DataModel';
|
||||
}
|
||||
|
||||
$treeModelClassName = $this->container->getNamespacePrefix($this->getSection()) . 'Model\\DefaultTreeModel';
|
||||
|
||||
if (!class_exists($treeModelClassName, true))
|
||||
{
|
||||
$treeModelClassName = '\\FOF30\\Model\\TreeModel';
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// First try creating a TreeModel
|
||||
$model = new $treeModelClassName($this->container, $config);
|
||||
}
|
||||
catch (DataModel\Exception\TreeIncompatibleTable $e)
|
||||
{
|
||||
// If the table isn't a nested set, create a regular DataModel
|
||||
$model = new $dataModelClassName($this->container, $config);
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* @package FOF
|
||||
* @copyright Copyright (c)2010-2021 Nicholas K. Dionysopoulos / Akeeba Ltd
|
||||
* @license GNU General Public License version 2, or later
|
||||
*/
|
||||
|
||||
namespace FOF30\Factory\Magic;
|
||||
|
||||
defined('_JEXEC') || die;
|
||||
|
||||
use FOF30\Dispatcher\Dispatcher;
|
||||
|
||||
/**
|
||||
* Creates a TransparentAuthentication object instance based on the information provided by the fof.xml configuration
|
||||
* file
|
||||
*/
|
||||
class TransparentAuthenticationFactory extends BaseFactory
|
||||
{
|
||||
/**
|
||||
* Create a new object instance
|
||||
*
|
||||
* @param array $config The config parameters which override the fof.xml information
|
||||
*
|
||||
* @return Dispatcher A new Dispatcher object
|
||||
*/
|
||||
public function make(array $config = [])
|
||||
{
|
||||
$appConfig = $this->container->appConfig;
|
||||
$defaultConfig = $appConfig->get('authentication.*');
|
||||
$config = array_merge($defaultConfig, $config);
|
||||
|
||||
$className = $this->container->getNamespacePrefix($this->getSection()) . 'TransparentAuthentication\\DefaultTransparentAuthentication';
|
||||
|
||||
if (!class_exists($className, true))
|
||||
{
|
||||
$className = '\\FOF30\\TransparentAuthentication\\TransparentAuthentication';
|
||||
}
|
||||
|
||||
$dispatcher = new $className($this->container, $config);
|
||||
|
||||
return $dispatcher;
|
||||
}
|
||||
}
|
||||
70
libraries/fof30/Factory/Magic/ViewFactory.php
Normal file
70
libraries/fof30/Factory/Magic/ViewFactory.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* @package FOF
|
||||
* @copyright Copyright (c)2010-2021 Nicholas K. Dionysopoulos / Akeeba Ltd
|
||||
* @license GNU General Public License version 2, or later
|
||||
*/
|
||||
|
||||
namespace FOF30\Factory\Magic;
|
||||
|
||||
defined('_JEXEC') || die;
|
||||
|
||||
use FOF30\Factory\Exception\ViewNotFound;
|
||||
use FOF30\View\DataView\DataViewInterface;
|
||||
|
||||
/**
|
||||
* Creates a DataModel/TreeModel object instance based on the information provided by the fof.xml configuration file
|
||||
*/
|
||||
class ViewFactory extends BaseFactory
|
||||
{
|
||||
/**
|
||||
* Create a new object instance
|
||||
*
|
||||
* @param string $name The name of the class we're making
|
||||
* @param string $viewType The view type, default html, possible values html, form, raw, json, csv
|
||||
* @param array $config The config parameters which override the fof.xml information
|
||||
*
|
||||
* @return DataViewInterface A new TreeModel or DataModel object
|
||||
*/
|
||||
public function make($name = null, $viewType = 'html', array $config = [])
|
||||
{
|
||||
if (empty($name))
|
||||
{
|
||||
throw new ViewNotFound("[name : type] = [$name : $viewType]");
|
||||
}
|
||||
|
||||
$appConfig = $this->container->appConfig;
|
||||
$name = ucfirst($name);
|
||||
|
||||
$defaultConfig = [
|
||||
'name' => $name,
|
||||
'template_path' => $appConfig->get("views.$name.config.template_path"),
|
||||
'layout' => $appConfig->get("views.$name.config.layout"),
|
||||
// You can pass something like .php => Class1, .foo.bar => Class 2
|
||||
'viewEngineMap' => $appConfig->get("views.$name.config.viewEngineMap"),
|
||||
];
|
||||
|
||||
$config = array_merge($defaultConfig, $config);
|
||||
|
||||
$className = $this->container->getNamespacePrefix($this->getSection()) . 'View\\DataView\\Default' . ucfirst($viewType);
|
||||
|
||||
if (!class_exists($className, true))
|
||||
{
|
||||
$className = '\\FOF30\\View\\DataView\\' . ucfirst($viewType);
|
||||
}
|
||||
|
||||
if (!class_exists($className, true))
|
||||
{
|
||||
$className = $this->container->getNamespacePrefix($this->getSection()) . 'View\\DataView\\DefaultHtml';
|
||||
}
|
||||
|
||||
if (!class_exists($className))
|
||||
{
|
||||
$className = '\\FOF30\\View\\DataView\\Html';
|
||||
}
|
||||
|
||||
$view = new $className($this->container, $config);
|
||||
|
||||
return $view;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user