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
+50
View File
@@ -0,0 +1,50 @@
<?php namespace ZN\Storage;
/**
* 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\DataTypes\Arrays;
use ZN\DataTypes\Strings;
trait CallableKeys
{
/**
* Magic call
*
* @param string $method
* @param array $parameters
*
* @return mixed
*/
public function __call($method, $parameters)
{
$split = Strings\Split::upperCase($method);
if( Arrays\GetElement::last($split) === 'Delete' )
{
$method = 'delete';
return $this->delete($split[0]);
}
if( $method === 'all' )
{
$method = 'selectAll';
return $this->$method();
}
if( $param = ($parameters[0] ?? NULL) )
{
return $this->insert($method, $param);
}
return $this->select($method);
}
}
+304
View File
@@ -0,0 +1,304 @@
<?php namespace ZN\Storage;
/**
* 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\Protection\Json;
use ZN\Storage\Exception\SetcookieException;
class Cookie implements CookieInterface, StorageInterface
{
use StorageCommonMethods;
/**
* Keeps time
*
* @var int
*/
protected $time;
/**
* Keeps path
*
* @var string
*/
protected $path;
/**
* Keeps domain
*
* @var string
*/
protected $domain;
/**
* Keeps secure status
*
* @var bool
*/
protected $secure;
/**
* Keeps http status
*
* @var bool
*/
protected $httpOnly;
/**
* Sets cookie time
*
* @param int $time
*
* @return Cookie
*/
public function time(int $time) : Cookie
{
$this->time = $time;
return $this;
}
/**
* Sets cookie path
*
* @param string $path
*
* @return Cookie
*/
public function path(string $path) : Cookie
{
$this->path = $path;
return $this;
}
/**
* Sets cookie domain
*
* @param string @domain
*
* @return Cookie
*/
public function domain(string $domain) : Cookie
{
$this->domain = $domain;
return $this;
}
/**
* Sets secure status
*
* @param bool $secure = false
*
* @return Cookie
*/
public function secure(bool $secure = false) : Cookie
{
$this->secure = $secure;
return $this;
}
/**
* Sets only http status
*
* @param bool $httpOnly = true
*
* @return Cookie
*/
public function httpOnly(bool $httpOnly = true) : Cookie
{
$this->httpOnly = $httpOnly;
return $this;
}
/**
* Insert cookie
*
* @param string $name
* @param mixed $value
* @param int $time = NULL
*
* @return bool
*/
public function insert(string $name, $value, ?int $time = NULL) : bool
{
if( ! empty($time) ) $this->time($time);
$this->encodeNameValue($name, $value);
$this->addType($_COOKIE, $name, $value);
$this->setParameters();
if( ! is_scalar($value) )
{
$value = Json::encode($value);
}
// @codeCoverageIgnoreStart
if( setcookie($name, $value, time() + $this->time, $this->path, $this->domain, $this->secure, $this->httpOnly) )
{
$this->regenerateSessionId();
$this->defaultVariable();
$this->cookieDefaultVariable();
return true;
}
// @codeCoverageIgnoreEnd
else
{
throw new SetcookieException;
}
}
/**
* Select cookie
*
* @param string $name
*
* @return mixed
*/
public function select(string $name)
{
$this->encodeNameValue($name);
if( isset($_COOKIE[$name]) )
{
return $this->getScalarCookieContentByName($name);
}
else
{
return false;
}
}
/**
* Select all cookie
*
* @param void
*
* @return array
*/
public function selectAll() : array
{
if( ! empty($_COOKIE) )
{
return $_COOKIE;
}
else
{
return [];
}
}
/**
* Delete cookie
*
* @param string $name
* @param string $path = NULL
*
* @param bool
*/
public function delete(string $name, ?string $path = NULL) : bool
{
$this->setCookiePath($path);
$this->encodeNameValue($name);
if( isset($_COOKIE[$name]) )
{
setcookie($name, '', (time() - 1), $this->path);
$this->path = NULL;
return true;
}
else
{
return false;
}
}
/**
* Delete all cookies
*
* @param void
*
* @return bool
*/
public function deleteAll() : bool
{
$path = $this->config['path'];
if( ! empty($_COOKIE) )
{
foreach( $_COOKIE as $key => $val )
{
setcookie($key, '', time() - 1, $path);
}
$_COOKIE = [];
}
else
{
return false; // @codeCoverageIgnore
}
return true;
}
/**
* Protected set parameters
*/
protected function setParameters()
{
if( empty($this->time ) ) $this->time = $this->config['time'];
if( empty($this->path ) ) $this->path = $this->config['path'];
if( empty($this->domain ) ) $this->domain = $this->config['domain'];
if( empty($this->secure ) ) $this->secure = $this->config['secure'];
if( empty($this->httpOnly) ) $this->httpOnly = $this->config['httpOnly'];
}
/**
* Protected set cookie path
*/
protected function setCookiePath($path = NULL)
{
if( empty($this->path) )
{
$this->path = $path ?? $this->config["path"];
}
}
/**
* Protected get scalar cookie content
*/
protected function getScalarCookieContentByName($name)
{
return is_string($_COOKIE[$name]) && Json::check($_COOKIE[$name]) ? Json::decodeArray($_COOKIE[$name]) : $_COOKIE[$name];
}
/**
* Default Cookie Variable
*
* @codeCoverageIgnore
*/
protected function cookieDefaultVariable()
{
$this->time = NULL;
$this->path = NULL;
$this->domain = NULL;
$this->secure = NULL;
$this->httpOnly = NULL;
}
}
@@ -0,0 +1,38 @@
<?php namespace ZN\Storage;
/**
* 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]
*/
/**
* Default Configuration
*
* Enabled when the configuration file can not be accessed.
*/
class CookieDefaultConfiguration
{
/*
|--------------------------------------------------------------------------
| Cookie
|--------------------------------------------------------------------------
|
| Contains settings related to cookies.
| Configures the parameters of the setcookie function.
|
| encode: The cookie keys are set to which algorithm to encrypt.
|
*/
public $encode = 'md5';
public $regenerate = true;
public $time = 604800;
public $path = '/';
public $domain = '';
public $secure = false;
public $httpOnly = true;
}
@@ -0,0 +1,58 @@
<?php namespace ZN\Storage;
/**
* 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 CookieInterface
{
/**
* Sets cookie time
*
* @param int $time
*
* @return Cookie
*/
public function time(int $time) : Cookie;
/**
* Sets cookie path
*
* @param string $path
*
* @return Cookie
*/
public function path(string $path) : Cookie;
/**
* Sets cookie domain
*
* @param string @domain
*
* @return Cookie
*/
public function domain(string $domain) : Cookie;
/**
* Sets secure status
*
* @param bool $secure = false
*
* @return Cookie
*/
public function secure(bool $secure) : Cookie;
/**
* Sets only http status
*
* @param bool $httpOnly = true
*
* @return Cookie
*/
public function httpOnly(bool $httpOnly) : Cookie;
}
@@ -0,0 +1,27 @@
<?php namespace ZN\Storage\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\Exception;
class SetcookieException extends Exception
{
/**
* Exception language settings
*
* @param string en
* @param string tr
*/
const lang =
[
'en' => 'Could not set the cookie!',
'tr' => 'Çerez tanımlanamadı!'
];
}
+36
View File
@@ -0,0 +1,36 @@
<?php namespace ZN\Storage;
/**
* 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\Config;
use ZN\Datatype;
trait Initialize
{
/**
* Keeps storage config
*/
protected $config;
/**
* Magic constructor
*
* @param void
*
* @return void
*/
public function __construct(array $config = [])
{
$this->config = $config ?: Config::default(__CLASS__ . 'DefaultConfiguration')
::get('Storage', strtolower(Datatype::divide(__CLASS__, '\\', -1)));
$this->start();
}
}
+105
View File
@@ -0,0 +1,105 @@
<?php namespace ZN\Storage;
/**
* 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 Session implements StorageInterface
{
use StorageCommonMethods;
/**
* Insert session
*
* @param string $name
* @param mixed $value
*
* @return bool
*/
public function insert(string $name, $value) : bool
{
$this->encodeNameValue($name, $value);
$this->addType($_SESSION, $name, $value);
if( $_SESSION[$name] )
{
$this->regenerateSessionId();
$this->defaultVariable();
return true;
}
else
{
return false;
}
}
/**
* Select session
*
* @param string $name
*
* @return mixed
*/
public function select(string $name)
{
$this->encodeNameValue($name);
return $_SESSION[$name] ?? false;
}
/**
* Select all session
*
* @param void
*
* @return array
*/
public function selectAll() : array
{
return $_SESSION;
}
/**
* Delete session
*
* @param string $name
*
* @return bool
*/
public function delete(string $name) : bool
{
$this->encodeNameValue($name);
if( isset($_SESSION[$name]) )
{
unset($_SESSION[$name]);
return true;
}
else
{
return false;
}
}
/**
* Delete all session
*
* @param void
*
* @return void
*/
public function deleteAll() : bool
{
$_SESSION = [];
return session_destroy();
}
}
@@ -0,0 +1,32 @@
<?php namespace ZN\Storage;
/**
* 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]
*/
/**
* Default Configuration
*
* Enabled when the configuration file can not be accessed.
*/
class SessionDefaultConfiguration
{
/*
|--------------------------------------------------------------------------
| Session
|--------------------------------------------------------------------------
|
| Contains settings related to session.
|
| encode: The session keys are set to which algorithm to encrypt.
|
*/
public $encode = 'md5';
public $regenerate = true;
}
+27
View File
@@ -0,0 +1,27 @@
<?php namespace ZN\Storage;
/**
* 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\Container;
class Storage
{
use Container;
/**
* Magic constructor
*
* @param StorageInterface $storage
*/
public function __construct(StorageInterface $storage = NULL)
{
self::$container = $storage;
}
}
@@ -0,0 +1,224 @@
<?php namespace ZN\Storage;
/**
* 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\IS;
use ZN\DataTypes\Arrays;
use ZN\Cryptography\Encode;
trait StorageCommonMethods
{
use CallableKeys, Initialize;
/**
* Regenarate session
*
* @var bool
*/
protected $regenerate = true;
/**
* Encode session keys
*
* @var array
*/
protected $encode = [];
/**
* Keeps storage parameters
*
* @var array
*/
protected $param = NULL;
/**
* Inserts at the beginning of the data.
*
* @return this
*/
public function first()
{
$this->param['addType'] = 'first';
return $this;
}
/**
* Inserts at the lasting of the data.
*
* @return this
*/
public function last()
{
$this->param['addType'] = 'last';
return $this;
}
/**
* Session start
*
* @param void
*
* @return void
*/
public static function start()
{
if( ! isset($_SESSION) )
{
session_start();
}
}
/**
* Encode session key & value
*
* @param string $nameAlgo = NULL
* @param string $valueAlgo = NULL
*
* @return $this
*/
public function encode(?string $nameAlgo = NULL, ?string $valueAlgo = NULL)
{
$this->encode['name'] = $nameAlgo;
$this->encode['value'] = $valueAlgo;
return $this;
}
/**
* Decode only session key
*
* @param string $nameAlgo
*
* @return $this
*/
public function decode(string $nameAlgo)
{
$this->encode['name'] = $nameAlgo;
return $this;
}
/**
* Regenerate status
*
* @param bool $regenerate = true
*
* @return $this
*/
public function regenerate(bool $regenerate = true)
{
$this->regenerate = $regenerate;
return $this;
}
/**
* Protected regenerate session id
*/
protected function regenerateSessionId()
{
if( $this->regenerate === true )
{
session_regenerate_id();
}
}
/**
* Protected add type
*/
protected function addType(&$type, $name, $value)
{
if( $addType = ($this->param['addType'] ?? NULL) )
{
$type[$name] = Arrays\AddElement::$addType((array) $type[$name], $value);
$this->param['addType'] = NULL;
}
else
{
$type[$name] = $value;
}
}
/**
* Protected encode name value
*/
protected function encodeNameValue(&$name, &$value = NULL)
{
if( ! empty($this->encode) )
{
$this->encodeDataByType($name, 'name');
if( $value !== NULL )
{
$this->encodeDataByType($value, 'value');
}
}
if( ! isset($this->encode['name']) )
{
$this->defaultEncodeData($name);
}
$this->encode = [];
}
/**
* Protected default encode data
*/
protected function defaultEncodeData(&$name)
{
if( ($encode = $this->config['encode']) === true )
{
$name = md5($name); // @codeCoverageIgnore
}
elseif( is_string($encode) )
{
$this->encodeDataIfValidHash($name, $encode);
}
}
/**
* Protected encode data by type
*/
protected function encodeDataByType(&$data, $type = 'value')
{
if( isset($this->encode[$type]) )
{
$this->encodeDataIfValidHash($data, $this->encode[$type]);
}
}
/**
* Protected encode data if valid hash
*/
protected function encodeDataIfValidHash(&$data, $encode)
{
if( IS::hash($encode) )
{
$data = Encode\Type::create($data, $encode);
}
}
/**
* protected default variable
*
* @param void
*
* @return void
*/
protected function defaultVariable()
{
$this->encode = [];
$this->regenerate = true;
}
}
@@ -0,0 +1,110 @@
<?php namespace ZN\Storage;
/**
* 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 StorageInterface
{
/**
* Inserts at the beginning of the data.
*
* @return this
*/
public function first();
/**
* Inserts at the lasting of the data.
*
* @return this
*/
public function last();
/**
* Encode session key & value
*
* @param string $nameAlgo = NULL
* @param string $valueAlgo = NULL
*
* @return $this
*/
public function encode(string $name, string $value);
/**
* Decode only session key
*
* @param string $nameAlgo
*
* @return $this
*/
public function decode(string $hash);
/**
* Regenerate status
*
* @param bool $regenerate = true
*
* @return $this
*/
public function regenerate(bool $regenerate);
/**
* Insert session
*
* @param string $name
* @param mixed $value
*
* @return bool
*/
public function insert(string $name, $value) : bool;
/**
* Select session
*
* @param string $name
*
* @return mixed
*/
public function select(string $name);
/**
* Delete session
*
* @param string $name
*
* @return bool
*/
public function delete(string $name) : bool;
/**
* Select all session
*
* @param void
*
* @return array
*/
public function selectAll() : array;
/**
* Delete all session
*
* @param void
*
* @return void
*/
public function deleteAll() : bool;
/**
* Session start
*
* @param void
*
* @return void
*/
public static function start();
}