parent
5a184fbf8c
commit
0d867c7371
@ -0,0 +1,4 @@
|
||||
.gitattributes export-ignore
|
||||
.gitignore export-ignore
|
||||
.gitlab-ci.yml export-ignore
|
||||
test/ export-ignore
|
@ -0,0 +1,6 @@
|
||||
composer.lock
|
||||
composer.phar
|
||||
.idea/
|
||||
build/
|
||||
test/temp/
|
||||
vendor/
|
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2013-2019 TechFuze
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "fuzeworks/mvcr",
|
||||
"description": "FuzeWorks Framework MVC Component",
|
||||
"license": ["MIT"],
|
||||
"authors": [
|
||||
{
|
||||
"name": "TechFuze",
|
||||
"homepage": "https://techfuze.net"
|
||||
},
|
||||
{
|
||||
"name": "FuzeWorks Community",
|
||||
"homepage": "https://techfuze.net/fuzeworks/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"fuzeworks/core": "dev-development",
|
||||
"phpunit/phpunit": "^7",
|
||||
"mikey179/vfsStream": "1.6.5"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"FuzeWorks\\": "src/FuzeWorks/"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* FuzeWorks Framework MVCR Component.
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-2019 TechFuze
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.2.0
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @todo Add documentation
|
||||
*/
|
||||
return array(
|
||||
);
|
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* FuzeWorks Framework MVCR Component.
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-2019 TechFuze
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.2.0
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
*/
|
||||
|
||||
return array(
|
||||
|
||||
'default_view' => 'index',
|
||||
'default_viewType' => 'standard',
|
||||
'default_viewMethod' => 'index',
|
||||
|
||||
);
|
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* FuzeWorks Framework MVCR Component.
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-2019 TechFuze
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.2.0
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
||||
/**
|
||||
* Abstract class Controller.
|
||||
*
|
||||
* Extends all controllers to use the Factory.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
*/
|
||||
abstract class Controller extends Factory
|
||||
{
|
||||
}
|
@ -0,0 +1,172 @@
|
||||
<?php
|
||||
/**
|
||||
* FuzeWorks Framework MVCR Component.
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-2019 TechFuze
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.2.0
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
||||
use FuzeWorks\Event\ControllerGetEvent;
|
||||
use FuzeWorks\Exception\ControllerException;
|
||||
use FuzeWorks\Exception\EventException;
|
||||
use FuzeWorks\Exception\NotFoundException;
|
||||
|
||||
/**
|
||||
* Controllers Class.
|
||||
*
|
||||
* Simple loader class for MVC Controllers.
|
||||
* Typically loads controllers from Application\Controller unless otherwise specified.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
*/
|
||||
class Controllers
|
||||
{
|
||||
use ComponentPathsTrait;
|
||||
|
||||
/**
|
||||
* Get a controller.
|
||||
*
|
||||
* Supply the name and the controller will be loaded from the supplied directory,
|
||||
* or from one of the controllerPaths (which you can add).
|
||||
*
|
||||
* @param string $controllerName Name of the controller
|
||||
* @param array $controllerPaths Alternative paths to use to load the controller
|
||||
* @param string $namespace Alternative namespace for the controller. Defaults to \Application\Controller
|
||||
* @param mixed %arguments,... Arguments to be provided to the constructor [...]
|
||||
* @return Controller
|
||||
* @throws ControllerException
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
public function get(string $controllerName, array $controllerPaths = [], string $namespace = '\Application\Controller\\'): Controller
|
||||
{
|
||||
if (empty($controllerName))
|
||||
throw new ControllerException("Could not load controller. No name provided", 1);
|
||||
|
||||
// First get the directories where the controller can be located
|
||||
$controllerPaths = (empty($controllerPaths) ? $this->componentPaths : [3 => $controllerPaths]);
|
||||
|
||||
// Get arguments for constructor
|
||||
if (func_num_args() > 3)
|
||||
$arguments = array_slice(func_get_args(), 3);
|
||||
else
|
||||
$arguments = [];
|
||||
|
||||
// Fire a controller load event
|
||||
/** @var ControllerGetEvent $event */
|
||||
try {
|
||||
$event = Events::fireEvent('controllerGetEvent', $controllerName, $controllerPaths, $namespace, $arguments);
|
||||
} catch (EventException $e) {
|
||||
throw new ControllerException("Could not load controller. controllerGetEvent threw exception: '".$e->getMessage()."'");
|
||||
}
|
||||
|
||||
// If the event is cancelled, stop loading
|
||||
if ($event->isCancelled())
|
||||
throw new ControllerException("Could not load controller. Controller cancelled by controllerGetEvent.");
|
||||
|
||||
// And attempt to load the controller
|
||||
return $this->loadController($event->controllerName, $event->controllerPaths, $event->namespace, $event->arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load and return a controller.
|
||||
*
|
||||
* Supply the name and the controller will be loaded from one of the supplied directories
|
||||
*
|
||||
* @param string $controllerName Name of the controller
|
||||
* @param array $controllerPaths
|
||||
* @param string $namespace
|
||||
* @param array $arguments
|
||||
* @return Controller The Controller object
|
||||
* @throws ControllerException
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
protected function loadController(string $controllerName, array $controllerPaths, string $namespace, array $arguments): Controller
|
||||
{
|
||||
// Now figure out the className and subdir
|
||||
$class = trim($controllerName, '/');
|
||||
if (($last_slash = strrpos($class, '/')) !== FALSE) {
|
||||
// Extract the path
|
||||
$subdir = substr($class, 0, ++$last_slash);
|
||||
|
||||
// Get the filename from the path
|
||||
$class = substr($class, $last_slash);
|
||||
} else {
|
||||
$subdir = '';
|
||||
}
|
||||
|
||||
// If the class already exists, return a new instance directly
|
||||
$class = ucfirst($class);
|
||||
$className = $namespace . $class . 'Controller';
|
||||
if (class_exists($className, false))
|
||||
{
|
||||
$controller = new $className(...$arguments);
|
||||
if (!$controller instanceof Controller)
|
||||
throw new ControllerException("Could not load controller. Provided controllerName is not instance of \FuzeWorks\Controller");
|
||||
|
||||
return $controller;
|
||||
}
|
||||
|
||||
// Search for the controller file
|
||||
for ($i=Priority::getHighestPriority(); $i<=Priority::getLowestPriority(); $i++)
|
||||
{
|
||||
if (!isset($controllerPaths[$i]))
|
||||
continue;
|
||||
|
||||
foreach ($controllerPaths[$i] as $directory) {
|
||||
|
||||
// Determine the file
|
||||
$file = $directory . DS . $subdir . "controller." . strtolower($class) . '.php';
|
||||
|
||||
// If it doesn't, try and load the file
|
||||
if (file_exists($file)) {
|
||||
include_once($file);
|
||||
|
||||
// Test if provided class is instance of Controller
|
||||
$controller = new $className(...$arguments);
|
||||
if (!$controller instanceof Controller)
|
||||
throw new ControllerException("Could not load controller. Provided controllerName is not instance of \FuzeWorks\Controller");
|
||||
|
||||
return $controller;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Maybe it's in a subdirectory with the same name as the class
|
||||
if ($subdir === '') {
|
||||
return $this->loadController($class . "/" . $class, $controllerPaths, $namespace, $arguments);
|
||||
}
|
||||
|
||||
throw new NotFoundException("Could not load controller. Controller was not found", 1);
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* FuzeWorks Framework MVCR Component.
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-2019 TechFuze
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.2.0
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Event;
|
||||
use FuzeWorks\Event;
|
||||
|
||||
/**
|
||||
* Event that gets fired when a controller is loaded.
|
||||
*
|
||||
* Use this to cancel the loading of a controller, or change the controller to be loaded
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
*/
|
||||
class ControllerGetEvent extends Event
|
||||
{
|
||||
/**
|
||||
* The directories the controller can get loaded from.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $controllerPaths = array();
|
||||
|
||||
/**
|
||||
* The name of the controller to be loaded.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $controllerName = null;
|
||||
|
||||
/**
|
||||
* The namespace of the controller to be loaded. Defaults to Application\Controller
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $namespace = '\Application\Controller\\';
|
||||
|
||||
/**
|
||||
* Arguments provided to the constructor
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $arguments = [];
|
||||
|
||||
public function init($controllerName, $controllerPaths, $namespace, $arguments)
|
||||
{
|
||||
$this->controllerName = $controllerName;
|
||||
$this->controllerPaths = $controllerPaths;
|
||||
$this->namespace = $namespace;
|
||||
$this->arguments = $arguments;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/**
|
||||
* FuzeWorks Framework MVCR Component.
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-2019 TechFuze
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.2.0
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Event;
|
||||
use FuzeWorks\Event;
|
||||
|
||||
/**
|
||||
* Event that gets loaded when a model is loaded.
|
||||
*
|
||||
* Use this to cancel the loading of a model, or change the model to be loaded
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
*/
|
||||
|
||||
class ModelGetEvent extends Event
|
||||
{
|
||||
/**
|
||||
* The directories the model can get loaded from.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $modelPaths = array();
|
||||
|
||||
/**
|
||||
* The name of the model to be loaded.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $modelName = null;
|
||||
|
||||
/**
|
||||
* The namespace of the model to be loaded. Defaults to Application\Model
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $namespace = '\Application\Model\\';
|
||||
|
||||
/**
|
||||
* Arguments provided to the constructor
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $arguments = [];
|
||||
|
||||
public function init($modelName, $modelPaths, $namespace, $arguments)
|
||||
{
|
||||
$this->modelName = $modelName;
|
||||
$this->modelPaths = $modelPaths;
|
||||
$this->namespace = $namespace;
|
||||
$this->arguments = $arguments;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
/**
|
||||
* FuzeWorks Framework MVCR Component.
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-2019 TechFuze
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.2.0
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Event;
|
||||
use FuzeWorks\Controller;
|
||||
use FuzeWorks\Event;
|
||||
|
||||
/**
|
||||
* Event that gets fired when a view and controller are loaded.
|
||||
*
|
||||
* Use this to cancel the loading of a combination, or change the details of what is loaded.
|
||||
*
|
||||
* Currently only used by OldRouter::defaultCallable();
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
*/
|
||||
class RouterLoadViewAndControllerEvent extends Event
|
||||
{
|
||||
/**
|
||||
* The name of the view
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $viewName;
|
||||
|
||||
/**
|
||||
* The type of view to be loaded
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $viewType;
|
||||
|
||||
/**
|
||||
* The function that will be loaded in the view
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $viewMethod;
|
||||
|
||||
/**
|
||||
* The parameters that will be provided to the function in the view
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $viewParameters;
|
||||
|
||||
/**
|
||||
* The route that resulted in this controller and view
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $route;
|
||||
|
||||
/**
|
||||
* A controller to be injected.
|
||||
*
|
||||
* @var Controller|null
|
||||
*/
|
||||
public $controller;
|
||||
|
||||
public function init(string $viewName, string $viewType, string $viewMethod, string $viewParameters, string $route)
|
||||
{
|
||||
$this->viewName = $viewName;
|
||||
$this->viewType = $viewType;
|
||||
$this->viewMethod = $viewMethod;
|
||||
$this->viewParameters = $viewParameters;
|
||||
$this->route = $route;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the controller to be provided to the view.
|
||||
*
|
||||
* @param Controller $controller
|
||||
*/
|
||||
public function overrideController(Controller $controller)
|
||||
{
|
||||
$this->controller = $controller;
|
||||
}
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/**
|
||||
* FuzeWorks Framework MVCR Component.
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-2019 TechFuze
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.2.0
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Event;
|
||||
use FuzeWorks\Controller;
|
||||
use FuzeWorks\Event;
|
||||
|
||||
/**
|
||||
* Event that gets fired when a view is loaded.
|
||||
*
|
||||
* Use this to cancel the loading of a view, or change the view to be loaded
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
*/
|
||||
class ViewGetEvent extends Event
|
||||
{
|
||||
/**
|
||||
* The directories the view can get loaded from.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $viewPaths = [];
|
||||
|
||||
/**
|
||||
* The name of the view to be loaded.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $viewName = null;
|
||||
|
||||
/**
|
||||
* The type of view to be loaded. Eg: html, json, cli.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $viewType = null;
|
||||
|
||||
/**
|
||||
* The namespace of the View to be loaded. Defaults to Application\View
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $namespace = '\Application\View\\';
|
||||
|
||||
/**
|
||||
* Arguments provided to the constructor
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $arguments = [];
|
||||
|
||||
/**
|
||||
* @var Controller
|
||||
*/
|
||||
public $controller;
|
||||
|
||||
public function init($viewName, $viewType, $viewPaths, $namespace, $controller, $arguments)
|
||||
{
|
||||
$this->viewName = $viewName;
|
||||
$this->viewType = $viewType;
|
||||
$this->viewPaths = $viewPaths;
|
||||
$this->namespace = $namespace;
|
||||
$this->controller = $controller;
|
||||
$this->arguments = $arguments;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* FuzeWorks Framework MVCR Component.
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-2019 TechFuze
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.2.0
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Exception;
|
||||
|
||||
class ControllerException extends Exception
|
||||
{
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* FuzeWorks Framework MVCR Component.
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-2019 TechFuze
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.2.0
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Exception;
|
||||
|
||||
class HaltException extends Exception
|
||||
{
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* FuzeWorks Framework MVCR Component.
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-2019 TechFuze
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.2.0
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Exception;
|
||||
|
||||
class ModelException extends Exception
|
||||
{
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* FuzeWorks Framework MVCR Component.
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-2019 TechFuze
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.2.0
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Exception;
|
||||
|
||||
class NotFoundException extends Exception
|
||||
{
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* FuzeWorks Framework MVCR Component.
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-2019 TechFuze
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.2.0
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Exception;
|
||||
|
||||
class RouterException extends Exception
|
||||
{
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* FuzeWorks Framework MVCR Component.
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-2019 TechFuze
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.2.0
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Exception;
|
||||
|
||||
class ViewException extends Exception
|
||||
{
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* FuzeWorks Framework MVCR Component.
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-2019 TechFuze
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.2.0
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
||||
|
||||
class MVCRComponent implements iComponent
|
||||
{
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return "MVCRComponent";
|
||||
}
|
||||
|
||||
public function getClasses(): array
|
||||
{
|
||||
return [
|
||||
'controllers' => '\FuzeWorks\Controllers',
|
||||
'models' => '\FuzeWorks\Models',
|
||||
'views' => '\FuzeWorks\Views',
|
||||
'router' => '\FuzeWorks\Router'
|
||||
];
|
||||
}
|
||||
|
||||
public function onAddComponent(Configurator $configurator)
|
||||
{
|
||||
// Add fallback config directory
|
||||
$configurator->addDirectory(
|
||||
dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Config',
|
||||
'config',
|
||||
Priority::LOWEST
|
||||
);
|
||||
}
|
||||
|
||||
public function onCreateContainer(Factory $container)
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* FuzeWorks Framework MVCR Component.
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-2019 TechFuze
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.2.0
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class Model.
|
||||
*
|
||||
* Extends all models to use the Factory.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
*/
|
||||
abstract class Model extends Factory
|
||||
{
|
||||
}
|
@ -0,0 +1,171 @@
|
||||
<?php
|
||||
/**
|
||||
* FuzeWorks Framework MVCR Component.
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-2019 TechFuze
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.2.0
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
||||
use FuzeWorks\Event\ModelGetEvent;
|
||||
use FuzeWorks\Exception\EventException;
|
||||
use FuzeWorks\Exception\ModelException;
|
||||
use FuzeWorks\Exception\NotFoundException;
|
||||
|
||||
/**
|
||||
* Models Class.
|
||||
*
|
||||
* Simple loader class for MVC Models.
|
||||
* Typically loads models from Application\Model unless otherwise specified.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
*/
|
||||
class Models
|
||||
{
|
||||
use ComponentPathsTrait;
|
||||
|
||||
/**
|
||||
* Get a model.
|
||||
*
|
||||
* Supply the name and the model will be loaded from the supplied directory,
|
||||
* or from one of the modelPaths (which you can add).
|
||||
*
|
||||
* @param string $modelName Name of the model
|
||||
* @param array $modelPaths Alternative paths to use to load the model
|
||||
* @param string $namespace Alternative namespace for the model. Defaults to \Application\Model
|
||||
* @param mixed %arguments,... Arguments to be provided to the constructor [...]
|
||||
* @return Model
|
||||
* @throws NotFoundException
|
||||
* @throws ModelException
|
||||
*/
|
||||
public function get(string $modelName, array $modelPaths = [], string $namespace = '\Application\Model\\'): Model
|
||||
{
|
||||
if (empty($modelName))
|
||||
throw new ModelException("Could not load model. No name provided", 1);
|
||||
|
||||
// First get the directories where the model can be located
|
||||
$modelPaths = (empty($modelPaths) ? $this->componentPaths : [3 => $modelPaths]);
|
||||
|
||||
// Get arguments for constructor
|
||||
if (func_num_args() > 3)
|
||||
$arguments = array_slice(func_get_args(), 3);
|
||||
else
|
||||
$arguments = [];
|
||||
|
||||
// Fire a model load event
|
||||
/** @var ModelGetEvent $event */
|
||||
try {
|
||||
$event = Events::fireEvent('modelGetEvent', $modelName, $modelPaths, $namespace, $arguments);
|
||||
} catch (EventException $e) {
|
||||
throw new ModelException("Could not load model. modelGetEvent threw exception: '".$e->getMessage()."'");
|
||||
}
|
||||
|
||||
// If the event is cancelled, stop loading
|
||||
if ($event->isCancelled())
|
||||
throw new ModelException("Could not load model. Model cancelled by modelGetEvent.");
|
||||
|
||||
// And attempt to load the model
|
||||
return $this->loadModel($event->modelName, $event->modelPaths, $event->namespace, $event->arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load and return a model.
|
||||
*
|
||||
* Supply the name and the model will be loaded from one of the supplied directories
|
||||
*
|
||||
* @param string $modelName Name of the model
|
||||
* @param array $modelPaths
|
||||
* @param string $namespace
|
||||
* @param array $arguments
|
||||
* @return Model The Model object
|
||||
* @throws ModelException
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
protected function loadModel(string $modelName, array $modelPaths, string $namespace, array $arguments): Model
|
||||
{
|
||||
// Now figure out the className and subdir
|
||||
$class = trim($modelName, '/');
|
||||
if (($last_slash = strrpos($class, '/')) !== FALSE) {
|
||||
// Extract the path
|
||||
$subdir = substr($class, 0, ++$last_slash);
|
||||
|
||||
// Get the filename from the path
|
||||
$class = substr($class, $last_slash);
|
||||
} else {
|
||||
$subdir = '';
|
||||
}
|
||||
|
||||
// If the class already exists, return a new instance directly
|
||||
$class = ucfirst($class);
|
||||
$className = $namespace . $class . 'Model';
|
||||
if (class_exists($className, false)) {
|
||||
$model = new $className(...$arguments);
|
||||
if (!$model instanceof Model)
|
||||
throw new ModelException("Could not load model. Provided modelName is not instance of \FuzeWorks\Model");
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
// Search for the model file
|
||||
for ($i=Priority::getHighestPriority(); $i<=Priority::getLowestPriority(); $i++)
|
||||
{
|
||||
if (!isset($modelPaths[$i]))
|
||||
continue;
|
||||
|
||||
foreach ($modelPaths[$i] as $directory) {
|
||||
|
||||
// Determine the file
|
||||
$file = $directory . DS . $subdir . "model." . strtolower($class) . '.php';
|
||||
|
||||
// If it doesn't, try and load the file
|
||||
if (file_exists($file)) {
|
||||
include_once($file);
|
||||
|
||||
// Test if provided class is instance of Model
|
||||
$model = new $className(...$arguments);
|
||||
if (!$model instanceof Model)
|
||||
throw new ModelException("Could not load model. Provided modelName is not instance of \FuzeWorks\Model");
|
||||
|
||||
return $model;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Maybe it's in a subdirectory with the same name as the class
|
||||
if ($subdir === '') {
|
||||
return $this->loadModel($class . "/" . $class, $modelPaths, $namespace, $arguments);
|
||||
}
|
||||
|
||||
throw new NotFoundException("Could not load model. Model was not found", 1);
|
||||
}
|
||||
}
|
@ -0,0 +1,400 @@
|
||||
<?php
|
||||
/**
|
||||
* FuzeWorks Framework MVCR Component.
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-2018 TechFuze
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2018, TechFuze. (http://techfuze.net)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.2.0
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
||||
|
||||
use FuzeWorks\Event\RouterLoadViewAndControllerEvent;
|
||||
use FuzeWorks\Exception\ConfigException;
|
||||
use FuzeWorks\Exception\ControllerException;
|
||||
use FuzeWorks\Exception\EventException;
|
||||
use FuzeWorks\Exception\HaltException;
|
||||
use FuzeWorks\Exception\NotFoundException;
|
||||
use FuzeWorks\Exception\RouterException;
|
||||
use FuzeWorks\Exception\ViewException;
|
||||
|
||||
class Router
|
||||
{
|
||||
/**
|
||||
* The routes loaded into the Router
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $routes = [];
|
||||
|
||||
/**
|
||||
* The current callable used
|
||||
*
|
||||
* @var callable|null
|
||||
*/
|
||||
protected $callable = null;
|
||||
|
||||
/**
|
||||
* The current matches used
|
||||
*
|
||||
* @var array|null
|
||||
*/
|
||||
protected $matches = null;
|
||||
|
||||
/**
|
||||
* The current route used
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $route = null;
|
||||
|
||||
/**
|
||||
* The current View
|
||||
*
|
||||
* @var View|null
|
||||
*/
|
||||
protected $view = null;
|
||||
|
||||
/**
|
||||
* The current Controller
|
||||
*
|
||||
* @var Controller|null
|
||||
*/
|
||||
protected $controller = null;
|
||||
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var Controllers
|
||||
*/
|
||||
private $controllers;
|
||||
|
||||
/**
|
||||
* @var Views
|
||||
*/
|
||||
private $views;
|
||||
|
||||
/**
|
||||
* Router constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// Prepare
|
||||
$factory = Factory::getInstance();
|
||||
$this->config = $factory->config;
|
||||
$this->controllers = $factory->controllers;
|
||||
$this->views = $factory->views;
|
||||
}
|
||||
|
||||
/**
|
||||
* Route Parser
|
||||
*
|
||||
* This method parses all the routes in the routes table config file
|
||||
* and adds them to the Router. It converts some routes which use wildcards
|
||||
*
|
||||
* @return void
|
||||
* @throws RouterException
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
// Get routing routes
|
||||
try {
|
||||
$routes = $this->config->getConfig('routes');
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (ConfigException $e) {
|
||||
throw new RouterException("Could not parse routing. Error in config 'routes'");
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
// Cycle through all provided routes
|
||||
foreach ($routes as $route => $routeConfig)
|
||||
{
|
||||
// Check if only a string is provided
|
||||
// e.g: 0 => '.*$'
|
||||
if (is_int($route))
|
||||
{
|
||||
$route = $routeConfig;
|
||||
$routeConfig = ['callable' => [$this, 'defaultCallable']];
|
||||
}
|
||||
|
||||
// Finally add the route
|
||||
$this->addRoute($route, $routeConfig);
|
||||
}
|
||||
}
|
||||
|
||||
public function addRoute(string $route, $routeConfig = null, bool $prepend = true)
|
||||
{
|
||||
// Set defaultCallable if no value provided
|
||||
if (is_null($routeConfig))
|
||||
$routeConfig = ['callable' => [$this, 'defaultCallable']];
|
||||
|
||||
// Convert wildcards to Regex
|
||||
$route = str_replace([':any',':num'], ['[^/]+', '[0-9]+'], $route);
|
||||
|
||||
if ($prepend)
|
||||
$this->routes = [$route => $routeConfig] + $this->routes;
|
||||
else
|
||||
$this->routes[$route] = $routeConfig;
|
||||
|
||||
Logger::log('Route added at '.($prepend ? 'top' : 'bottom').': "'.$route.'"');
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a route from the array based on the given route.
|
||||
*
|
||||
* @param $route string The route to remove
|
||||
*/
|
||||
public function removeRoute(string $route)
|
||||
{
|
||||
unset($this->routes[$route]);
|
||||
|
||||
Logger::log('Route removed: '.$route);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @return mixed
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
public function route(string $path)
|
||||
{
|
||||
// Check all the provided custom paths
|
||||
foreach ($this->routes as $route => $routeConfig)
|
||||
{
|
||||
// Match the path against the routes
|
||||
if (!preg_match('#^'.$route.'$#', $path, $matches))
|
||||
continue;
|
||||
|
||||
// Save the matches
|
||||
Logger::log('Route matched: '.$route);
|
||||
$this->matches = $matches;
|
||||
$this->route = $route;
|
||||
|
||||
// Call callable if routeConfig is callable, so routeConfig can be replaced
|
||||
// e.g: '.*$' => callable
|
||||
if (is_callable($routeConfig))
|
||||
$routeConfig = call_user_func_array($routeConfig, [$matches]);
|
||||
|
||||
// If routeConfig is an array, multiple things might be at hand
|
||||
if (is_array($routeConfig))
|
||||
{
|
||||
// Replace defaultCallable if a custom callable is provided
|
||||
// e.g: '.*$' => ['callable' => [$object, 'method']]
|
||||
if (isset($routeConfig['callable']) && is_callable($routeConfig['callable']))
|
||||
$this->callable = $routeConfig['callable'];
|
||||
|
||||
// If the route provides a configuration, use that
|
||||
// e.g: '.*$' => ['viewName' => 'custom', 'viewType' => 'cli', 'function' => 'index']
|
||||
else
|
||||
$this->matches = array_merge($this->matches, $routeConfig);
|
||||
}
|
||||
|
||||
// If no custom callable is provided, use default
|
||||
if (is_null($this->callable))
|
||||
$this->callable = [$this, 'defaultCallable'];
|
||||
|
||||
// Attempt and load callable. If false, continue
|
||||
$output = $this->loadCallable($this->callable, $this->matches, $route);
|
||||
if (is_bool($output) && $output === FALSE)
|
||||
{
|
||||
Logger::log('Callable not satisfied, skipping to next callable');
|
||||
continue;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
throw new NotFoundException("Could not load view. Router could not find matching route.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $callable
|
||||
* @param array $matches
|
||||
* @param string $route
|
||||
* @return mixed
|
||||
*/
|
||||
protected function loadCallable(callable $callable, array $matches, string $route)
|
||||
{
|
||||
// Log the input to the logger
|
||||
Logger::newLevel('Loading callable with matches:');
|
||||
foreach ($matches as $key => $value) {
|
||||
if (!is_int($key))
|
||||
Logger::log($key.': '.var_export($value, true).'');
|
||||
}
|
||||
Logger::stopLevel();
|
||||
|
||||
// Invoke callable
|
||||
return call_user_func_array($callable, [$matches, $route]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $matches
|
||||
* @param string $route
|
||||
* @return mixed
|
||||
* @throws HaltException
|
||||
* @throws RouterException
|
||||
* @todo Use $route and send it to the view
|
||||
*/
|
||||
public function defaultCallable(array $matches, string $route)
|
||||
{
|
||||
Logger::log('defaultCallable called');
|
||||
|
||||
// Prepare variables
|
||||
$viewName = isset($matches['viewName']) ? $matches['viewName'] : null;
|
||||
$viewType = isset($matches['viewType']) ? $matches['viewType'] : $this->config->routing->default_viewType;
|
||||
$viewMethod = isset($matches['viewMethod']) ? $matches['viewMethod'] : $this->config->routing->default_viewMethod;
|
||||
$viewParameters = isset($matches['viewParameters']) ? $matches['viewParameters'] : '';
|
||||
|
||||
// If nothing is provided, cancel loading
|
||||
if (is_null($viewName))
|
||||
return false;
|
||||
|
||||
try {
|
||||
/** @var RouterLoadViewAndControllerEvent $event */
|
||||
$event = Events::fireEvent('routerLoadViewAndControllerEvent',
|
||||
$viewName,
|
||||
$viewType,
|
||||
$viewMethod,
|
||||
$viewParameters,
|
||||
$route
|
||||
);
|
||||
} catch (EventException $e) {
|
||||
throw new RouterException("Could not load view. routerLoadViewAndControllerEvent threw exception: '".$e->getMessage()."'");
|
||||
}
|
||||
|
||||
// Cancel if requested to do so
|
||||
if ($event->isCancelled())
|
||||
throw new HaltException("Will not load view. Cancelled by routerLoadViewAndControllerEvent.");
|
||||
|
||||
// First receive the controller
|
||||
try {
|
||||
$this->controller = (!is_null($event->controller) ? $event->controller : $this->controllers->get($event->viewName));
|
||||
} catch (ControllerException $e) {
|
||||
throw new RouterException("Could not load view. Controllers::get threw ControllerException: '".$e->getMessage()."'");
|
||||
} catch (NotFoundException $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Then try and receive the view
|
||||
try {
|
||||
$this->view = $this->views->get($event->viewName, $this->controller, $event->viewType);
|
||||
} catch (ViewException $e) {
|
||||
throw new RouterException("Could not load view. Views::get threw ViewException: '".$e->getMessage()."'");
|
||||
} catch (NotFoundException $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the view does not want a function to be loaded, provide a halt parameter
|
||||
if (isset($this->view->halt))
|
||||
throw new HaltException("Will not load view. Cancelled by 'halt' attribute in view.");
|
||||
|
||||
// Check if requested function or magic method exists in view
|
||||
if (method_exists($this->view, $event->viewMethod) || method_exists($this->view, '__call'))
|
||||
{
|
||||
// Run viewCallMethodEvent.
|
||||
try {
|
||||
$methodEvent = Events::fireEvent('viewCallMethodEvent');
|
||||
} catch (EventException $e) {
|
||||
throw new RouterException("Could not load view. viewCallMethodEvent threw exception: '".$e->getMessage()."'");
|
||||
}
|
||||
|
||||
// If cancelled, halt
|
||||
if ($methodEvent->isCancelled())
|
||||
throw new HaltException("Will not load view. Cancelled by viewCallMethodEvent");
|
||||
|
||||
// Execute the function on the view
|
||||
return $this->view->{$event->viewMethod}($event->viewParameters);
|
||||
}
|
||||
|
||||
// View could not be found
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array with all the routes.
|
||||
*
|
||||
* @return array
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function getRoutes(): array
|
||||
{
|
||||
return $this->routes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current route
|
||||
*
|
||||
* @return string|null
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function getCurrentRoute()
|
||||
{
|
||||
return $this->route;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the matches with the RegEx route.
|
||||
*
|
||||
* @return null|array
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function getCurrentMatches()
|
||||
{
|
||||
return $this->matches;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current View
|
||||
*
|
||||
* @return View|null
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function getCurrentView()
|
||||
{
|
||||
return $this->view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current Controller
|
||||
*
|
||||
* @return Controller|null
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function getCurrentController()
|
||||
{
|
||||
return $this->controller;
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* FuzeWorks Framework MVCR Component.
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-2019 TechFuze
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.2.0
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class View.
|
||||
*
|
||||
* Extends all views to use the Factory.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
*/
|
||||
abstract class View extends Factory
|
||||
{
|
||||
|
||||
/**
|
||||
* The controller associated with this view
|
||||
*
|
||||
* @var Controller
|
||||
*/
|
||||
protected $controller;
|
||||
|
||||
/**
|
||||
* Provide the View with its associated Controller
|
||||
*
|
||||
* @param Controller $controller
|
||||
*/
|
||||
public function setController(Controller $controller)
|
||||
{
|
||||
$this->controller = $controller;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,179 @@
|
||||
<?php
|
||||
/**
|
||||
* FuzeWorks Framework MVCR Component.
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||