Initial commit
This commit is contained in:
commit
e276a7ca29
|
@ -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,30 @@
|
||||||
|
{
|
||||||
|
"name": "fuzeworks/webcomponent",
|
||||||
|
"description": "FuzeWorks WebComponent",
|
||||||
|
"license": ["MIT"],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "TechFuze",
|
||||||
|
"homepage": "https://techfuze.net"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "FuzeWorks Community",
|
||||||
|
"homepage": "https://techfuze.net/fuzeworks/contributors"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"require": {
|
||||||
|
"php": ">=7.1.0",
|
||||||
|
"fuzeworks/core": "dev-development",
|
||||||
|
"fuzeworks/mvcr": "dev-master"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "^7",
|
||||||
|
"fuzeworks/tracycomponent": "dev-master"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"FuzeWorks\\": "src/FuzeWorks/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* FuzeWorks WebComponent.
|
||||||
|
*
|
||||||
|
* 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 [
|
||||||
|
'allow_get_input' => true,
|
||||||
|
'empty_global_arrays' => true,
|
||||||
|
'restore_global_arrays' => true
|
||||||
|
];
|
|
@ -0,0 +1,186 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* FuzeWorks WebComponent.
|
||||||
|
*
|
||||||
|
* 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\ConfigORM\ConfigORM;
|
||||||
|
use FuzeWorks\Event\NotifierEvent;
|
||||||
|
|
||||||
|
class Input
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Array with all the values from $_GET, $_POST, $_SERVER, $_COOKIE
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $inputArray = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Config of the WebComponent
|
||||||
|
*
|
||||||
|
* @var ConfigORM
|
||||||
|
*/
|
||||||
|
protected $webConfig;
|
||||||
|
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
// Set the configuration
|
||||||
|
$this->webConfig = Factory::getInstance()->config->getConfig('web');
|
||||||
|
|
||||||
|
// Sanitize all global arrays
|
||||||
|
$this->sanitizeGlobals();
|
||||||
|
|
||||||
|
if ($this->webConfig->get('empty_global_arrays') && $this->webConfig->get('restore_global_arrays'))
|
||||||
|
Events::addListener(
|
||||||
|
array($this, 'restoreGlobalArrays'),
|
||||||
|
'coreShutdownEvent', Priority::HIGH
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function restoreGlobalArrays(NotifierEvent $event)
|
||||||
|
{
|
||||||
|
$_GET = $this->inputArray['get'];
|
||||||
|
$_POST = $this->inputArray['post'];
|
||||||
|
$_COOKIE = $this->inputArray['cookie'];
|
||||||
|
$_SERVER = $this->inputArray['server'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @todo Do this later
|
||||||
|
*/
|
||||||
|
protected function sanitizeGlobals()
|
||||||
|
{
|
||||||
|
// Copy all values from the global arrays into a local inputArray
|
||||||
|
$this->inputArray['get'] = ($this->webConfig->get('allow_get_input') ? $_GET : []);
|
||||||
|
$this->inputArray['post'] = $_POST;
|
||||||
|
$this->inputArray['cookie'] = $_COOKIE;
|
||||||
|
$this->inputArray['server'] = $_SERVER;
|
||||||
|
|
||||||
|
// If required to, empty the global arrays
|
||||||
|
if ($this->webConfig->get('empty_global_arrays'))
|
||||||
|
unset($_GET, $_POST, $_COOKIE, $_SERVER);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $arrayName
|
||||||
|
* @param null $index
|
||||||
|
* @param bool $xssClean
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function getFromInputArray(string $arrayName, $index = null, bool $xssClean = true)
|
||||||
|
{
|
||||||
|
// Clean XSS if requested manually or forced through configuration
|
||||||
|
$xssClean = $xssClean || $this->webConfig->get('xss_clean');
|
||||||
|
|
||||||
|
// If the index is null, the entire array is requested
|
||||||
|
$index = (!is_null($index) ? $index : array_keys($this->inputArray[$arrayName]));
|
||||||
|
|
||||||
|
// If the requested index is an array, fetch all requested fields
|
||||||
|
if (is_array($index))
|
||||||
|
{
|
||||||
|
$values = [];
|
||||||
|
foreach ($index as $key)
|
||||||
|
$values[$key] = $this->getFromInputArray($arrayName, $key, $xssClean);
|
||||||
|
return $values;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the requested index is a string and found, take the value
|
||||||
|
if (isset($this->inputArray[$arrayName][$index]))
|
||||||
|
$value = $this->inputArray[$arrayName][$index];
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
|
||||||
|
// @todo Implement XSS Clean here
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get($index = null, bool $xssClean = true)
|
||||||
|
{
|
||||||
|
return $this->getFromInputArray('get', $index, $xssClean);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function post($index = null, bool $xssClean = true)
|
||||||
|
{
|
||||||
|
return $this->getFromInputArray('post', $index, $xssClean);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postGet($index, bool $xssClean = true)
|
||||||
|
{
|
||||||
|
return isset($this->inputArray['post'][$index]) ? $this->post($index, $xssClean) : $this->get($index, $xssClean);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPost($index, bool $xssClean = true)
|
||||||
|
{
|
||||||
|
return isset($this->inputArray['get'][$index]) ? $this->get($index, $xssClean) : $this->post($index, $xssClean);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function cookie($index = null, bool $xssClean = true)
|
||||||
|
{
|
||||||
|
return $this->getFromInputArray('cookie', $index, $xssClean);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function server($index = null, bool $xssClean = true)
|
||||||
|
{
|
||||||
|
return $this->getFromInputArray('server', $index, $xssClean);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @todo Extend with OldInput functionality
|
||||||
|
*/
|
||||||
|
public function ip()
|
||||||
|
{
|
||||||
|
$ip = '';
|
||||||
|
// Validate IP
|
||||||
|
|
||||||
|
$valid = (
|
||||||
|
(bool)filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ||
|
||||||
|
(bool)filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function userAgent(bool $xssClean = true): string
|
||||||
|
{
|
||||||
|
return $this->getFromInputArray('server', 'HTTP_USER_AGENT', $xssClean);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function method(bool $xssClean = true): string
|
||||||
|
{
|
||||||
|
return $this->getFromInputArray('server', 'REQUEST_METHOD', $xssClean);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,102 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* FuzeWorks WebComponent.
|
||||||
|
*
|
||||||
|
* 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 Output
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Output to be sent to the client
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $output;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Headers to be sent to the client
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $headers = [];
|
||||||
|
|
||||||
|
public function getOutput(): string
|
||||||
|
{
|
||||||
|
return $this->output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setOutput(string $output)
|
||||||
|
{
|
||||||
|
$this->output = $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function appendOutput(string $output)
|
||||||
|
{
|
||||||
|
$this->output .= $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setHeader(string $header)
|
||||||
|
{
|
||||||
|
$this->headers[] = $header;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHeader()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setContentType()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getContentType()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setStatusHeader()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function cache()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* FuzeWorks WebComponent.
|
||||||
|
*
|
||||||
|
* 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 URI
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,80 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* FuzeWorks WebComponent.
|
||||||
|
*
|
||||||
|
* 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 WebComponent implements iComponent
|
||||||
|
{
|
||||||
|
|
||||||
|
public function getName(): string
|
||||||
|
{
|
||||||
|
return "WebComponent";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getClasses(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'web' => $this,
|
||||||
|
'input' => '\FuzeWorks\Input',
|
||||||
|
'output' => '\FuzeWorks\Output'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Configurator $configurator
|
||||||
|
* @todo WebComponent will not always be running when added to FuzeWorks, move this into a separate method
|
||||||
|
*/
|
||||||
|
public function onAddComponent(Configurator $configurator)
|
||||||
|
{
|
||||||
|
// Add dependencies
|
||||||
|
$configurator->addComponent(new MVCRComponent());
|
||||||
|
|
||||||
|
// Invoke methods to prepare system for HTTP calls
|
||||||
|
$configurator->call('logger', 'setLoggerTemplate', null, 'logger_http');
|
||||||
|
|
||||||
|
// Add fallback config directory
|
||||||
|
$configurator->addDirectory(
|
||||||
|
dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Config',
|
||||||
|
'config',
|
||||||
|
Priority::LOWEST
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onCreateContainer(Factory $container)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue