new pisilinux web sites

This commit is contained in:
Erkan IŞIK
2026-07-01 16:44:17 +03:00
commit b58488b586
21740 changed files with 2066209 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
<?php namespace ZN\Request;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
class Env
{
/**
* Magic Call Static
*
* @param string $method
* @param array $parameters
*
* @return mixed
*/
public static function __callStatic($method, $parameters)
{
if( $method === 'all' )
{
return Method::env();
}
return Method::env($method, $parameters[0] ?? NULL);
}
}
@@ -0,0 +1,17 @@
<?php namespace ZN\Request\Exception;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
use ZN\Ability\Exclusion;
class InvalidArgumentException extends \InvalidArgumentException
{
use Exclusion;
}
+31
View File
@@ -0,0 +1,31 @@
<?php namespace ZN\Request;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
class Get
{
/**
* Magic Call Static
*
* @param string $method
* @param array $parameters
*
* @return mixed
*/
public static function __callStatic($method, $parameters)
{
if( $method === 'all' )
{
return Method::get();
}
return Method::get($method, $parameters[0] ?? NULL);
}
}
+373
View File
@@ -0,0 +1,373 @@
<?php namespace ZN\Request;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
use ZN\Request;
use ZN\Datatype;
use ZN\Ability\Singleton;
use ZN\Request\Exception\InvalidArgumentException;
class Http implements HttpInterface
{
use Singleton;
/**
* Settings
*
* @var array
*/
protected static $settings;
/**
* Types
*
* @var array
*/
protected static $types =
[
'post',
'get',
'env',
'server',
'request'
];
/**
* Http Messages
*
* @var array
*/
protected static $messages =
[
# 1XX Information
'100|continue' => '100 Continue',
'101|switchProtocols' => '101 Switching Protocols',
'103|checkpoint' => '103 Checkpoint',
# 2XX Successful
'200|ok' => '200 OK',
'201|created' => '201 Created',
'202|accepted' => '202 Accepted',
'203|nonAuthInfo' => '203 Non-Authoritative Information',
'204|noContent' => '204 No Content',
'205|resetContent' => '205 Reset Content',
'206|partialContent' => '206 Partial Content',
# 3XX Redirection
'300|multipleChoices' => '300 Multiple Choices',
'301|movedPermanent' => '301 Moved Permanently',
'302|found' => '301 Found',
'303|seeOther' => '303 See Other',
'304|notModified' => '304 Not Modified',
'306|switchProxy' => '306 Switch Proxy',
'307|temporaryRedirect' => '307 Temporary Redirect',
'308|resumeIncomplete' => '308 Resume Incomplete',
# 4XX Client Error
'400|badRequest' => '400 Bad Request',
'401|unauth' => '401 Unauthorized',
'402|paymentRequired' => '402 Payment Required',
'403|forbidden' => '403 Forbidden',
'404|notFound' => '404 Not Found',
'405|methodNotAllowed' => '405 Method Not Allowed',
'406|notAccept' => '406 Not Acceptable',
'407|proxyAuth' => '407 Proxy Authentication Required',
'408|requestTimeout' => '408 Request Timeout',
'409|conflict' => '409 Conflict',
'410|gone' => '410 Gone',
'411|lengthRequired' => '411 Length Required',
'412|preconditionFailed' => '412 Precondition Failed',
'413|requestEntity' => '413 Request Entity Too Large',
'414|requestUri' => '414 Request-URI Too Long',
'415|unsupportedMedia' => '415 Unsupported Media Type',
'416|requestedRange' => '416 Requested Range Not Satisfiable',
'417|expectFailed' => '417 Expectation Failed',
# 5XX Server Error
'500|internalServerError' => '500 Internal Server Error',
'501|notImplement' => '501 Not Implemented',
'502|badGateway' => '502 Bad Gateway',
'503|serviceUnavailable' => '503 Service Unavailable',
'504|gatewayTimeout' => '504 Gateway Timeout',
'505|versionNotSupported' => '505 HTTP Version Not Supported',
'511|authRequired' => '511 Network Authentication Required'
];
/**
* Response
*
* @param int $code
* @param string $version = '1.1'
*/
public static function response(int $code, string $version = '1.1')
{
header("HTTP/$version " . self::code($code));
}
/**
* Fix
*
* @param bool $security = false
*
* @return string
*/
public static function fix(bool $security = false) : string
{
return ( $security === false )
? 'http://'
: 'https://';
}
/**
* Host
*
* @return string
*/
public static function host() : string
{
return Server::data('host');
}
/**
* User Agent
*
* @return string
*/
public static function userAgent() : string
{
return Server::data('userAgent');
}
/**
* Accept
*
* @return string
*/
public static function accept() : string
{
return Server::data('accept');
}
/**
* Language
*
* @return string
*/
public static function language() : string
{
return Server::data('acceptLanguage');
}
/**
* Encoding
*
* @return string
*/
public static function encoding() : string
{
return Server::data('acceptEncoding');
}
/**
* Cookie
*
* @return string
*/
public static function cookie() : string
{
return Server::data('cookie');
}
/**
* Connection
*
* @return string
*/
public static function connection() : string
{
return Server::data('connection');
}
/**
* Request method type
*
* @param string ...$methods
*
* @returm bool
*/
public static function isRequestMethod(...$methods) : bool
{
return Request::isMethod(...$methods);
}
/**
* Request is ajax
*
* @param bool
*/
public static function isAjax() : bool
{
return Request::isAjax();
}
/**
* Get Browser Lang
*
* @param string $default = 'en'
*
* @return string
*/
public static function browserLang(string $default = 'en') : string
{
return strtolower(substr(($_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? $default), 0, 2));
}
/**
* Code
*
* @param int|string $code = 200
*
* @return string
*/
public static function code($code = 200) : string
{
$messages = Datatype::multikey(self::$messages);
if( isset($messages[$code]) )
{
return $messages[$code];
}
return false;
}
/**
* Message
*
* @param string $message
*
* @return string
*/
public static function message(string $message) : string
{
return self::code($message);
}
/**
* Name
*
* @param string $name
*
* @return Http
*/
public static function name(string $name) : Http
{
self::$settings['name'] = $name;
return self::singleton();
}
/**
* Value
*
* @param mixed $value
*
* @return Http
*/
public static function value($value) : Http
{
self::$settings['value'] = $value;
return self::singleton();
}
/**
* Input
*
* @param string $input
*
* @return Http
*/
public static function input(string $input) : Http
{
if( in_array($input, self::$types) )
{
self::$settings['input'] = $input;
}
else
{
throw new InvalidArgumentException('Error', 'invalidInput', $input.' : get, post, server, env, request');
}
return self::singleton();
}
/**
* Select
*
* @param string $name
*
* @return mixed
*/
public static function select(?string $name = NULL)
{
$name = self::$settings['name'] ?? $name;
$input = self::$settings['input'] ?? false;
self::$settings = [];
return Method::$input($name);
}
/**
* Insert
*
* @param string $name = NULL
* @param mixed $value = NULL
*
* @return bool
*/
public static function insert(?string $name = NULL, $value = NULL) : bool
{
$name = self::$settings['name'] ?? $name;
$input = self::$settings['input'] ?? false;
$value = self::$settings['value'] ?? $value;
self::$settings = [];
return Method::$input($name, $value);
}
/**
* Insert
*
* @param string $name = NULL
*
* @return bool
*/
public static function delete(?string $name = NULL) : bool
{
$name = self::$settings['name'] ?? $name;
$input = self::$settings['input'] ?? false;
self::$settings = [];
switch( $input )
{
case 'post' : unset($_POST[$name]); break;
case 'get' : unset($_GET[$name]); break;
case 'env' : unset($_ENV[$name]); break;
case 'server' : unset($_SERVER[$name]); break;
case 'request' : unset($_REQUEST[$name]); break;
}
return true;
}
}
+177
View File
@@ -0,0 +1,177 @@
<?php namespace ZN\Request;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
interface HttpInterface
{
/**
* Response
*
* @param int $code
* @param string $version = '1.1'
*/
public static function response(int $code, string $version = '1.1');
/**
* Fix
*
* @param bool $security = false
*
* @return string
*/
public static function fix(bool $security = false) : string;
/**
* Host
*
* @return string
*/
public static function host() : string;
/**
* User Agent
*
* @return string
*/
public static function userAgent() : string;
/**
* Accept
*
* @return string
*/
public static function accept() : string;
/**
* Language
*
* @return string
*/
public static function language() : string;
/**
* Encoding
*
* @return string
*/
public static function encoding() : string;
/**
* Cookie
*
* @return string
*/
public static function cookie() : string;
/**
* Connection
*
* @return string
*/
public static function connection() : string;
/**
* Request method type
*
* @param string ...$methods
*
* @returm bool
*/
public static function isRequestMethod(...$methods) : bool;
/**
* Request is ajax
*
* @param bool
*/
public static function isAjax() : bool;
/**
* Get Browser Lang
*
* @param string $default = 'en'
*
* @return string
*/
public static function browserLang(string $default = 'en') : string;
/**
* Code
*
* @param int|string $code = 200
*
* @return string
*/
public static function code($code = 200) : string;
/**
* Message
*
* @param string $message
*
* @return string
*/
public static function message(string $message) : string;
/**
* Name
*
* @param string $name
*
* @return Http
*/
public static function name(string $name) : Http;
/**
* Value
*
* @param mixed $value
*
* @return Http
*/
public static function value($value) : Http;
/**
* Input
*
* @param string $input
*
* @return Http
*/
public static function input(string $input) : Http;
/**
* Select
*
* @param string $name
*
* @return mixed
*/
public static function select(?string $name = NULL);
/**
* Insert
*
* @param string $name = NULL
* @param mixed $value = NULL
*
* @return bool
*/
public static function insert(?string $name = NULL, $value = NULL) : bool;
/**
* Insert
*
* @param string $name = NULL
*
* @return bool
*/
public static function delete(?string $name = NULL) : bool;
}
+184
View File
@@ -0,0 +1,184 @@
<?php namespace ZN\Request;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
use ZN\In;
use ZN\Security\Html;
use ZN\Protection\Json;
use ZN\DataTypes\Arrays;
class Method implements MethodInterface
{
/**
* Post
*
* @param string $name = NULL
* @param mixed $value = NULL
*
* @return mixed
*/
public static function post(?string $name = NULL, $value = NULL)
{
return self::_method($name, $value, $_POST ,__FUNCTION__);
}
/**
* Get
*
* @param string $name = NULL
* @param mixed $value = NULL
*
* @return mixed
*/
public static function get(?string $name = NULL, $value = NULL)
{
return self::_method($name, $value, $_GET, __FUNCTION__);
}
/**
* Request
*
* @param string $name = NULL
* @param mixed $value = NULL
*
* @return mixed
*/
public static function request(?string $name = NULL, $value = NULL)
{
return self::_method($name, $value, $_REQUEST, __FUNCTION__);
}
/**
* Env
*
* @param string $name = NULL
* @param mixed $value = NULL
*
* @return mixed
*/
public static function env(?string $name = NULL, $value = NULL)
{
return self::_method($name, $value, $_ENV, __FUNCTION__);
}
/**
* Server
*
* @param string $name = ''
* @param mixed $value = NULL
*
* @return mixed
*/
public static function server(string $name = '', $value = NULL)
{
// @value parametresi boş değilse
if( ! empty($value) )
{
$_SERVER[$name] = $value;
}
return Server::data($name);
}
/**
* Files
*
* @param string $filename = NULL
* @param string $type = 'name'
*
* @return mixed
*/
public static function files(?string $fileName = NULL, string $type = 'name')
{
return $_FILES[$fileName][$type] ?? false;
}
/**
* Delete
*
* @param string $input
* @param string $name
*/
public static function delete(string $input, string $name)
{
switch( $input )
{
case 'post' : unset($_POST[$name]); break;
case 'get' : unset($_GET[$name]); break;
case 'env' : unset($_ENV[$name]); break;
case 'server' : unset($_SERVER[$name]); break;
case 'request' : unset($_REQUEST[$name]); break;
}
}
/**
* Protected Method
*/
protected static function _method($name, $value, $input, $type)
{
if( empty($name) )
{
return $input;
}
# @value parametresi boş değilse 5.4.7[edited]
if( $value !== NULL )
{
switch( $type )
{
case 'post' : $_POST[$name] = $value; break;
case 'get' : $_GET[$name] = $value; break;
case 'request' : $_REQUEST[$name] = $value; break;
case 'env' : $_ENV[$name] = $value; break;
}
return true;
}
if( isset($input[$name]) )
{
if( is_scalar($input[$name]) )
{
return self::checkData($input[$name], $type, $name);
}
elseif( is_array($input[$name]) )
{
$input[$name] = Arrays\Force::recursive($input[$name], function($value) use($type, $name)
{
return self::checkData($value, $type, $name);
});
}
return $input[$name];
}
return false;
}
/**
* protected check data
*/
protected static function checkData($value, $type, $name)
{
if( Json::check($value) )
{
return Html::encode($value, 'noquotes');
}
else
{
if( $type === 'get' || ($type === 'request' && isset($_GET[$name])) )
{
$value = In::cleanInjection($value);
}
return Html::encode($value);
}
}
}
@@ -0,0 +1,83 @@
<?php namespace ZN\Request;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
interface MethodInterface
{
/**
* Post
*
* @param string $name
* @param mixed $value
*
* @return mixed
*/
public static function post(string $name, $value);
/**
* Get
*
* @param string $name
* @param mixed $value
*
* @return mixed
*/
public static function get(string $name, $value);
/**
* Env
*
* @param string $name
* @param mixed $value
*
* @return mixed
*/
public static function env(string $name, $value);
/**
* Server
*
* @param string $name
* @param mixed $value
*
* @return mixed
*/
public static function server(string $name, $value);
/**
* Request
*
* @param string $name
* @param mixed $value
*
* @return mixed
*/
public static function request(string $name, $value);
/**
* Files
*
* @param string $fileName
* @param string $type
*
* @return mixed
*/
public static function files(string $fileName, string $type);
/**
* Delete
*
* @param string $input
* @param string $name
*
* @return mixed
*/
public static function delete(string $input, string $name);
}
+31
View File
@@ -0,0 +1,31 @@
<?php namespace ZN\Request;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
class Post
{
/**
* Magic Call Static
*
* @param string $method
* @param array $parameters
*
* @return mixed
*/
public static function __callStatic($method, $parameters)
{
if( $method === 'all' )
{
return Method::post();
}
return Method::post($method, $parameters[0] ?? NULL);
}
}
+98
View File
@@ -0,0 +1,98 @@
<?php namespace ZN\Request;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
use ZN\Helper;
use ZN\Request as Req;
class Request
{
/**
* Magic Call Static
*
* @param string $method
* @param array $parameters
*
* @return mixed
*/
public static function __callStatic($method, $parameters)
{
if( $method === 'all' )
{
return Method::request();
}
return Method::request($method, $parameters[0] ?? NULL);
}
/**
* IP v4
*
* @param void
*
* @return string
*/
public static function ipv4() : string
{
return Req::ipv4();
}
/**
* Scheme
*
* @return string
*/
public static function scheme() : string
{
return Server::data('requestScheme');
}
/**
* Method
*
* @param string $casing = 'upper'
*
* @return string
*/
public static function method(string $casing = 'upper') : string
{
return mb_convert_case(Server::data('requestMethod'), Helper::toConstant($casing, 'MB_CASE_'));
}
/**
* URI
*
* @return string
*/
public static function uri() : string
{
return Server::data('requestUri');
}
/**
* Time
*
* @return int
*/
public static function time() : int
{
return Server::data('requestTime');
}
/**
* Time
*
* @return float
*/
public static function timeFloat() : Float
{
return Server::data('requestTimeFloat');
}
}
+145
View File
@@ -0,0 +1,145 @@
<?php namespace ZN\Request;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
class Server
{
/**
* Magic Call Static
*
* @param string $method
* @param array $parameters
*
* @return mixed
*/
public static function __callStatic($method, $parameters)
{
return self::data($method);
}
/**
* OS
*
* @return string
*
* @codeCoverageIgnore
*/
public static function os() : string
{
if( stristr(PHP_OS, 'WIN') )
{
return 'WIN';
}
elseif( stristr(PHP_OS, 'MAC') )
{
return 'MAC';
}
elseif( stristr(PHP_OS, 'LINUX') )
{
return 'LINUX';
}
elseif( stristr(PHP_OS, 'UNIX') )
{
return 'UNIX';
}
else
{
return 'UNKNOWN';
}
}
/**
* server
*
* The compiled version of the $_SERVER global variable.
*
* @param string $type
*
* @return mixed
*/
public static function data(?string $type = NULL)
{
$server =
[
NULL => $_SERVER,
'name' => $_SERVER['SERVER_NAME'] ?? false,
'admin' => $_SERVER['SERVER_ADMIN'] ?? false,
'addr' => $_SERVER['SERVER_ADDR'] ?? false,
'port' => $_SERVER['SERVER_PORT'] ?? false,
'protocol' => $_SERVER['SERVER_PROTOCOL'] ?? false,
'signature' => $_SERVER['SERVER_SIGNATURE'] ?? false,
'software' => $_SERVER['SERVER_SOFTWARE'] ?? false,
'remoteAddr' => $_SERVER['REMOTE_ADDR'] ?? false,
'remotePort' => $_SERVER['REMOTE_PORT'] ?? false,
'requestMethod' => $_SERVER['REQUEST_METHOD'] ?? false,
'requestUri' => $_SERVER['REQUEST_URI'] ?? false,
'requestScheme' => $_SERVER['REQUEST_SCHEME'] ?? false,
'requestTime' => $_SERVER['REQUEST_TIME'] ?? false,
'requestTimeFloat' => $_SERVER['REQUEST_TIME_FLOAT'] ?? false,
'accept' => $_SERVER['HTTP_ACCEPT'] ?? false,
'acceptCharset' => $_SERVER['HTTP_ACCEPT_CHARSET'] ?? false,
'acceptEncoding' => $_SERVER['HTTP_ACCEPT_ENCODING'] ?? false,
'acceptLanguage' => $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? false,
'clientIp' => $_SERVER['HTTP_CLIENT_IP'] ?? false,
'xForwardedHost' => $_SERVER['HTTP_X_FORWARDED_HOST'] ?? false,
'xForwardedFor' => $_SERVER['HTTP_X_FORWARDED_FOR'] ?? false,
'xOriginalUrl' => $_SERVER['HTTP_X_ORIGINAL_URL'] ?? false,
'xRequestedWith' => $_SERVER['HTTP_X_REQUESTED_WITH'] ?? false,
'connection' => $_SERVER['HTTP_CONNECTION'] ?? false,
'host' => $_SERVER['HTTP_HOST'] ?? false,
'referer' => $_SERVER['HTTP_REFERER'] ?? false,
'userAgent' => $_SERVER['HTTP_USER_AGENT'] ?? false,
'cookie' => $_SERVER['HTTP_COOKIE'] ?? false,
'cacheControl' => $_SERVER['HTTP_CACHE_CONTROL'] ?? false,
'https' => $_SERVER['HTTPS'] ?? false,
'scriptFileName' => $_SERVER['SCRIPT_FILENAME'] ?? false,
'scriptName' => $_SERVER['SCRIPT_NAME'] ?? false,
'path' => $_SERVER['PATH'] ?? false,
'pathInfo' => $_SERVER['PATH_INFO'] ?? false,
'currentPath' => $_SERVER['PATH_INFO'] ?? $_SERVER['QUERY_STRING'] ?? false,
'pathTranslated' => $_SERVER['PATH_TRANSLATED'] ?? false,
'pathext' => $_SERVER['PATHEXT'] ?? false,
'redirectQueryString' => $_SERVER['REDIRECT_QUERY_STRING'] ?? false,
'redirectUrl' => $_SERVER['REDIRECT_URL'] ?? false,
'redirectStatus' => $_SERVER['REDIRECT_STATUS'] ?? false,
'phpSelf' => $_SERVER['PHP_SELF'] ?? false,
'queryString' => $_SERVER['QUERY_STRING'] ?? false,
'documentRoot' => $_SERVER['DOCUMENT_ROOT'] ?? false,
'windir' => $_SERVER['WINDIR'] ?? false,
'comspec' => $_SERVER['COMSPEC'] ?? false,
'systemRoot' => $_SERVER['SystemRoot'] ?? false,
'gatewayInterface' => $_SERVER['GATEWAY_INTERFACE'] ?? false
];
if( $type === 'all' )
{
return $server;
}
if( isset($server[$type]) )
{
if( is_array($server[$type]) )
{
return $server[$type];
}
else
{
$return = htmlspecialchars($server[$type], ENT_QUOTES, "utf-8");
}
}
elseif( isset($_SERVER[$type]) )
{
$return = htmlspecialchars($_SERVER[$type], ENT_QUOTES, "utf-8");
}
// 5.4.3[edited]
return str_replace('&amp;', '&', $return ?? '') ?: false;
}
}
+555
View File
@@ -0,0 +1,555 @@
<?php namespace ZN\Request;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
use ZN\In;
use ZN\IS;
use ZN\Lang;
use ZN\Base;
use ZN\Request;
use ZN\Security;
use ZN\DataTypes\Arrays;
use ZN\DataTypes\Strings;
class URI implements URIInterface
{
/**
* Keeps data.
*
* @param array
*/
protected static $data = NULL;
/**
* Magic Call
*
* @param string $method
* @param array $parameters
*
* @return string|int
*/
public function __call($method, $parameters)
{
if( preg_match('/^(e|s)([0-9]+)$/', $method) )
{
$typ = $method[0];
$num = $method[1];
$val = $typ === 's' ? $num : -($num);
$return = self::segment($val, ...$parameters);
}
else
{
$return = self::get($method, ...$parameters);
}
if( $method[0] == 'X' )
{
$m = substr($method, 1);
return explode('?', self::$m(...$parameters))[0];
}
return $return;
}
/**
* Data usage.
*
* @param string|array $data
*
* @return self
*/
public static function data($data) : URI
{
if( is_string($data) )
{
$data = explode('/', Base::removePrefix($data));
}
self::$data = $data;
return new self;
}
/**
* Manipulation
*
* @param array $rules
* @param string $type = 'none' - options[none|left|right|both]
*
* @return string
*/
public static function manipulation(array $rules, string $type = 'none') : string
{
$query = '';
foreach( $rules as $key => $value )
{
if( is_numeric($key) )
{
if( ! empty($val = self::get($value)) )
{
$query .= $value . '/' . $val . '/';
}
}
else
{
$query .= $key . '/' . $value . '/';
}
}
return self::_addFix($query, $type);
}
/**
* Build Query
*
* @param array $data
* @param string $separator = '/'
* @param string $type = 'none' - options[none|left|right|both]
*
* @return string
*/
public static function buildQuery(array $data, string $separator = '/', string $type = 'none') : string
{
$query = '';
foreach( $data as $key => $value )
{
if( is_numeric($key) )
{
$query .= $value . $separator;
}
else
{
$query .= $key . $separator . $value . $separator;
}
}
return self::_addFix($query, $type, $separator);
}
/**
* Get
*
* @param string|int $get = 1
* @param string|int $index = 1
* @param bool $while = false
*
* @return string
*/
public static function get($get = 1, $index = 1, bool $while = false) : string
{
if( ! IS::char($index) )
{
$index = 1;
}
$segArr = self::segmentArray();
$segVal = '';
if( is_numeric($get) )
{
return self::getByIndex($get, $index, $segArr);
}
if( in_array($get, $segArr) )
{
$segVal = array_search($get, $segArr);
# 3. parameter is not empty
# 2. The non-numerical state of the parameter
if( ! empty($while) && ! is_numeric($index) )
{
return self::getByName($get, $index, $segArr);
}
# 2. the parameter is all-in
# It gives all segments from parameter 1.
if( $index === 'all' )
{
return self::getNameAll($get, $segArr);
}
# 3. parameter is not empty
if( ! empty($while) )
{
$return = '';
$countSegArr = count($segArr) - 1;
if( $index > $countSegArr )
{
$index = $countSegArr; // @codeCoverageIgnore
}
if( $index < 0 )
{
$index = $countSegArr + $index + 1; // @codeCoverageIgnore
}
for( $i = 1; $i <= $index; $i++ )
{
$return .= $segArr[$segVal + $i] . '/';
}
$return = substr($return,0,-1);
return $return;
}
# 2. the parameter is all-in
# It gives all segments from parameter 1.
if( $index === 'count' )
{
return self::getNameCount($get, $segArr);
}
if( isset($segArr[$segVal + $index]) )
{
return $segArr[$segVal + $index];
}
else
{
return false; // @codeCoverageIgnore
}
}
else
{
return false;
}
}
/**
* Returns the number of segments after the specified segment.
*
* @param string $get
*
* @return int
*/
public static function getNameCount(string $get, $segArr = NULL) : int
{
$segArr = $segArr ?? self::segmentArray();
if( in_array($get, $segArr) )
{
$segVal = array_search($get, $segArr);
return count($segArr) - 1 - $segVal;
}
return false;
}
/**
* Returns all segments after the specified segment.
*
* @param string $get
*
* @return string
*/
public static function getNameAll(string $get, $segArr = NULL) : string
{
$segArr = $segArr ?? self::segmentArray();
if( in_array($get, $segArr) )
{
$return = '';
$segVal = array_search($get, $segArr);
for( $i = 1; $i < count($segArr) - $segVal; $i++ )
{
$return .= $segArr[$segVal + $i] . '/';
}
$return = substr($return, 0, -1);
return $return;
}
return false;
}
/**
* Used to get the range according to the index of the specified segment.
*
* @param int $get = 1
* @param int $index = 1
*
* @return string
*/
public static function getByIndex(int $get = 1, int $index = 1, $segArr = NULL) : string
{
$segArr = $segArr ?? self::segmentArray();
if( $get == 0 )
{
$get = 1;
}
$get -= 1;
$countSegArr = count($segArr);
if( $index < 0 )
{
$index = $countSegArr + ($index + 1);
}
else if( $index > 0 )
{
$index = $get + $index;
if( $index > $countSegArr )
{
$index = $countSegArr;
}
}
$uri = '';
for( $i = $get; $i < $index; $i++ )
{
$uri .= $segArr[$i].'/';
}
return rtrim($uri, '/');
}
/**
* Used to get the range according to the specified segment names.
*
* @param string $get
* @param mixed $index = NULL
*
* @return string
*/
public static function getByName(string $get, $index = NULL, $segArr = NULL) : string
{
$segArr = $segArr ?? self::segmentArray();
$getVal = (int) array_search($get, $segArr);
if( $index === 'all' )
{
$indexVal = count($segArr) - 1;
}
else if( $index === NULL )
{
return $segArr[array_search($get, $segArr) + 1] ?? '';
}
else
{
$indexVal = array_search($index, $segArr);
}
$return = '';
for( $i = $getVal; $i <= $indexVal; $i++ )
{
$return .= $segArr[$i] . '/';
}
return substr($return, 0, -1);
}
/**
* Get Segment Array
*
* @return array
*/
public static function segmentArray() : array
{
$segmentEx = self::$data ?? Arrays\RemoveElement::element(explode('/', self::_cleanPath()), '');
self::$data = NULL;
return $segmentEx;
}
/**
* Get Total Segments
*
* @return int
*/
public static function totalSegments() : int
{
$segmentEx = array_diff(self::segmentArray(), ['', ' ']);
$totalSegments = count($segmentEx);
return $totalSegments;
}
/**
* Get Segment Count / Get Total Segments
*
* @return int
*/
public static function segmentCount() : int
{
return self::totalSegments();
}
/**
* Get segment
*
* @param int $set = 1
*
* @return string
*/
public static function segment(int $seg = 1) : string
{
$segments = self::segmentArray();
if( $seg > 0 )
{
$seg -= 1;
}
elseif( $seg < 0 )
{
$count = count($segments);
$seg = $count + $seg;
}
$select = $segments[$seg] ?? false;
if( ! empty($select) )
{
return $segments[$seg];
}
elseif( $select === '0' ) // 5.3.34[added]
{
return (int) $select;
}
return false;
}
/**
* Current Segment
*
* @return string
*/
public static function currentSegment() : string
{
return self::current(false);
}
/**
* Current
*
* @param bool $isPath = true
*
* @return string
*/
public static function current(bool $isPath = true) : string
{
$currentPagePath = str_replace(Lang::get().'/', '', Base::currentPath());
if( ($currentPagePath[0] ?? NULL) === '/' )
{
$currentPagePath = substr($currentPagePath, 1, strlen($currentPagePath) - 1);
}
if( $isPath === true )
{
return $currentPagePath;
}
else
{
$str = explode('/', $currentPagePath);
if( count($str) > 1 )
{
return $str[count($str) - 1];
}
return $str[0]; // @codeCoverageIgnore
}
}
/**
* Get active URI
*
* @param bool $fullPath = false
*
* @return string
*/
public static function active(bool $fullPath = false) : string
{
return Request::getActiveURI($fullPath);
}
/**
* Base
*
* @param string $uri = NULL
*
* @return string
*/
public static function base(?string $uri = NULL) : string
{
return In::cleanInjection(BASE_DIR . $uri);
}
/**
* Prev
*
* @param bool $isPath = true
*
* @return string
*/
public static function prev(bool $isPath = true) : string
{
if( ! isset($_SERVER['HTTP_REFERER']) )
{
return false;
}
$str = str_replace(URL::site(), '', $_SERVER['HTTP_REFERER']);
if( $isPath === true )
{
return $str;
}
else
{
return Strings\Split::divide($str, '/', -1);
}
}
/**
* Protected Clean Path
*/
protected static function _cleanPath()
{
$pathInfo = Security\Html::encode(In::cleanInjection(self::active()));
return $pathInfo;
}
/**
* Protected Add Fix
*/
protected static function _addFix($query, $type, $separator = '/')
{
$query = rtrim($query, $separator);
switch( $type )
{
case 'left' : return Base::prefix($query, $separator);
case 'right' : return Base::suffix($query, $separator);
case 'both' : return Base::presuffix($query, $separator);
default : return $query;
}
}
}
+165
View File
@@ -0,0 +1,165 @@
<?php namespace ZN\Request;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
interface URIInterface
{
/**
* Data usage.
*
* @param string|array $data
*
* @return self
*/
public static function data($data) : URI;
/**
* Manipulation
*
* @param array $rules
* @param string $type = 'none' - options[none|left|right|both]
*
* @return string
*/
public static function manipulation(array $rules, string $type = 'none') : string;
/**
* Build Query
*
* @param array $data
* @param string $separator = '/'
* @param string $type = 'none' - options[none|left|right|both]
*
* @return string
*/
public static function buildQuery(array $data, string $separator = '/', string $type = 'none') : string;
/**
* Get
*
* @param string|int $get = 1
* @param string|int $index = 1
* @param bool $while = false
*
* @return string
*/
public static function get($get = 1, $index = 1, bool $while = false) : string;
/**
* Returns the number of segments after the specified segment.
*
* @param string $get
*
* @return int
*/
public static function getNameCount(string $get) : int;
/**
* Returns all segments after the specified segment.
*
* @param string $get
*
* @return string
*/
public static function getNameAll(string $get) : string;
/**
* Used to get the range according to the index of the specified segment.
*
* @param int $get = 1
* @param int $index = 1
*
* @return string
*/
public static function getByIndex(int $get = 1, int $index = 1) : string;
/**
* Used to get the range according to the specified segment names.
*
* @param string $get
* @param mixed $index = NULL
*
* @return string
*/
public static function getByName(string $get, $index = NULL) : string;
/**
* Get Segment Array
*
* @return array
*/
public static function segmentArray() : array;
/**
* Get Total Segments
*
* @param int
*/
public static function totalSegments() : int;
/**
* Get Segment Count / Get Total Segments
*
* @return int
*/
public static function segmentCount() : int;
/**
* Get segment
*
* @param int $set = 1
*
* @return string
*/
public static function segment(int $seg = 1) : string;
/**
* Current Segment
*
* @return string
*/
public static function currentSegment() : string;
/**
* Current
*
* @param bool $isPath = true
*
* @return string
*/
public static function current(bool $isPath = true) : string;
/**
* Get active URL
*
* @param bool $fullPath = false
*
* @return string
*/
public static function active(bool $fullPath = false) : string;
/**
* Base
*
* @param string $uri = NULL
*
* @return string
*/
public static function base(?string $uri = NULL) : string;
/**
* Prev
*
* @param bool $isPath = true
*
* @return string
*/
public static function prev(bool $isPath = true) : string;
}
+143
View File
@@ -0,0 +1,143 @@
<?php namespace ZN\Request;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
use ZN\Base;
use ZN\Helper;
use ZN\Request;
use ZN\Ability\Singleton;
class URL implements URLInterface
{
use Singleton;
/**
* Sets lang
*
* @param string $lang
*
* @return self
*/
public static function lang(string $lang)
{
Request::$lang = $lang;
return self::singleton();
}
/**
* Get base name
*
* @param string $uri = NULL
*
* @return string
*/
public static function base(?string $uri = NULL) : string
{
return Request::getBaseURL($uri);
}
/**
* Get site URL
*
* @param string $uri = NULL
*
* @return string
*/
public static function site(?string $uri = NULL) : string
{
return Request::getSiteURL($uri);
}
/**
* Get site URLs
*
* @param string $uri = NULL
*
* @return string
*/
public static function sites(?string $uri = NULL) : string
{
return str_replace(SSL_STATUS, Http::fix(true), self::site($uri));
}
/**
* Get host name
*
* @param string $uri = NULL
*
* @return string
*/
public static function host(?string $uri = NULL) : string
{
return Request::getHostName($uri);
}
/**
* Get current URL
*
* @param string $uri = NULL
*
* @return string
*/
public static function current(?string $fix = NULL) : string
{
$currentUrl = Request::getHostName(Server::data('requestUri'));
if( ! empty($fix) )
{
# It allows the parametric value to be inserted after the / symbol.
# If the parametric value is present, it is not appended to the end of the URI.
return Base::suffix(Base::removeSuffix($currentUrl, $fix)) . $fix;
}
return $currentUrl;
}
/**
* Get prev URL
*
* @return string
*/
public static function prev() : string
{
return $_SERVER['HTTP_REFERER'] ?? '';
}
/**
* Build Query
*
* @param mixed $data
* @param string $numericPrefix = NULL
* @param string $separator = NULL
* @param string $type = '+' - options[+|%]
*
* @return mixed
*/
public static function buildQuery($data, ?string $numericPrefix = NULL, ?string $separator = NULL, string $enctype = '+') : string
{
$rfc = $enctype === '+' ? PHP_QUERY_RFC1738 : PHP_QUERY_RFC3986;
return http_build_query($data, $numericPrefix ?? '', $separator ?? '&', $rfc);
}
/**
* Parse URL
*
* @param string $url
* @param mixed $component = 1
*
* @return mixed
*/
public static function parse(string $url, $component = 1)
{
return parse_url($url, Helper::toConstant($component, 'PHP_URL_'));
}
}
+87
View File
@@ -0,0 +1,87 @@
<?php namespace ZN\Request;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
interface URLInterface
{
/**
* Get base name
*
* @param string $uri = NULL
*
* @return string
*/
public static function base(?string $uri = NULL) : string;
/**
* Get site URL
*
* @param string $uri = NULL
*
* @return string
*/
public static function site(?string $uri = NULL) : string;
/**
* Get site URLs
*
* @param string $uri = NULL
*
* @return string
*/
public static function sites(?string $uri = NULL) : string;
/**
* Get host name
*
* @param string $uri = NULL
*
* @return string
*/
public static function host(?string $uri = NULL) : string;
/**
* Get current URL
*
* @param string $uri = NULL
*
* @return string
*/
public static function current(?string $fix = NULL) : string;
/**
* Get prev URL
*
* @return string
*/
public static function prev() : string;
/**
* Build Query
*
* @param mixed $data
* @param string $numericPrefix = NULL
* @param string $separator = NULL
* @param string $type = '+' - options[+|%]
*
* @return mixed
*/
public static function buildQuery($data, ?string $numericPrefix = NULL, ?string $separator = NULL, string $enctype = '+') : string;
/**
* Parse URL
*
* @param string $url
* @param mixed $component = 1
*
* @return mixed
*/
public static function parse(string $url, $component = 1);
}