new pisilinux web sites
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
<?php namespace ZN\Ability;
|
||||
/**
|
||||
* 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\Classes;
|
||||
|
||||
trait Configurable
|
||||
{
|
||||
/**
|
||||
* Magic call static
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function __callStatic($method, $parameters)
|
||||
{
|
||||
# Class name information without a namespace.
|
||||
$config = self::getOnlyClassName();
|
||||
|
||||
# The called method name is accepted as the first parameter.
|
||||
array_unshift($parameters, $method);
|
||||
|
||||
# If it contains at least 2 or 3 parameters,
|
||||
# it means that reconfiguration is being performed.
|
||||
if( is_array($parameters[0] ?? NULL) || count($parameters) >= 2 )
|
||||
{
|
||||
# Settings are being reconfigured.
|
||||
return Config::set($config, ...$parameters);
|
||||
}
|
||||
|
||||
# If no reconfiguration condition is found, the current settings are returned.
|
||||
return Config::get($config, ...$parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all config
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function all() : array
|
||||
{
|
||||
return Config::get(self::getOnlyClassName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get only class name
|
||||
*/
|
||||
protected static function getOnlyClassName()
|
||||
{
|
||||
return Classes::onlyName(__CLASS__);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php namespace ZN\Ability;
|
||||
/**
|
||||
* 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\Datatype;
|
||||
use ZN\Singleton;
|
||||
use ZN\Ability\Exception\InvalidContainerMethod;
|
||||
use ZN\Ability\Exception\UnsupportedDriverException;
|
||||
|
||||
trait Container
|
||||
{
|
||||
/**
|
||||
* Keeps class interface..
|
||||
*
|
||||
* @var StorageInterface
|
||||
*/
|
||||
protected static $container;
|
||||
|
||||
/**
|
||||
* Magic call
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
return self::call($method, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic call static
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function __callStatic($method, $parameters)
|
||||
{
|
||||
return self::call($method, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get driver
|
||||
*
|
||||
* @param string $class
|
||||
*
|
||||
* @return ZN\Singleton
|
||||
*/
|
||||
public static function driver(string $class)
|
||||
{
|
||||
$class = Datatype::divide(__CLASS__, '\\', 0, -1) . ucfirst($origin = $class);
|
||||
|
||||
if( ! class_exists($class) )
|
||||
{
|
||||
throw new UnsupportedDriverException(NULL, ['%' => $origin, '#' => __CLASS__]);
|
||||
}
|
||||
|
||||
return Singleton::class($class); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected static call
|
||||
*/
|
||||
protected static function call($method, $parameters)
|
||||
{
|
||||
if( method_exists(self::$container, $method) )
|
||||
{
|
||||
return self::$container->$method(...$parameters);
|
||||
}
|
||||
|
||||
throw new InvalidContainerMethod(NULL, ['%' => $method, '#' => __CLASS__]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php namespace ZN\Ability;
|
||||
/**
|
||||
* 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\Config;
|
||||
use ZN\Support;
|
||||
use ZN\Singleton;
|
||||
use ZN\Exception\UndefinedConstException;
|
||||
|
||||
trait Driver
|
||||
{
|
||||
/**
|
||||
* protected driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $driver;
|
||||
|
||||
/**
|
||||
* protected driver name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $selectedDriverName;
|
||||
|
||||
/**
|
||||
* magic constructor
|
||||
*
|
||||
* @param string $driver = NULL
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(?string $driver = NULL)
|
||||
{
|
||||
# If parent class does not contain driver constant, the operation is stopped.
|
||||
if( ! defined('static::driver') )
|
||||
{
|
||||
throw new UndefinedConstException('[const driver] is required to use the [Driver Ability]!'); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
# 5.3.42|5.4.5|5.6.0[edited]
|
||||
$driver = $driver ?? # driver($driver)
|
||||
$this->config['driver'] ?? # class name driver
|
||||
$this->getDriverNameFromDriverConstant() ?: # define config
|
||||
$this->getDefaultDriverNameFromDriverConstant() ?: # define default
|
||||
static::driver['options'][0] ?? // @codeCoverageIgnore
|
||||
$this->setNullDefaultDriverName(); # Default driver name is NULL
|
||||
|
||||
# It checks whether the selected driver is a valid driver.
|
||||
Support::driver(static::driver['options'], $driver);
|
||||
|
||||
# The selected drive stores its name.
|
||||
$this->selectedDriverName = $driver;
|
||||
|
||||
# Drivers should be written with Pascal case notation.
|
||||
$driver = ucfirst($driver);
|
||||
|
||||
# If the driver does not contain a namespace, it is called directly.
|
||||
if( ! isset(static::driver['namespace']) )
|
||||
{
|
||||
$this->driver = Singleton::class($driver);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->driver = $this->createSingletonInstanceDriverClass($driver);
|
||||
}
|
||||
|
||||
# This ability is used to trigger a method of the parent class in the __construct method.
|
||||
if( isset(static::driver['construct']) )
|
||||
{
|
||||
$construct = static::driver['construct'];
|
||||
|
||||
$this->{$construct}();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Select driver
|
||||
*
|
||||
* @param string $driver
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function driver(string $driver) : self
|
||||
{
|
||||
return new self($driver);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected set null default driver name.
|
||||
*/
|
||||
protected function setNullDefaultDriverName()
|
||||
{
|
||||
return 'NULL';
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected create singleton instance driver class.
|
||||
*/
|
||||
protected function createSingletonInstanceDriverClass($driver)
|
||||
{
|
||||
return Singleton::class(Base::suffix(static::driver['namespace'], '\\') . $driver . 'Driver');
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get driver name from driver constant.
|
||||
*/
|
||||
protected function getDriverNameFromDriverConstant()
|
||||
{
|
||||
return isset(static::driver['config']) ? Config::get(...explode(':', static::driver['config']))['driver'] : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get default driver name from driver constant.
|
||||
*/
|
||||
protected function getDefaultDriverNameFromDriverConstant()
|
||||
{
|
||||
return isset(static::driver['default']) ? get_class_vars(static::driver['default'])['driver'] : NULL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php namespace ZN\Ability\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 InvalidContainerMethod extends Exception
|
||||
{
|
||||
const lang =
|
||||
[
|
||||
'tr' => '[#::%()] yöntemi tanımlı değil!',
|
||||
'en' => 'The [#::%()] method is undefined!'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php namespace ZN\Ability\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 InvalidFactoryMethod extends Exception
|
||||
{
|
||||
const lang =
|
||||
[
|
||||
'tr' => '[%] parametre geçersiz fabrika yöntemi içeriyor!',
|
||||
'en' => '[%] parameter contains invalid factory method!'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php namespace ZN\Ability\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 UnsupportedDriverException extends Exception
|
||||
{
|
||||
/**
|
||||
* Exception language settings
|
||||
*
|
||||
* @param string en
|
||||
* @param string tr
|
||||
*/
|
||||
const lang =
|
||||
[
|
||||
'en' => '[%] driver is not a valid driver for class [#]!',
|
||||
'tr' => '[%] sürücüsü [#] sınıfı için geçerli bir sürücü değil!'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php namespace ZN\Ability;
|
||||
/**
|
||||
* 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\Lang;
|
||||
use ZN\ErrorHandling\Exceptions;
|
||||
|
||||
trait Exclusion
|
||||
{
|
||||
/**
|
||||
* Magic constructor
|
||||
*
|
||||
* @param string $file = NULL
|
||||
* @param string $message = NULL
|
||||
* @param mixed $changed = NULL
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($file = NULL, $message = NULL, $changed = NULL)
|
||||
{
|
||||
# If the 1. parameter is set to NULL,
|
||||
# the language contents defined in the exception class are used.
|
||||
if( defined('static::lang') && $file === NULL )
|
||||
{
|
||||
# Language content is being obtained.
|
||||
$content = static::lang[Lang::get()] ?? 'No Exception Lang';
|
||||
|
||||
# The 2.($message) parameter is assumed to be the parameter that will contain the statements to be placed.
|
||||
$placement = static::lang['placement'] ?? $message;
|
||||
|
||||
# If there is an phrase insertion, the message is rearranged.
|
||||
$message = $this->phrasePlacement($content, $placement);
|
||||
}
|
||||
else
|
||||
{
|
||||
# If the parameters are set as Lang::select(),
|
||||
# this method is enabled.
|
||||
if( is_scalar($data = Lang::default('ZN\CoreDefaultLanguage')::select($file, $message, $changed)) && ! empty($data) )
|
||||
{
|
||||
$message = $data;
|
||||
}
|
||||
# If 1. parameter is an exception object,
|
||||
# the contents of the object's message are retrieved.
|
||||
elseif( is_object($file) )
|
||||
{
|
||||
$message = $file->getMessage();
|
||||
}
|
||||
# The 1. parameter can be used directly as message content.
|
||||
else
|
||||
{
|
||||
$message = $file;
|
||||
}
|
||||
}
|
||||
|
||||
# The constructor method of the exception class goes into effect.
|
||||
parent::__construct($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Code continue
|
||||
*
|
||||
* @param void
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function continue()
|
||||
{
|
||||
echo Exceptions::continue($this->getMessage(), $this->getFile(), $this->getLine());
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected phrase placement
|
||||
*/
|
||||
protected function phrasePlacement($content, $placement)
|
||||
{
|
||||
if( is_array($placement) )
|
||||
{
|
||||
return str_replace(array_keys($placement), array_values($placement), $content);
|
||||
}
|
||||
|
||||
return str_replace('%', $placement, $content);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php namespace ZN\Ability;
|
||||
/**
|
||||
* 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]
|
||||
*/
|
||||
|
||||
trait Fabrication
|
||||
{
|
||||
/**
|
||||
* Magic call
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
# It provides a way to invoke class groups of certain names as methods.
|
||||
return $this->call($parameters, $method);
|
||||
}
|
||||
|
||||
/**
|
||||
* protected call
|
||||
*
|
||||
* @param array $parameters
|
||||
* @param string $type = NULL
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function call($parameters, $type = NULL)
|
||||
{
|
||||
# For example ReflectionClass
|
||||
# A usage like ReflectionClass is obtained by using Reflect::class.
|
||||
$class = (self::fabrication['prefix'] ?? NULL) . $type . (self::fabrication['suffix'] ?? NULL);
|
||||
|
||||
# It can be thought of as a factory that produces a class.
|
||||
return (new $class(...$parameters));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php namespace ZN\Ability;
|
||||
/**
|
||||
* 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\Singleton;
|
||||
|
||||
trait Facade
|
||||
{
|
||||
/**
|
||||
* Magic call static
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function __callStatic($method, $parameters)
|
||||
{
|
||||
return self::useClassName($method, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic call
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
return self::useClassName($method, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use class name
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected static function useClassName($method, $parameters)
|
||||
{
|
||||
return Singleton::class(static::target)->$method(...$parameters);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
<?php namespace ZN\Ability;
|
||||
/**
|
||||
* 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\Support;
|
||||
use ZN\Singleton;
|
||||
|
||||
trait Factory
|
||||
{
|
||||
/**
|
||||
* Magic call static
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function __callStatic($method, $parameters)
|
||||
{
|
||||
return self::call($method, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic call
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
return $this->call($method, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic call
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function call($method, $parameters)
|
||||
{
|
||||
if( ! defined('static::factory') )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$method = strtolower($originMethodName = $method);
|
||||
|
||||
if( ! isset(static::factory['methods'][$method]) )
|
||||
{
|
||||
Support::classMethod(get_called_class(), $originMethodName);
|
||||
}
|
||||
|
||||
# The subclass and method that the method will execute is taken.
|
||||
$class = static::factory['methods'][$method];
|
||||
|
||||
# The class to be used as factory for the library used is defined.
|
||||
# However, this usage is not necessary.
|
||||
$factory = static::factory['class'] ?? NULL;
|
||||
|
||||
if( $factory !== NULL )
|
||||
{
|
||||
return $factory::class($class)->$method(...$parameters); // @codeCoverageIgnore
|
||||
}
|
||||
# It can call the desired method of another class.
|
||||
# That is, it opens the way to a mixed class design
|
||||
# that consists of methods of various classes.
|
||||
else
|
||||
{
|
||||
# Solving starts when a valid class and method information is sent.
|
||||
if( ! self::isValidClassAndMethodName($class, $resolve) )
|
||||
{
|
||||
throw new Exception\InvalidFactoryMethod(NULL, $class);
|
||||
}
|
||||
|
||||
# A new singleton inheritance class instance is created.
|
||||
$return = self::createSingletonInstance($resolve['class'], $resolve['method'], $parameters);
|
||||
|
||||
# The return value $this can be sent to ensure object continuity.
|
||||
if( isset($resolve['this']) )
|
||||
{
|
||||
$parent = get_called_class();
|
||||
|
||||
return new $parent;
|
||||
}
|
||||
|
||||
# Return new instance.
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected create singleton instance
|
||||
*/
|
||||
protected static function createSingletonInstance($class, $method, $parameters)
|
||||
{
|
||||
return Singleton::class(self::getCalledClassNamespace() . $class)->$method(...$parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get called class namespace
|
||||
*/
|
||||
protected static function getCalledClassNamespace()
|
||||
{
|
||||
$namespace = NULL;
|
||||
|
||||
# The namespace is being rebuilt.
|
||||
if( strstr($calledClass = get_called_class(), $separator = '\\') )
|
||||
{
|
||||
$namespace = explode($separator, $calledClass);
|
||||
|
||||
array_pop($namespace);
|
||||
|
||||
$namespace = implode($separator, $namespace) . $separator;
|
||||
}
|
||||
|
||||
return $namespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected is valid class & method name.
|
||||
*/
|
||||
protected static function isValidClassAndMethodName($class, &$resolve)
|
||||
{
|
||||
return preg_match('/(?<class>([a-zA-Z]\w+(\\\\)*){1,})\:\:(?<method>\w+)(?<this>\:this)*/', $class ?? '', $resolve);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php namespace ZN\Ability;
|
||||
/**
|
||||
* 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]
|
||||
*/
|
||||
|
||||
trait Functionalization
|
||||
{
|
||||
/**
|
||||
* Magic call
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
# It allows a library to cluster the desired functions within it.
|
||||
if( $standart = (static::functionalization[strtolower($method)] ?? NULL) )
|
||||
{
|
||||
return $standart(...$parameters);
|
||||
}
|
||||
|
||||
$getParentClass = get_parent_class($this);
|
||||
|
||||
# The __call method of the parent class does not lose its functionality.
|
||||
if( $getParentClass && method_exists($getParentClass, '__call'))
|
||||
{
|
||||
return parent::__call($method, $parameters);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php namespace ZN\Ability;
|
||||
/**
|
||||
* 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\Lang;
|
||||
|
||||
trait Information
|
||||
{
|
||||
/**
|
||||
* Catch error
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $error;
|
||||
|
||||
/**
|
||||
* Catch success
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $success;
|
||||
|
||||
/**
|
||||
* Classes that incorporate this feature include a structure that can hold error messages.
|
||||
*
|
||||
* @param string $endOfLine = '<br>'
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function error(string $endOfLine = '<br>')
|
||||
{
|
||||
if( ! empty($this->error) )
|
||||
{
|
||||
if( is_array($this->error) )
|
||||
{
|
||||
return implode($endOfLine, $this->error);
|
||||
}
|
||||
|
||||
return $this->error;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Classes that incorporate this feature include a structure that can hold success messages.
|
||||
*
|
||||
* @param string $endOfLine = '<br>'
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function success(string $endOfLine = '<br>')
|
||||
{
|
||||
if( empty($this->error) )
|
||||
{
|
||||
if( ! empty($this->success) )
|
||||
{
|
||||
if( is_array($this->success) )
|
||||
{
|
||||
return implode($endOfLine, $this->success);
|
||||
}
|
||||
|
||||
return $this->success;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Lang::default('ZN\CoreDefaultLanguage')::select('Success', 'success');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Classes that incorporate this feature include a structure that can hold error or success messages.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function status()
|
||||
{
|
||||
if( $success = $this->success() )
|
||||
{
|
||||
return $success;
|
||||
}
|
||||
|
||||
return $this->error();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php namespace ZN\Ability;
|
||||
/**
|
||||
* 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]
|
||||
*/
|
||||
|
||||
trait Revolving
|
||||
{
|
||||
/**
|
||||
* Get revolving values
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $revolvings;
|
||||
|
||||
/**
|
||||
* Magic call
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $param
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function __call($method, $param)
|
||||
{
|
||||
# It opens the way for you to use multiple magic call methods.
|
||||
if( defined('static::call') )
|
||||
{
|
||||
if( $return = $this->{static::call}($method, $param) )
|
||||
{
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
||||
$this->$method = (count($param ?? []) > 1) ? $param : ($param[0] ?? NULL);
|
||||
|
||||
$this->revolvings[$method] = $this->$method;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic call static
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $param
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function __callStatic($method, $param)
|
||||
{
|
||||
return (new self)->__call($method, $param);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default variables
|
||||
*
|
||||
* @param string $type = 'all'
|
||||
* @param bool $self = false
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function defaultVariables($type = 'all', $self = false)
|
||||
{
|
||||
if( $type === NULL )
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if( is_array($type) )
|
||||
{
|
||||
foreach( $type as $key )
|
||||
{
|
||||
$this->$key = ($self === false ? NULL : $var);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
# Gets class variables.
|
||||
$vars = $this->getClassVarsByType($type);
|
||||
|
||||
# MDefaults all class properties null.
|
||||
foreach( $vars as $key => $var )
|
||||
{
|
||||
$this->$key = ($self === false ? NULL : $var);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get class vars
|
||||
*/
|
||||
protected function getClassVarsByType($type)
|
||||
{
|
||||
return $type === 'all' ? get_class_vars(get_called_class()) : $this->revolvings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default revolving variables
|
||||
*
|
||||
* @param void
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function defaultRevolvingVariables($type = NULL)
|
||||
{
|
||||
# It only converts the properties that this property creates to a null value.
|
||||
$this->defaultVariables($type);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php namespace ZN\Ability;
|
||||
/**
|
||||
* 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]
|
||||
*/
|
||||
|
||||
trait Serialization
|
||||
{
|
||||
/**
|
||||
* Magic call
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
# Gets lower method name.
|
||||
$lowerMethodName = strtolower($method);
|
||||
|
||||
# Gets serialization class name.
|
||||
$class = self::serialization['class'];
|
||||
|
||||
# Gets process type.
|
||||
# If operation type data is selected, operation is continued on the value sent as parameter.
|
||||
# Otherwise, the operation continues on the last value returned from the parameter being processed.
|
||||
$process = (self::serialization['process'] ?? 'serial') === 'serial' ? 'data' : 'return';
|
||||
|
||||
# The name of the first method that holds the data to be processed.
|
||||
if( $lowerMethodName === self::serialization['start'] )
|
||||
{
|
||||
$this->data = $parameters[0];
|
||||
}
|
||||
# The name of the final method to complete the process flow.
|
||||
elseif( $lowerMethodName === self::serialization['end'] )
|
||||
{
|
||||
return $this->$process;
|
||||
}
|
||||
# Otherwise, the invoked other class methods are executed.
|
||||
else
|
||||
{
|
||||
$this->$process = $class::$method($this->data, ...$parameters);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php namespace ZN\Ability;
|
||||
/**
|
||||
* 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]
|
||||
*/
|
||||
|
||||
trait Singleton
|
||||
{
|
||||
/**
|
||||
* singleton
|
||||
*
|
||||
* @var self
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
protected static $singleton = NULL;
|
||||
|
||||
/**
|
||||
* singleton
|
||||
*
|
||||
* @param void
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
protected static function singleton()
|
||||
{
|
||||
if( ! self::$singleton instanceof self )
|
||||
{
|
||||
self::$singleton = new self;
|
||||
}
|
||||
|
||||
return self::$singleton;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php namespace ZN\Ability;
|
||||
/**
|
||||
* 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\Lang;
|
||||
use ZN\Classes;
|
||||
|
||||
trait Speech
|
||||
{
|
||||
/**
|
||||
* Magic call static
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function __callStatic($method, $parameters)
|
||||
{
|
||||
$config = self::getOnlyClassName();
|
||||
|
||||
array_unshift($parameters, $method);
|
||||
|
||||
return Lang::default('ZN\CoreDefaultLanguage')::select($config, ...$parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all config
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function all() : array
|
||||
{
|
||||
return Lang::default('ZN\CoreDefaultLanguage')::select(self::getOnlyClassName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get only class name
|
||||
*/
|
||||
protected static function getOnlyClassName()
|
||||
{
|
||||
return Classes::onlyName(__CLASS__);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,841 @@
|
||||
<?php namespace ZN;
|
||||
/**
|
||||
* 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 Autoloader
|
||||
{
|
||||
/**
|
||||
* Keep classes
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $classes;
|
||||
|
||||
/**
|
||||
* Keep namespaces
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $namespaces;
|
||||
|
||||
/**
|
||||
* Keep classmap path
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $path = PROJECT_DIR . 'map.php';
|
||||
|
||||
/**
|
||||
* Keep static access directory
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $staticAccessDirectory = RESOURCES_DIR . 'Statics/';
|
||||
|
||||
/**
|
||||
* Starts the class load process.
|
||||
*
|
||||
* @param string $class
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function run(string $class)
|
||||
{
|
||||
# Automatically loads internal facade class.
|
||||
if( self::facade($class) !== false )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
# If a valid ClassMap file can not be found, this file is recreated.
|
||||
# Immediately before this build, the auto-installer performs a class
|
||||
# lookup in the directories that are defined.
|
||||
if( ! is_file(self::$path) )
|
||||
{
|
||||
self::createClassMap(); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
# Getting information from the class map of the class being called according to ZN's autoloader.
|
||||
$classInfo = self::getClassFileInfo($class);
|
||||
|
||||
# If the class file exists, it is included.
|
||||
if( is_file($file = $classInfo['path']) )
|
||||
{
|
||||
# Requires class file.
|
||||
require $file;
|
||||
|
||||
# If the class file can not be loaded, the class map is rebuilt.
|
||||
if( self::isClassExists($classInfo['namespace']) )
|
||||
{
|
||||
self::tryAgainCreateClassMap($class);
|
||||
}
|
||||
}
|
||||
# If the file of the invoked class does not contain a valid path, the class map is rebuilt.
|
||||
else
|
||||
{
|
||||
self::tryAgainCreateClassMap($class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Autoload Facade
|
||||
*
|
||||
* @param string $class
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function facade(string $class)
|
||||
{
|
||||
# The namespace of the invoked class is converted to path information.
|
||||
$path = str_replace('\\', '/', $class) . '.php';
|
||||
|
||||
# If a facade class is called, this part goes into effect.
|
||||
if( strpos($class, 'ZN\\') !== 0 && is_file($file = (__DIR__ . '/Facades/' . $path)) )
|
||||
{
|
||||
require $file; return;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restarts the class mapping process.
|
||||
*
|
||||
* @param void
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function restart()
|
||||
{
|
||||
if( is_file(self::$path) )
|
||||
{
|
||||
unlink(self::$path);
|
||||
}
|
||||
|
||||
return self::createClassMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the class mapping process.
|
||||
*
|
||||
* @param void
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function createClassMap()
|
||||
{
|
||||
# Clears file status cache.
|
||||
clearstatcache();
|
||||
|
||||
# Getting predefined autoload settings.
|
||||
$configAutoloader = Config::get('Autoloader') ?:
|
||||
# Default class map directory.
|
||||
# Applies to custom edition and individual package usage.
|
||||
[
|
||||
'directoryScanning' => true, // @codeCoverageIgnore
|
||||
'classMap' => [REAL_BASE_DIR]
|
||||
];
|
||||
|
||||
# If the 'directoryScanning' value in the Settings/Autoloader.php
|
||||
# setting file is set to false, it will not scan the directory
|
||||
# Setting this value to true is not recommended.
|
||||
if( $configAutoloader['directoryScanning'] === false )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
# Directory information for class scanning is being retrieved.
|
||||
# Settings/Autoloader.php -> classMap key.
|
||||
$classMap = array_reverse($configAutoloader['classMap']);
|
||||
|
||||
# The classes are scanned in the specified directories.
|
||||
if( ! empty($classMap) ) foreach( $classMap as $directory )
|
||||
{
|
||||
$classMaps = self::searchClassMap($directory);
|
||||
}
|
||||
|
||||
# The top output of the class map is being generated.
|
||||
self::createClassMapTopOutput($classMapPage);
|
||||
|
||||
# Gets classes content.
|
||||
self::getClassesAndNamespacesOutput('classes', $classMaps, $classMapPage);
|
||||
|
||||
# Gets namespaces content.
|
||||
self::getClassesAndNamespacesOutput('namespaces', $classMaps, $classMapPage);
|
||||
|
||||
# It is checked whether the content to be newly added is empty.
|
||||
# 5.7.4.4[added|changed]
|
||||
self::addToClassMap($classMapPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* The invoked class holds the class, path, and namespace information.
|
||||
*
|
||||
* @param string $class
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getClassFileInfo(string $class) : array
|
||||
{
|
||||
$classCaseLower = strtolower($class);
|
||||
$classMap = self::getClassMapContent();
|
||||
$classes = array_merge($classMap['classes'] ?? [], (array) self::$classes);
|
||||
$namespaces = array_merge($classMap['namespaces'] ?? [], (array) self::$namespaces);
|
||||
$path = '';
|
||||
$namespace = '';
|
||||
|
||||
if( isset($classes[$classCaseLower]) )
|
||||
{
|
||||
$path = $classes[$classCaseLower];
|
||||
$namespace = $class;
|
||||
}
|
||||
elseif( ! empty($namespaces) )
|
||||
{
|
||||
$namespaces = array_flip($namespaces);
|
||||
|
||||
if( isset($namespaces[$classCaseLower]) )
|
||||
{
|
||||
$namespace = $namespaces[$classCaseLower];
|
||||
$path = $classes[$namespace] ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
[
|
||||
'path' => $path,
|
||||
'class' => $class,
|
||||
'namespace' => $namespace
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tokenize
|
||||
*/
|
||||
protected static function tokenize($code)
|
||||
{
|
||||
return token_get_all($code);
|
||||
}
|
||||
|
||||
/**
|
||||
* The path holds the class and namespace information of the specified class.
|
||||
*
|
||||
* @param string $fileName
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function tokenClassFileInfo(string $fileName) : array
|
||||
{
|
||||
$classInfo = [];
|
||||
|
||||
if( ! is_file($fileName) )
|
||||
{
|
||||
return $classInfo;
|
||||
}
|
||||
|
||||
$tokens = self::tokenize(file_get_contents($fileName));
|
||||
$i = 0;
|
||||
$ns = '';
|
||||
|
||||
foreach( $tokens as $token )
|
||||
{
|
||||
if( $token[0] === T_NAMESPACE )
|
||||
{
|
||||
if( isset($tokens[$i + 2][1]) )
|
||||
{
|
||||
if( ! isset($tokens[$i + 3][1]) )
|
||||
{
|
||||
$ns = $tokens[$i + 2][1];
|
||||
}
|
||||
else
|
||||
{
|
||||
$ii = $i;
|
||||
|
||||
while( isset($tokens[$ii + 2][1]) )
|
||||
{
|
||||
$ns .= $tokens[$ii + 2][1];
|
||||
|
||||
$ii++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$classInfo['namespace'] = trim($ns);
|
||||
}
|
||||
|
||||
if
|
||||
(
|
||||
$token[0] === T_CLASS ||
|
||||
$token[0] === T_INTERFACE ||
|
||||
$token[0] === T_TRAIT
|
||||
)
|
||||
{
|
||||
$classInfo['class'] = $tokens[$i + 2][1] ?? NULL;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $classInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* The location captures information from the specified file.
|
||||
*
|
||||
* @param string $fileName
|
||||
* @param int $type = T_FUNCTION
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function tokenFileInfo(string $fileName, int $type = T_FUNCTION)
|
||||
{
|
||||
if( ! is_file($fileName) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$tokens = self::tokenize(file_get_contents($fileName));
|
||||
$info = [];
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach( $tokens as $token )
|
||||
{
|
||||
if( $token[0] === $type )
|
||||
{
|
||||
$info[] = $tokens[$i + 2][1] ?? NULL;
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* spl autoload register
|
||||
*
|
||||
* @param string $type = 'run' - options[run|standart]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function register($type = 'run')
|
||||
{
|
||||
# Autoload register.
|
||||
spl_autoload_register('ZN\Autoloader::' . $type);
|
||||
|
||||
# If the use of alias is obvious, it will activate this operation.
|
||||
self::aliases();
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected is class exists
|
||||
*/
|
||||
protected static function isClassExists($class)
|
||||
{
|
||||
return ! class_exists($class) && ! trait_exists($class) && ! interface_exists($class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected create class map top output.
|
||||
*/
|
||||
protected static function createClassMapTopOutput(&$classMapPage)
|
||||
{
|
||||
if( ! is_file(self::$path) )
|
||||
{
|
||||
$classMapPage = '<?php'.EOL;
|
||||
$classMapPage .= '#----------------------------------------------------------------------'.EOL;
|
||||
$classMapPage .= '# This file automatically created and updated'.EOL;
|
||||
$classMapPage .= '#----------------------------------------------------------------------'.EOL;
|
||||
}
|
||||
else
|
||||
{
|
||||
$classMapPage = '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get classes & namespaces output
|
||||
*/
|
||||
protected static function getClassesAndNamespacesOutput($type, $classMaps, &$classMapPage)
|
||||
{
|
||||
# Get the class and namespace array information from the Project/Any/map.php file
|
||||
$configClassMap = self::getClassMapContent();
|
||||
|
||||
# Getting class paths to print on the class map.
|
||||
# For the concurrent correct class list, information is obtained from
|
||||
# both the configuration file and the $classes variable of this class.
|
||||
$classArray = array_diff_key
|
||||
(
|
||||
$classMaps[$type] ?? [],
|
||||
$configClassMap[$type] ?? []
|
||||
);
|
||||
|
||||
if( ! empty($classArray) )
|
||||
{
|
||||
self::${$type} = $classMaps[$type];
|
||||
|
||||
foreach( $classArray as $k => $v )
|
||||
{
|
||||
$classMapPage .= '$classMap[\''.$type.'\'][\''.$k.'\'] = \''.$v.'\';'.EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected add to class map
|
||||
*
|
||||
* 5.7.4.4[added]
|
||||
*/
|
||||
protected static function addToClassMap($content)
|
||||
{
|
||||
if( ! is_file(self::$path) || (! empty($content) && ! strstr(file_get_contents(self::$path), $content)) )
|
||||
{
|
||||
file_put_contents(self::$path, $content, FILE_APPEND);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the use of alias is obvious, it will activate this operation.
|
||||
*/
|
||||
protected static function aliases()
|
||||
{
|
||||
if( $autoloaderAliases = Config::get('Autoloader')['aliases'] ?? NULL ) foreach( $autoloaderAliases as $alias => $origin )
|
||||
{
|
||||
if( class_exists($origin) )
|
||||
{
|
||||
class_alias($origin, $alias);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Search the invoked class in the classmap.
|
||||
*
|
||||
* @param string $directory
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected static function searchClassMap($directory)
|
||||
{
|
||||
# Keeps a list of classes to be written to the class map.
|
||||
static $classes;
|
||||
|
||||
# Directory path information to start scanning.
|
||||
$directory = Base::suffix($directory);
|
||||
|
||||
# Gets the contents of the class map.
|
||||
$configClassMap = self::getClassMapContent();
|
||||
|
||||
# Gets up the contents of the Settings/Autoloader.php
|
||||
# file which holds the settings for this library.
|
||||
$configAutoloader = Config::get('Autoloader');
|
||||
|
||||
# The list of files contained within the directory is retrieved.
|
||||
$files = glob($directory.'*');
|
||||
|
||||
# The previously recorded class information on the list is eliminated.
|
||||
$files = array_diff
|
||||
(
|
||||
$files,
|
||||
$configClassMap['classes'] ?? []
|
||||
);
|
||||
|
||||
# If the class is found in the scanned list, the class finder is started.
|
||||
if( ! empty($files) ) foreach( $files as $file )
|
||||
{
|
||||
# Continue scanning if the value is a file.
|
||||
if( is_file($file) )
|
||||
{
|
||||
# Class information about the file is retrieved.
|
||||
$classInfo = self::tokenClassFileInfo($file);
|
||||
|
||||
# If the file contains valid class information, scanning continues.
|
||||
if( isset($classInfo['class']) )
|
||||
{
|
||||
# Gets relative file path.
|
||||
$file = self::getRelativeFilePath($file);
|
||||
|
||||
# In the class map, array keys are kept in lower case.
|
||||
$class = strtolower($realOnlyClassName = $classInfo['class']);
|
||||
|
||||
# It is checked whether the scanned class a namespace.
|
||||
# According to this information class name is obtained.
|
||||
if( isset($classInfo['namespace']) )
|
||||
{
|
||||
$className = strtolower($realFullClassName = $classInfo['namespace'] . '\\' . $realOnlyClassName);
|
||||
|
||||
# If the class contains a namespace, it is kept in the namespace array in the class map.
|
||||
# This data is stored in the direct controller of a class that contains a namespace to
|
||||
# provide access to the $this object using only the class name.
|
||||
$classes['namespaces'][self::cleanNailClassMapContent($className)] = self::cleanNailClassMapContent($class);
|
||||
}
|
||||
else
|
||||
{
|
||||
$className = $class;
|
||||
}
|
||||
|
||||
# The name and path information of the scanned class is added to the class map.
|
||||
$classes['classes'][self::cleanNailClassMapContent($className)] = self::cleanNailClassMapContent($file);
|
||||
|
||||
# Creates facade of class.
|
||||
if( ! self::createFacadeClass($file, $realOnlyClassName, $realFullClassName ?? $realOnlyClassName, $classes) )
|
||||
{
|
||||
# If the scanned class has the prefix [Internal],
|
||||
# the static view of this class is created.
|
||||
self::createStaticAccessClass($realOnlyClassName, $file, $configAutoloader['directoryPermission'], $classes);
|
||||
}
|
||||
}
|
||||
}
|
||||
# If the value is an index, resume the scan from that index.
|
||||
# Performs a nested directory scan until the file is found.
|
||||
elseif( is_dir($file) )
|
||||
{
|
||||
self::searchClassMap($file);
|
||||
}
|
||||
}
|
||||
|
||||
return $classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected create facade class
|
||||
*/
|
||||
protected static function createFacadeClass($file, $onlyClassName, $fullClassName, &$classes)
|
||||
{
|
||||
if( in_array('facade', self::tokenFileInfo($file, T_CONST)) && self::isFacadeConstantExistsInFile($file, $match) )
|
||||
{
|
||||
$getFacadeName = $match['name'] === true ? $onlyClassName : $match['name'];
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
if( ! is_file($facadeClassPath = self::getFacadeClassFilePath($file, $onlyClassName)) )
|
||||
{
|
||||
# If constants are used in the scanned class, these constants are taken.
|
||||
$constants = self::findConstantsClassContent($file, ['facade', 'target']);
|
||||
|
||||
# The static view of the scanned class is being created.
|
||||
$getFacadeContent = self::getFacadeContent($getFacadeName , $fullClassName, $constants);
|
||||
|
||||
# Creates facade class.
|
||||
file_put_contents($facadeClassPath, $getFacadeContent);
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
$classes['classes'][strtolower($getFacadeName)] = $facadeClassPath;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get facade class file path
|
||||
*/
|
||||
protected static function getFacadeClassFilePath($file, $onlyClassName)
|
||||
{
|
||||
return Base::removePrefix(pathinfo($file, PATHINFO_DIRNAME) . '/' . $onlyClassName . 'Facade.php', './');
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected is facade constant exists in file
|
||||
*/
|
||||
protected static function isFacadeConstantExistsInFile($file, &$match)
|
||||
{
|
||||
return preg_match('/const\s+(facade)\s+\=\s+(\'|\")(?<name>([A-Z]\w+(\\\\)*){1,})(\'|\");/i', file_get_contents($file), $match);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected create static access class
|
||||
*/
|
||||
protected static function createStaticAccessClass($className, $file, $permission, &$classes)
|
||||
{
|
||||
if( self::isInternalClassExists($className) )
|
||||
{
|
||||
# If the directory in which static views are to be created does not exist,
|
||||
# it will be rebuilt.
|
||||
self::createStaticsDirectoryIfNotExists($directoryPermission = $permission ?? 0755);
|
||||
|
||||
# The static view creates a new directory with the same name into
|
||||
# the Resources Statics/ directory according to the location of the original class.
|
||||
self::createStaticClassDirectoryIfNotExists($staticClassDirectory = self::getStaticClassDirectoryFromFile($file), $directoryPermission);
|
||||
|
||||
# The static view of the scanned class is being created.
|
||||
$classContent = self::createClassFileContent($originClassName = self::getOriginalClassName($className), self::findConstantsClassContent($file));
|
||||
|
||||
# If a previously rendered static view of the scanned class has been created,
|
||||
# it is checked for changes in appearance before this static view is reconstructed.
|
||||
if( $classContent != self::getStaticAccessFileContent($staticClassPath = self::getStaticClassFile($staticClassDirectory, $className)) )
|
||||
{
|
||||
# If the data do not match, recreate it.
|
||||
file_put_contents($staticClassPath, $classContent);
|
||||
}
|
||||
|
||||
# Add the class to the class map.
|
||||
$classes['classes'][strtolower($originClassName)] = $staticClassPath;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected is internal class exists
|
||||
*/
|
||||
protected static function isInternalClassExists($className)
|
||||
{
|
||||
return stripos($className, INTERNAL_ACCESS) === 0 && ! preg_match('/(Interface|Trait)$/i', $className);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get static class file
|
||||
*/
|
||||
protected static function getStaticClassFile($staticClassDirectory, $className)
|
||||
{
|
||||
return Base::suffix($staticClassDirectory) . $className . '.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get static class directory from file
|
||||
*/
|
||||
protected static function getStaticClassDirectoryFromFile($file)
|
||||
{
|
||||
return self::$staticAccessDirectory . pathinfo($file, PATHINFO_DIRNAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get original class name
|
||||
*/
|
||||
protected static function getOriginalClassName($className)
|
||||
{
|
||||
return str_ireplace(INTERNAL_ACCESS, '', $className ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected create static class directory if not exists
|
||||
*/
|
||||
protected static function createStaticClassDirectoryIfNotExists($staticClassDirectory, $directoryPermission)
|
||||
{
|
||||
if( ! is_dir($staticClassDirectory) )
|
||||
{
|
||||
mkdir($staticClassDirectory, $directoryPermission, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected create statics directory if not exists
|
||||
*/
|
||||
protected static function createStaticsDirectoryIfNotExists($directoryPermission)
|
||||
{
|
||||
if( ! is_dir(self::$staticAccessDirectory) )
|
||||
{
|
||||
# Created Resources/Statics/ directory.
|
||||
mkdir(self::$staticAccessDirectory, $directoryPermission, true); // @codeCoverageIgnore
|
||||
|
||||
# Access to this directory via URL is blocked.
|
||||
# It is assumed that the system is running on apache.
|
||||
file_put_contents(self::$staticAccessDirectory . '.htaccess', 'Deny from all'); // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get static access file content
|
||||
*/
|
||||
protected static function getStaticAccessFileContent($staticClassPath)
|
||||
{
|
||||
return is_file($staticClassPath) ? file_get_contents($staticClassPath) : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* It finds constants in the class.
|
||||
*
|
||||
* @param string $v
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function findConstantsClassContent($v, $exclude = [])
|
||||
{
|
||||
$getFileContent = file_get_contents($v);
|
||||
|
||||
# If the classes in which the static view will be created contain constants,
|
||||
# these constants are built into the static view.
|
||||
preg_match_all('/const\s+(\w+)\s+\=\s+(.*?);/i', $getFileContent, $match);
|
||||
|
||||
$const = $match[1] ?? [];
|
||||
$value = $match[2] ?? [];
|
||||
|
||||
$constants = '';
|
||||
|
||||
if( ! empty($const) )
|
||||
{
|
||||
foreach( $const as $key => $c )
|
||||
{
|
||||
if( ! in_array($c, $exclude) )
|
||||
{
|
||||
$constants .= HT."const ".$c.' = '.$value[$key].';'.EOL.EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $constants;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates internal class content.
|
||||
*
|
||||
* @param string $newClassName
|
||||
* @param string $constants
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function createClassFileContent($newClassName, $constants)
|
||||
{
|
||||
# Static view of classes with prefix 'Internal'.
|
||||
# Static views are built into the Resources/Statics/ directory.
|
||||
$classContent = '<?php'.EOL;
|
||||
$classContent .= '#-------------------------------------------------------------------------'.EOL;
|
||||
$classContent .= '# This file automatically created and updated'.EOL;
|
||||
$classContent .= '#-------------------------------------------------------------------------'.EOL.EOL;
|
||||
$classContent .= 'class '.$newClassName.' extends ZN\StaticAccess'.EOL;
|
||||
$classContent .= '{'.EOL;
|
||||
$classContent .= $constants;
|
||||
$classContent .= HT.'public static function getClassName()'.EOL;
|
||||
$classContent .= HT.'{'.EOL;
|
||||
$classContent .= HT.HT.'return __CLASS__;'.EOL;
|
||||
$classContent .= HT.'}'.EOL;
|
||||
$classContent .= '}'.EOL.EOL;
|
||||
$classContent .= '#-------------------------------------------------------------------------';
|
||||
|
||||
return $classContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates internal class content.
|
||||
*
|
||||
* @param string $newClassName
|
||||
* @param string $constants
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getFacadeContent($facade, $target, $constants)
|
||||
{
|
||||
self::getClassNamespace($facade, $namespace);
|
||||
|
||||
$classContent = '<?php' . $namespace . EOL;
|
||||
$classContent .= '#-------------------------------------------------------------------------'.EOL;
|
||||
$classContent .= '# This file automatically created and updated'.EOL;
|
||||
$classContent .= '#-------------------------------------------------------------------------'.EOL.EOL;
|
||||
$classContent .= 'class '.$facade.EOL;
|
||||
$classContent .= '{'.EOL;
|
||||
$classContent .= $constants;
|
||||
$classContent .= HT.'use \ZN\Ability\Facade;'.EOL.EOL;
|
||||
$classContent .= HT.'const target = \'' . $target . '\';'.EOL;
|
||||
$classContent .= '}'.EOL.EOL;
|
||||
$classContent .= '#-------------------------------------------------------------------------';
|
||||
|
||||
return $classContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get class namespace
|
||||
*/
|
||||
protected static function getClassNamespace(&$facade, &$namespace)
|
||||
{
|
||||
$namespace = '';
|
||||
$facadeEx = explode('\\', $facade);
|
||||
|
||||
if( count($facadeEx) > 1 )
|
||||
{
|
||||
$facade = $facadeEx[count($facadeEx) - 1];
|
||||
|
||||
array_pop($facadeEx);
|
||||
|
||||
$namespace = ' namespace ' . implode('\\', $facadeEx) . ';';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get config
|
||||
*
|
||||
* @param void
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private static function getClassMapContent()
|
||||
{
|
||||
# Some server configuration bugs may lead to erroneous writing to the class map.
|
||||
# If a code error is detected in the possible class map, the class map is rebuilt.
|
||||
# Thus, system operation is never interrupted.
|
||||
if( is_file(self::$path) )
|
||||
{
|
||||
global $classMap;
|
||||
|
||||
# 5.4.61[added]
|
||||
try
|
||||
{
|
||||
require_once self::$path;
|
||||
}
|
||||
// @codeCoverageIgnoreStart
|
||||
catch( \Throwable $e )
|
||||
{
|
||||
self::restart();
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return $classMap;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* It attempts to construct the class map.
|
||||
*
|
||||
* @param string $class
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function tryAgainCreateClassMap($class)
|
||||
{
|
||||
# The class map is being rebuilt.
|
||||
self::createClassMap();
|
||||
|
||||
# Getting class information.
|
||||
$classInfo = self::getClassFileInfo($class);
|
||||
|
||||
# The file location of the class is being obtained.
|
||||
$file = $classInfo['path'];
|
||||
|
||||
# If the file location is correct, the class is included.
|
||||
if( is_file($file) )
|
||||
{
|
||||
require $file;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get realative file path
|
||||
*/
|
||||
protected static function getRelativeFilePath($file)
|
||||
{
|
||||
return str_replace(REAL_BASE_DIR, '', $file ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean nail
|
||||
*
|
||||
* @param string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function cleanNailClassMapContent($string)
|
||||
{
|
||||
# If the class or namespace information contains quotes, these quotes are cleared.
|
||||
return str_replace(["'", '"'], '', $string ?? '');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,362 @@
|
||||
<?php namespace ZN;
|
||||
/**
|
||||
* 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 Base
|
||||
{
|
||||
/**
|
||||
* Is resource or object
|
||||
*
|
||||
* @param resource|object $object;
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isResourceObject($object)
|
||||
{
|
||||
if( IS::phpVersion('8') )
|
||||
{
|
||||
return is_object($object); // @codeCoverageIgnore
|
||||
}
|
||||
else
|
||||
{
|
||||
return is_resource($object);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default project or host name.
|
||||
*
|
||||
* @param string $default = 'Frontend'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function project($default = 'Frontend')
|
||||
{
|
||||
$host = self::host();
|
||||
|
||||
return ! empty($host) && is_dir(PROJECTS_DIR . $host) ? $host : $default;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get path info
|
||||
*
|
||||
* @return string|false
|
||||
*/
|
||||
public static function currentPath()
|
||||
{
|
||||
return $_SERVER['PATH_INFO'] ?? $_SERVER['QUERY_STRING'] ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* illustrate
|
||||
*
|
||||
* Returns the constant value. If the constant is undefined,
|
||||
* it defines the constant according to
|
||||
* the specified value and returns the value.
|
||||
*
|
||||
* @param string $const
|
||||
* @param mixed $value = ''
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function illustrate(string $const, $value = '')
|
||||
{
|
||||
if( ! defined($const) )
|
||||
{
|
||||
define($const, $value);
|
||||
}
|
||||
else
|
||||
{
|
||||
if( $value !== '' )
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
return constant($const);
|
||||
}
|
||||
|
||||
/**
|
||||
* import
|
||||
*
|
||||
* Include files once. Performance is better than require_once function.
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function import(string $file)
|
||||
{
|
||||
$constant = 'ImportFilePrefix' . $file;
|
||||
|
||||
if( ! defined($constant) )
|
||||
{
|
||||
define($constant, true);
|
||||
|
||||
if( is_file($file) )
|
||||
{
|
||||
return require self::prefix($file, REAL_BASE_DIR);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* host
|
||||
*
|
||||
* Returns the system host information.
|
||||
*
|
||||
* @param void
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function host() : string
|
||||
{
|
||||
if( isset($_SERVER['HTTP_X_FORWARDED_HOST']) )
|
||||
{
|
||||
$host = $_SERVER['HTTP_X_FORWARDED_HOST'];
|
||||
$elements = explode(',', $host);
|
||||
$host = trim(end($elements));
|
||||
}
|
||||
else
|
||||
{
|
||||
$host = $_SERVER['HTTP_HOST'] ??
|
||||
$_SERVER['SERVER_NAME'] ??
|
||||
$_SERVER['SERVER_ADDR'] ??
|
||||
'';
|
||||
}
|
||||
|
||||
$host = trim($host);
|
||||
|
||||
if( defined('IS_MAIN_DOMAIN') )
|
||||
{
|
||||
$host = self::prefix($host, 'www.');
|
||||
}
|
||||
|
||||
return $host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an expression in begin of a string.,
|
||||
*
|
||||
* @param string $data
|
||||
* @param string $fix = '/'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function removePrefix(?string $data = NULL, string $fix = '/') : string
|
||||
{
|
||||
$data = $data ?? '';
|
||||
|
||||
if( strpos($data, $fix) === 0 )
|
||||
{
|
||||
$data = substr($data, strlen($fix));
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an expression in begin of a string.,
|
||||
*
|
||||
* @param string $data
|
||||
* @param string $fix = '/'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function removeSuffix(?string $data = NULL, string $fix = '/') : string
|
||||
{
|
||||
$data = $data ?? '';
|
||||
|
||||
if( strrpos($data, $fix) === ($start = strlen($data) - strlen($fix)) )
|
||||
{
|
||||
$data = substr($data, 0, $start);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* It removes an expression from both sides of a string.
|
||||
*
|
||||
* @param string $data
|
||||
* @param string $fix = '/'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function removePresuffix(?string $data = NULL, string $fix = '/') : string
|
||||
{
|
||||
return self::removeSuffix(self::removePrefix($data, $fix), $fix);
|
||||
}
|
||||
|
||||
/**
|
||||
* suffix
|
||||
*
|
||||
* It is used to append a suffix to any string.
|
||||
*
|
||||
* @param string = NULL
|
||||
* @param string = $fix = '/'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function suffix(?string $string = NULL, string $fix = '/') : string
|
||||
{
|
||||
return self::prefix($string, $fix, __FUNCTION__);
|
||||
}
|
||||
|
||||
/**
|
||||
* prefix
|
||||
*
|
||||
* It is used to append a prefix to any string.
|
||||
*
|
||||
* @param string = NULL
|
||||
* @param string = $fix = '/'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function prefix(?string $string = NULL, string $fix = '/', $type = __FUNCTION__) : string
|
||||
{
|
||||
$string = $string ?? '';
|
||||
|
||||
$stringFix = $type === 'prefix' ? $fix . $string : $string . $fix;
|
||||
|
||||
if( strlen($fix) <= strlen($string) )
|
||||
{
|
||||
$prefix = $type === 'prefix' ? substr($string, 0, strlen($fix)) : substr($string, -strlen($fix));
|
||||
|
||||
if( $prefix !== $fix )
|
||||
{
|
||||
$string = $stringFix;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$string = $stringFix;
|
||||
}
|
||||
|
||||
if( $string === $fix )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* prefix
|
||||
*
|
||||
* Used to append both suffixes and prefixes to any string.
|
||||
*
|
||||
* @param string = NULL
|
||||
* @param string = $fix = '/'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function presuffix(?string $string = NULL, string $fix = '/') : string
|
||||
{
|
||||
return self::suffix(self::prefix(empty($string) ? $fix . $string . $fix : $string, $fix), $fix);
|
||||
}
|
||||
|
||||
/**
|
||||
* headers
|
||||
*
|
||||
* Send HTTP headers in singular or plural structure.
|
||||
*
|
||||
* @param mixed $header
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function headers($header)
|
||||
{
|
||||
if( ! is_array($header) )
|
||||
{
|
||||
header($header);
|
||||
}
|
||||
else
|
||||
{
|
||||
if( ! empty($header) ) foreach( $header as $k => $v )
|
||||
{
|
||||
header($v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* trace
|
||||
*
|
||||
* Produces formatted output that terminates the operation.
|
||||
*
|
||||
* @param string $message
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function trace(string $message, $exit = true, $consoleEnabled = true)
|
||||
{
|
||||
# Shows console trace
|
||||
if( $consoleEnabled && defined('CONSOLE_ENABLED') )
|
||||
{
|
||||
self::consoleTrace('CONSOLE TRACE', $message, $exit);
|
||||
}
|
||||
|
||||
$style = 'border:solid 1px #E1E4E5;';
|
||||
$style .= 'background:#FEFEFE;';
|
||||
$style .= 'padding:10px;';
|
||||
$style .= 'margin-bottom:10px;';
|
||||
$style .= 'font-family:Calibri, Ebrima, Century Gothic, Consolas, Courier New, Courier, monospace, Tahoma, Arial;';
|
||||
$style .= 'color:#666;';
|
||||
$style .= 'text-align:left;';
|
||||
$style .= 'font-size:14px;';
|
||||
|
||||
$message = preg_replace('/\[(.*?)\]/', '<span style="color:#990000;">$1</span>', $message);
|
||||
|
||||
$str = "<div style=\"$style\">";
|
||||
$str .= $message;
|
||||
$str .= '</div>';
|
||||
|
||||
if( $exit === true && ! defined('ZN_REDIRECT_NOEXIT') )
|
||||
{
|
||||
exit($str); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Console trace
|
||||
*
|
||||
* @param string $title
|
||||
* @param string $message
|
||||
*/
|
||||
public static function consoleTrace(string $title, string $message, $exit = true)
|
||||
{
|
||||
$repeat = self::presuffix(str_repeat('-', strlen($message) + 2), '+');
|
||||
|
||||
$spaceRepeatCount = strlen($message) - strlen($title);
|
||||
|
||||
$spaceRepeat = $spaceRepeatCount > 0 ? $spaceRepeatCount : 0;
|
||||
|
||||
$titleSpaceRepeat = str_repeat(' ', $spaceRepeat);
|
||||
|
||||
$output = $repeat . CRLF;
|
||||
$output .= '| '.$title . $titleSpaceRepeat .' |' . CRLF;
|
||||
$output .= $repeat . CRLF;
|
||||
$output .= '| ' . $message . ' |' . CRLF;
|
||||
$output .= $repeat;
|
||||
|
||||
if( $exit === true && ! defined('ZN_REDIRECT_NOEXIT') )
|
||||
{
|
||||
exit($output); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php namespace ZN;
|
||||
/**
|
||||
* 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\InvalidArgumentException;
|
||||
|
||||
class Buffering
|
||||
{
|
||||
/**
|
||||
* OB start.
|
||||
*/
|
||||
public static function start()
|
||||
{
|
||||
if( (HTACCESS_CONFIG['cache']['obGzhandler'] ?? true) === true && substr_count($_SERVER['HTTP_ACCEPT_ENCODING'] ?? '', 'gzip') )
|
||||
{
|
||||
ob_start('ob_gzhandler');
|
||||
}
|
||||
else
|
||||
{
|
||||
ob_start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* OB end flush;
|
||||
*/
|
||||
public static function end()
|
||||
{
|
||||
ob_end_flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Buffer code
|
||||
*
|
||||
* @param string $randomBufferClassCallbackCode
|
||||
* @param array $randomBufferClassCallbackData
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function code(string $randomBufferClassCallbackCode, ?array $randomBufferClassCallbackData = NULL)
|
||||
{
|
||||
if( is_array($randomBufferClassCallbackData) )
|
||||
{
|
||||
extract($randomBufferClassCallbackData, EXTR_OVERWRITE, 'ZN');
|
||||
}
|
||||
|
||||
ob_start();
|
||||
|
||||
eval('?>' . $randomBufferClassCallbackCode);
|
||||
|
||||
$randomBufferClassCallbackContents = ob_get_contents();
|
||||
|
||||
ob_end_clean();
|
||||
|
||||
return $randomBufferClassCallbackContents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Buffer file
|
||||
*
|
||||
* @param string $randomBufferClassPagePath
|
||||
* @param array $randomBufferClassDataVariable
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function file(string $randomBufferClassPagePath, ?array $randomBufferClassDataVariable = NULL) : string
|
||||
{
|
||||
if( ! is_file($randomBufferClassPagePath) )
|
||||
{
|
||||
throw new InvalidArgumentException('Error', 'fileParameter', '1.($file)');
|
||||
}
|
||||
|
||||
if( is_array($randomBufferClassDataVariable) )
|
||||
{
|
||||
extract($randomBufferClassDataVariable, EXTR_OVERWRITE, 'ZN');
|
||||
}
|
||||
|
||||
ob_start();
|
||||
|
||||
require $randomBufferClassPagePath;
|
||||
|
||||
$randomBufferClassPageContents = ob_get_contents();
|
||||
|
||||
ob_end_clean();
|
||||
|
||||
return $randomBufferClassPageContents;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,968 @@
|
||||
<?php namespace ZN;
|
||||
|
||||
class Butcher
|
||||
{
|
||||
/**
|
||||
* Protected default project file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $defaultProjectFile = EXTERNAL_FILES_DIR . 'DefaultProject.zip';
|
||||
|
||||
/**
|
||||
* Protected theme directory
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $themeDirectory = 'Default';
|
||||
|
||||
/**
|
||||
* Protected location
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $location = 'project';
|
||||
|
||||
/**
|
||||
* Protected fint base theme directory
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $findBaseThemeDirectory = BUTCHERY_DIR;
|
||||
|
||||
/**
|
||||
* Protected current butchery directory
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $currentButcheryDirectory;
|
||||
|
||||
/**
|
||||
* Protected application
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $application;
|
||||
|
||||
/**
|
||||
* Protected lang
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $lang;
|
||||
|
||||
/**
|
||||
* Protected inc
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $inc = 0;
|
||||
|
||||
/**
|
||||
* Protected body parser
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $bodyParser = [];
|
||||
|
||||
/**
|
||||
* Protected multiple
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $multiple = NULL;
|
||||
|
||||
/**
|
||||
* Protected supported file extensions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $supportedFileExtensions = ['html', 'htm', 'php'];
|
||||
|
||||
/**
|
||||
* Keeps extract delete
|
||||
*/
|
||||
protected $extractDelete;
|
||||
|
||||
/**
|
||||
* Magic constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->lang = Lang::default('ZN\CoreDefaultLanguage')::select('Core');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets default project file.
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function defaultProjectFile(string $path)
|
||||
{
|
||||
$this->defaultProjectFile = Base::suffix($path, '.zip');
|
||||
|
||||
if( ! file_exists($this->defaultProjectFile) )
|
||||
{
|
||||
throw new Exception\FileNotFoundException($this->defaultProjectFile);
|
||||
}
|
||||
|
||||
return $this; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets default project file.
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function location(string $location)
|
||||
{
|
||||
if( ! in_array($location, ['project', 'external']) )
|
||||
{
|
||||
throw new Exception\InvalidLocationException;
|
||||
}
|
||||
|
||||
$this->location = $this->location;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects project. Only with run and runDelete methods work.
|
||||
*
|
||||
* @param string $application
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function application(string $application)
|
||||
{
|
||||
$this->application = $application;
|
||||
$this->currentButcheryDirectory = PROJECTS_DIR . $application . '/Butchery/';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract themes.
|
||||
*
|
||||
* @param string $which = 'all' - options[all|{name}]
|
||||
* @param string $case = 'title' - options[title|lower|slug|normal|{name}]
|
||||
* @param string $location = 'project' - options[project|external]
|
||||
* @param bool $force = false - options[true|false]
|
||||
*/
|
||||
public function extract(string $which = 'all', string $case = 'title', string $location = 'project', bool $force = false)
|
||||
{
|
||||
$this->openZipFiles(EXTERNAL_BUTCHERY_DIR, true);
|
||||
|
||||
if( $which === 'all' )
|
||||
{
|
||||
$themes = Filesystem::getFiles(EXTERNAL_BUTCHERY_DIR, ['dir']);
|
||||
|
||||
if( empty($themes) )
|
||||
{
|
||||
return $this->getLangValue('notFoundExternalButcheryThemes');
|
||||
}
|
||||
|
||||
foreach( $themes as $theme )
|
||||
{
|
||||
$this->runProjectExtract($theme, $case, $force, $location);
|
||||
}
|
||||
|
||||
return $this->getLangValue('extractThemeSuccess');
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->runProjectExtract($which, $case, $force, $location);
|
||||
}
|
||||
|
||||
return $this->getLangValue('cantExtractTheme');
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract themes.
|
||||
*
|
||||
* @param string $which = 'all' - options[all|{name}]
|
||||
* @param string $case = 'title' - options[title|lower|slug|normal|{name}]
|
||||
* @param string $location = 'project' - options[project|external]
|
||||
*/
|
||||
public function extractForce(string $which = 'all', string $case = 'title', string $location = 'project')
|
||||
{
|
||||
return $this->extract($which, $case, $location, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract themes.
|
||||
*
|
||||
* @param string $which = 'all' - options[all|{name}]
|
||||
* @param string $case = 'title' - options[title|lower|slug|normal|{name}]
|
||||
* @param string $location = 'project' - options[project|external]
|
||||
*/
|
||||
public function extractDelete(string $which = 'all', string $case = 'title', string $location = 'project')
|
||||
{
|
||||
$this->extractDelete = true;
|
||||
|
||||
return $this->extract($which, $case, $location, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run
|
||||
*
|
||||
* @param string $theme = 'Default' - options[{name}|multiple]
|
||||
* @param string $location = 'project' - options[project|external]
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
public function run(string $theme = 'Default', string $location = 'project')
|
||||
{
|
||||
if( $location === 'external' )
|
||||
{
|
||||
$this->location = $location;
|
||||
}
|
||||
|
||||
if( $theme === 'multiple' )
|
||||
{
|
||||
$this->openZipFiles($this->getCurrentProjectButcheryDirectory());
|
||||
|
||||
if( $directories = Filesystem::getFiles($this->getCurrentProjectButcheryDirectory(), 'dir') )
|
||||
{
|
||||
foreach( $directories as $directory )
|
||||
{
|
||||
$this->themeDirectory = $this->projectDirectoryCase($directory, 'title');
|
||||
|
||||
$this->multiple = $directory . '/';
|
||||
|
||||
$this->singleRun();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->getLangValue('cantMultipleExtractTheme', $this->getCurrentProjectButcheryDirectory());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->themeDirectory = $theme;
|
||||
|
||||
$this->singleRun();
|
||||
}
|
||||
|
||||
return $this->getLangValue('extractThemeSuccess');
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get lang value
|
||||
*/
|
||||
protected function getLangValue($key, $string = NULL)
|
||||
{
|
||||
return str_replace('%', $string ?? '', $this->lang['butcher:' . $key] ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get current project butchery directory
|
||||
*/
|
||||
protected function getCurrentProjectButcheryDirectory()
|
||||
{
|
||||
return ($this->currentButcheryDirectory ?? BUTCHERY_DIR) . $this->multiple;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected single run.
|
||||
*/
|
||||
protected function singleRun()
|
||||
{
|
||||
$this->findHTMLFiles($this->getCurrentProjectButcheryDirectory());
|
||||
$this->generateControllers();
|
||||
$this->moveAssetsToThemeDirectory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run Delete
|
||||
*
|
||||
* @param string $theme = 'Default'
|
||||
* @param string $location = 'project' - options[project|external]
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
public function runDelete(string $theme = 'Default', string $location = 'project')
|
||||
{
|
||||
$return = $this->run($theme, $location);
|
||||
|
||||
Filesystem::deleteFolder($this->getCurrentProjectButcheryDirectory());
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get theme directory name
|
||||
*/
|
||||
protected function getThemeDirectoryName()
|
||||
{
|
||||
return $this->themeDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected route config
|
||||
*/
|
||||
protected function routeConfig()
|
||||
{
|
||||
return $this->getApplicationConfig('Routing') ?: ['openController' => 'Home', 'openFunction' => 'main'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected run project extract
|
||||
*/
|
||||
protected function runProjectExtract($theme, $case, $force, $location)
|
||||
{
|
||||
$this->currentButcheryDirectory = EXTERNAL_BUTCHERY_DIR . $theme . '/';
|
||||
|
||||
$project = $this->projectDirectoryCase($theme, $case);
|
||||
|
||||
if( $this->generateProject($project, $force) )
|
||||
{
|
||||
$this->application = $project;
|
||||
|
||||
$this->run($project, $location);
|
||||
|
||||
if( $this->extractDelete ?? NULL )
|
||||
{
|
||||
Filesystem::deleteFolder($this->currentButcheryDirectory);
|
||||
}
|
||||
|
||||
return $this->getLangValue('extractThemeSuccess');
|
||||
}
|
||||
|
||||
return $this->getLangValue('cantExtractTheme'); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected generate project
|
||||
*/
|
||||
protected function generateProject($project, $force)
|
||||
{
|
||||
$source = $this->defaultProjectFile;
|
||||
$target = PROJECTS_DIR . $project;
|
||||
|
||||
if( $force === true )
|
||||
{
|
||||
Filesystem::zipExtract($source, $target);
|
||||
|
||||
return true;
|
||||
}
|
||||
// @codeCoverageIgnoreStart
|
||||
elseif( ! file_exists($target) )
|
||||
{
|
||||
Filesystem::zipExtract($source, $target);
|
||||
|
||||
return true;
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return false; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected project directory case
|
||||
*/
|
||||
protected function projectDirectoryCase($directory, $case)
|
||||
{
|
||||
if( $case === 'normal' )
|
||||
{
|
||||
return $directory; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$directory = str_replace([' ', '_'], '-', $directory ?? '');
|
||||
|
||||
switch( $case )
|
||||
{
|
||||
case 'slug' : return strtolower($directory);
|
||||
case 'title':
|
||||
case 'lower': return $this->mbConvertCase($directory, $case);
|
||||
default :
|
||||
{
|
||||
$case = explode(':', $case); $type = $case[1] ?? '';
|
||||
$name = $case[0];
|
||||
|
||||
if( strpos($type, 'inc') === 0 )
|
||||
{
|
||||
return $this->setIncrementCase($name, $type);
|
||||
}
|
||||
elseif( strpos($type, 'rand') === 0 )
|
||||
{
|
||||
return $this->randCase($name, $type);
|
||||
}
|
||||
|
||||
return $this->incrementCase($name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected set increment case
|
||||
*/
|
||||
protected function setIncrementCase($case, $type)
|
||||
{
|
||||
if( preg_match('/inc\[(?<increment>[0-9]+)\]/', $type, $match) )
|
||||
{
|
||||
if( $this->inc === 0 )
|
||||
{
|
||||
$this->inc = $match['increment'] ?? 0;
|
||||
}
|
||||
|
||||
return $case . $this->inc++;
|
||||
}
|
||||
|
||||
return $this->incrementCase($case); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected rand case
|
||||
*/
|
||||
protected function randCase($case, $type)
|
||||
{
|
||||
if( preg_match('/rand\[(?<min>[0-9]+)\s*\,\s*(?<max>[0-9]+)\]/', $type, $match) )
|
||||
{
|
||||
return $case . rand($match['min'] ?? 0, $match['max'] ?? 0);
|
||||
}
|
||||
|
||||
return $this->incrementCase($case); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected increment case
|
||||
*/
|
||||
protected function incrementCase($case)
|
||||
{
|
||||
static $start = 0;
|
||||
|
||||
$fix = $start === 0 ? NULL : $start;
|
||||
|
||||
$start++;
|
||||
|
||||
return $case . $fix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected MB convert case
|
||||
*/
|
||||
protected function mbConvertCase($string, $type)
|
||||
{
|
||||
return str_replace(' ', '', mb_convert_case(str_replace('-', ' ', $string ?? ''), Helper::toConstant($type, 'MB_CASE_')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get HTML files
|
||||
*/
|
||||
protected function getHTMLFiles()
|
||||
{
|
||||
return Filesystem::getFiles($this->findBaseThemeDirectory, $this->supportedFileExtensions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get other theme files
|
||||
*/
|
||||
protected function getOtherThemeFiles()
|
||||
{
|
||||
return Filesystem::getFiles($this->findBaseThemeDirectory, ['dir', 'css', 'js']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get zip files
|
||||
*/
|
||||
public function openZipFiles($directory, $path = false)
|
||||
{
|
||||
$zipFiles = Filesystem::getFiles($directory, 'zip');
|
||||
|
||||
if( is_array($zipFiles) && ! empty($zipFiles) ) foreach( $zipFiles as $zip )
|
||||
{
|
||||
$target = $directory . rtrim($zip, '.zip');
|
||||
|
||||
Filesystem::zipExtract($directory . $zip, $target, $path);
|
||||
|
||||
if( $this->extractDelete ?? NULL )
|
||||
{
|
||||
Filesystem::deleteFolder($directory . $zip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected find HTML Files
|
||||
*/
|
||||
protected function findHTMLFiles($directory = BUTCHERY_DIR)
|
||||
{
|
||||
$getHTMLFiles = Filesystem::getFiles($directory, $this->supportedFileExtensions);
|
||||
|
||||
if( ! $getHTMLFiles )
|
||||
{
|
||||
$this->openZipFiles($directory);
|
||||
|
||||
$getThemeDirectories = Filesystem::getFiles($directory, 'dir');
|
||||
|
||||
foreach( $getThemeDirectories as $dir )
|
||||
{
|
||||
$this->findHTMLFiles($directory . Base::suffix($dir));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->findBaseThemeDirectory = $directory;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get project theme directory
|
||||
*/
|
||||
protected function getProjectThemeDirectory()
|
||||
{
|
||||
return $this->themesDirectory() . $this->getThemeDirectoryName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected move assets to theme directory
|
||||
*/
|
||||
protected function moveAssetsToThemeDirectory()
|
||||
{
|
||||
$getAssets = $this->getOtherThemeFiles();
|
||||
|
||||
$this->cleanProjectThemeDirectory();
|
||||
|
||||
if( is_array($getAssets) ) foreach( $getAssets as $file )
|
||||
{
|
||||
$this->moveAssets($file);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected clean project theme directory
|
||||
*/
|
||||
protected function cleanProjectThemeDirectory()
|
||||
{
|
||||
if( file_exists($getProjectThemeDirectory = $this->getProjectThemeDirectory()) )
|
||||
{
|
||||
Filesystem::deleteFolder($getProjectThemeDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected move assets
|
||||
*/
|
||||
protected function moveAssets($path)
|
||||
{
|
||||
$assetsBaseDirectory = $this->findBaseThemeDirectory . $path;
|
||||
|
||||
Filesystem::copy($assetsBaseDirectory, $this->getThemePath($path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get theme path
|
||||
*/
|
||||
protected function getThemePath($directory = NULL)
|
||||
{
|
||||
return $this->getProjectThemeDirectory() . (Base::prefix($directory));
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected clean cache
|
||||
*/
|
||||
protected function cleanCache($path)
|
||||
{
|
||||
clearstatcache(true, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected generate controllers
|
||||
*/
|
||||
protected function generateControllers()
|
||||
{
|
||||
$htmlFiles = $this->getHTMLFiles();
|
||||
|
||||
$this->writeInitializeController();
|
||||
|
||||
if( is_array($htmlFiles) )
|
||||
{
|
||||
foreach( $htmlFiles as $file )
|
||||
{
|
||||
$controller = $this->convertValidControllerName($file);
|
||||
|
||||
$this->deletePreviousController($controller);
|
||||
|
||||
$this->generator()->controller($controller,
|
||||
[
|
||||
'application' => $this->application ?? DEFINED_CURRENT_PROJECT,
|
||||
'namespace' => $this->getControllerNamespace(),
|
||||
'functions' => [$this->routeConfig()['openFunction']],
|
||||
'extends' => 'Controller'
|
||||
]);
|
||||
|
||||
$this->generateView($controller, $file);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected convert valid controller name
|
||||
*/
|
||||
protected function convertValidControllerName($controller)
|
||||
{
|
||||
return $this->cleanNumericPrefix
|
||||
(
|
||||
$this->titleCase
|
||||
(
|
||||
$this->convertControllerName
|
||||
(
|
||||
$this->removeExtension($controller)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected convert slug separator
|
||||
*/
|
||||
protected function convertSlugSeparator($string)
|
||||
{
|
||||
return str_replace([' ', '_', '.'], '-', $string ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected clean numeric prefix
|
||||
*/
|
||||
protected function cleanNumericPrefix($string)
|
||||
{
|
||||
return preg_replace('/^[0-9]+/', '', $string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected add slashes to at
|
||||
*/
|
||||
protected function addSlashesToAt($string)
|
||||
{
|
||||
return str_replace('@', '/@', $string ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected views directory
|
||||
*/
|
||||
protected function viewsDirectory($type = 'Views', $dir = VIEWS_DIR)
|
||||
{
|
||||
if( $this->application !== NULL )
|
||||
{
|
||||
$return = PROJECTS_DIR . $this->application . '/'.$type .'/';
|
||||
}
|
||||
else
|
||||
{
|
||||
$return = $dir;
|
||||
}
|
||||
|
||||
if( ! file_exists($return) && $dir !== CONFIG_DIR )
|
||||
{
|
||||
Filesystem::createFolder($return); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected controllers directory
|
||||
*/
|
||||
protected function controllersDirectory()
|
||||
{
|
||||
return $this->viewsDirectory('Controllers', CONTROLLERS_DIR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected controllers directory
|
||||
*/
|
||||
protected function getApplicationConfig($file)
|
||||
{
|
||||
$configFile = $this->viewsDirectory('Config', CONFIG_DIR) . $file . '.php';
|
||||
|
||||
if( file_exists($configFile) )
|
||||
{
|
||||
return require $configFile;
|
||||
}
|
||||
|
||||
return []; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected themes directory
|
||||
*/
|
||||
protected function themesDirectory()
|
||||
{
|
||||
if( $this->location === 'project' )
|
||||
{
|
||||
if( $this->application !== NULL )
|
||||
{
|
||||
$return = PROJECTS_DIR . $this->application . '/Resources/Themes/'; // @codeCoverageIgnore
|
||||
}
|
||||
else
|
||||
{
|
||||
$return = THEMES_DIR;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return EXTERNAL_THEMES_DIR;
|
||||
}
|
||||
|
||||
if( ! file_exists($return) )
|
||||
{
|
||||
Filesystem::createFolder($return); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected multiple theme directory
|
||||
*/
|
||||
protected function getMultipleThemeDirectory()
|
||||
{
|
||||
return ($this->multiple ? $this->getThemeDirectoryName() . '/' : NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected generate view
|
||||
*/
|
||||
protected function generateView($controller, $file)
|
||||
{
|
||||
$file = $this->findBaseThemeDirectory . $file;
|
||||
|
||||
$viewDirectory = ($viewThemeDirectory = $this->viewsDirectory() . $this->getMultipleThemeDirectory()) . $controller . '/';
|
||||
|
||||
Filesystem::createFolder($viewDirectory);
|
||||
|
||||
$content = file_get_contents($file);
|
||||
|
||||
preg_match('/<head.*?>(?<head>.*?)<\/head>.*?<body.*?>(?<body>.*?)<\/body>/is', $content, $match);
|
||||
|
||||
$head = $match['head'] ?? false;
|
||||
$body = $match['body'] ?? false;
|
||||
|
||||
if( $body !== false )
|
||||
{
|
||||
$mainFile = $viewDirectory . $this->routeConfig()['openFunction'].'.wizard.php';
|
||||
|
||||
$this->generateBodyViewContent($mainFile, $body);
|
||||
}
|
||||
|
||||
if( $head !== false && $controller === $this->routeConfig()['openController'] )
|
||||
{
|
||||
$this->createSectionViews($sectionsDirectory);
|
||||
|
||||
$headFile = $sectionsDirectory . 'head.wizard.php';
|
||||
|
||||
if( $this->getMultipleThemeDirectory() !== NULL )
|
||||
{
|
||||
$this->generateMultipleHeadPage($headFile);
|
||||
|
||||
$headFile = $viewThemeDirectory . 'head.wizard.php';
|
||||
}
|
||||
|
||||
$this->generateHeadViewContent($headFile, $head);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected generate multiple head page
|
||||
*/
|
||||
protected function generateMultipleHeadPage($file)
|
||||
{
|
||||
$content = '@view(ZN\Inclusion\Project\Theme::$active . \'/head.wizard.php\')';
|
||||
|
||||
if( ! file_exists($file) || file_get_contents($file) !== $content )
|
||||
{
|
||||
file_put_contents($file, $content);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected generate head view content
|
||||
*/
|
||||
protected function generateHeadViewContent($file, $content)
|
||||
{
|
||||
file_put_contents($file, $this->globalPageParser($this->addSlashesToAt($content)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected generate head view content
|
||||
*/
|
||||
protected function generateBodyViewContent($file, $content)
|
||||
{
|
||||
file_put_contents($file, $this->globalPageParser($this->bodyParser($content)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected body parser
|
||||
*/
|
||||
protected function bodyParser($body)
|
||||
{
|
||||
return $this->addSlashesToAt(preg_replace_callback($this->getFileLinkPattern(), function($link)
|
||||
{
|
||||
$data = $link[0];
|
||||
|
||||
if( ! IS::url($url = $link['filename']) )
|
||||
{
|
||||
return str_replace
|
||||
(
|
||||
$url,
|
||||
'{|{ URL::site(\''.$this->convertValidControllerName($url).'\') }|}',
|
||||
$data
|
||||
);
|
||||
}
|
||||
|
||||
return $data; // @codeCoverageIgnore
|
||||
|
||||
}, $body));
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get file link pattern
|
||||
*/
|
||||
protected function getFileLinkPattern()
|
||||
{
|
||||
return '/(?<attribute>(href|action))\=(\"|\')(?<filename>.*?\.(' . implode('|', $this->supportedFileExtensions) . '))(\"|\')/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean comments
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function cleanComments()
|
||||
{
|
||||
$this->bodyParser['/\<\!\-\-(.*?)\-\-\>/s'] = '';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected global parser
|
||||
*/
|
||||
protected function globalPageParser($page)
|
||||
{
|
||||
$this->bodyParser['/(\.\.\/)+/'] = '//';
|
||||
$this->bodyParser['/\{\{/'] = '[{';
|
||||
$this->bodyParser['/\}\}/'] = '}]';
|
||||
$this->bodyParser['/\{\|\{/'] = '{{';
|
||||
$this->bodyParser['/\}\|\}/'] = '}}';
|
||||
|
||||
return preg_replace
|
||||
(
|
||||
array_keys($this->bodyParser),
|
||||
array_values($this->bodyParser),
|
||||
$page
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected create section views
|
||||
*/
|
||||
protected function createSectionViews(&$sectionsDirectory)
|
||||
{
|
||||
$sectionsDirectory = $this->viewsDirectory() . 'Sections/';
|
||||
|
||||
if( ! file_exists($sectionsDirectory) )
|
||||
{
|
||||
Filesystem::createFolder($sectionsDirectory); // @codeCoverageIgnore
|
||||
file_put_contents($sectionsDirectory . 'body.wizard.php', '@view'); // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected delete provious controller
|
||||
*/
|
||||
protected function deletePreviousController($controller)
|
||||
{
|
||||
$this->cleanCache($file = ($this->controllersDirectory() . Base::suffix($controller, '.php')));
|
||||
|
||||
if( is_file($file) )
|
||||
{
|
||||
@unlink($file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get controller namespace
|
||||
*/
|
||||
protected function getControllerNamespace()
|
||||
{
|
||||
return rtrim(PROJECT_CONTROLLER_NAMESPACE, '\\');
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected convert controller name
|
||||
*/
|
||||
protected function convertControllerName($controller)
|
||||
{
|
||||
return str_replace(['index'], [$this->routeConfig()['openController']], $controller ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected title case
|
||||
*/
|
||||
protected function titleCase($file)
|
||||
{
|
||||
$words = explode('-', $this->convertSlugSeparator($file));
|
||||
|
||||
$words = array_map(function($data){ return mb_convert_case($data, MB_CASE_TITLE);}, $words);
|
||||
|
||||
return implode('', $words);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected generator
|
||||
*/
|
||||
protected function generator()
|
||||
{
|
||||
return Singleton::class('ZN\Generator\Generate');
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected remove extension
|
||||
*/
|
||||
protected function removeExtension($file)
|
||||
{
|
||||
return Filesystem::removeExtension($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected write initizalize cotroller
|
||||
*/
|
||||
protected function writeInitializeController()
|
||||
{
|
||||
$initialize = '<?php namespace Project\Controllers;
|
||||
|
||||
class Initialize extends Controller
|
||||
{
|
||||
/**
|
||||
* The codes to run at startup.
|
||||
* It enters the circuit before all controllers.
|
||||
* You can change this setting in Config/Starting.php file.
|
||||
*/
|
||||
public function main(?string $params = NULL)
|
||||
{
|
||||
# The theme is activated.
|
||||
# Location: Resources/Themes/'.$this->getThemeDirectoryName().'/
|
||||
Theme::active(\''.$this->getThemeDirectoryName().'\');
|
||||
|
||||
# The current settings are being configured.
|
||||
Masterpage::headPage(\'Sections/head\')
|
||||
->bodyPage(\'Sections/body\');
|
||||
}
|
||||
}';
|
||||
|
||||
file_put_contents($this->controllersDirectory() . 'Initialize.php', $initialize);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
<?php namespace ZN;
|
||||
/**
|
||||
* 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 ReflectionClass;
|
||||
|
||||
class Classes
|
||||
{
|
||||
/**
|
||||
* Reflection Class
|
||||
*
|
||||
* @param string $className
|
||||
*
|
||||
* @return ReflectionClass
|
||||
*/
|
||||
public static function reflection(string $className) : ReflectionClass
|
||||
{
|
||||
return new ReflectionClass(self::_class($className));
|
||||
}
|
||||
|
||||
/**
|
||||
* Is Relation
|
||||
*
|
||||
* @param string $className
|
||||
* @param mixed $object
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isRelation(string $className, $object) : bool
|
||||
{
|
||||
if( ! is_object($object) )
|
||||
{
|
||||
throw new Exception\InvalidArgumentException('Error', 'objectParameter', '2.($object)');
|
||||
}
|
||||
|
||||
return is_a($object, self::_class($className));
|
||||
}
|
||||
|
||||
/**
|
||||
* Is Parent
|
||||
*
|
||||
* @param string $className
|
||||
* @param mixed $object
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isParent(string $className, $object) : bool
|
||||
{
|
||||
return is_subclass_of($object, self::_class($className));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method Exists
|
||||
*
|
||||
* @param string $className
|
||||
* @param string $method
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function methodExists(string $className, string $method) : bool
|
||||
{
|
||||
return method_exists(Singleton::class(self::_class($className)), $method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Property Exists
|
||||
*
|
||||
* @param string $className
|
||||
* @param string $property
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function propertyExists(string $className, string $property) : bool
|
||||
{
|
||||
return property_exists(Singleton::class(self::_class($className)), $property);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Methods
|
||||
*
|
||||
* @param string $className
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function methods(string $className) : array
|
||||
{
|
||||
return get_class_methods(self::_class($className));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Vars
|
||||
*
|
||||
* @param string $className
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function vars(string $className) : array
|
||||
{
|
||||
return get_class_vars(self::_class($className));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Class Name
|
||||
*
|
||||
* @param object $var
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function name($var) : string
|
||||
{
|
||||
if( ! is_object($var) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return get_class($var);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Declared Classes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function declared() : array
|
||||
{
|
||||
return get_declared_classes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Declared Interfaces
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function declaredInterfaces() : array
|
||||
{
|
||||
return get_declared_interfaces();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Declared Traits
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function declaredTraits() : array
|
||||
{
|
||||
return get_declared_traits();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Only Class Name
|
||||
*
|
||||
* @param string $class
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function onlyName(string $class) : string
|
||||
{
|
||||
return Datatype::divide(str_replace(INTERNAL_ACCESS, '', $class), '\\', -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Class Name
|
||||
*
|
||||
* @param string $clasName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function class(string $className) : string
|
||||
{
|
||||
return self::_class($className);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Class
|
||||
*/
|
||||
protected static function _class($name)
|
||||
{
|
||||
global $classMap;
|
||||
|
||||
Config::get('ClassMap');
|
||||
|
||||
$lowerName = strtolower($name);
|
||||
$lowerInternalAccess = strtolower(INTERNAL_ACCESS);
|
||||
$flipClassMap = array_flip($classMap['namespaces'] ?? []);
|
||||
$lowerClass = $lowerInternalAccess.$lowerName;
|
||||
|
||||
|
||||
if( ! empty($flipClassMap[$lowerName]) )
|
||||
{
|
||||
return $flipClassMap[$lowerName]; // @codeCoverageIgnore
|
||||
}
|
||||
elseif( ! empty($flipClassMap[$lowerClass]) )
|
||||
{
|
||||
return $flipClassMap[$lowerClass]; // @codeCoverageIgnore
|
||||
}
|
||||
elseif( ! empty($classMap['classes'][$lowerClass]) )
|
||||
{
|
||||
return $classMap['classes'][$lowerClass]; // @codeCoverageIgnore
|
||||
}
|
||||
else
|
||||
{
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php namespace ZN;
|
||||
/**
|
||||
* 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 Coalesce
|
||||
{
|
||||
/**
|
||||
* Null Coalesce
|
||||
*
|
||||
* @param mixed & $var
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function null( & $var, $value = NULL)
|
||||
{
|
||||
$var = $var ?? $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* False Coalesce
|
||||
*
|
||||
* @param mixed & $var
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function false( & $var, $value = NULL)
|
||||
{
|
||||
$var = $var === false ? $value : $var;
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty Coalesce
|
||||
*
|
||||
* @param mixed & $var
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function empty( & $var, $value = NULL)
|
||||
{
|
||||
$var = empty($var) ? $value : $var;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php namespace ZN;
|
||||
/**
|
||||
* 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 Command extends Base
|
||||
{
|
||||
/**
|
||||
* Magic constructor
|
||||
*
|
||||
* @param void
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
# If the operation is executed via console, the code flow is not continue.
|
||||
if( ! defined('CONSOLE_ENABLED') )
|
||||
{
|
||||
throw new Exception('Commands', 'canNotCommandClass'); // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php namespace ZN;
|
||||
/**
|
||||
* 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 Composer
|
||||
{
|
||||
/**
|
||||
* Default vendor path
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $path = 'vendor/autoload.php';
|
||||
|
||||
/**
|
||||
* Protected Composer Loader
|
||||
*
|
||||
* @param mixed $composer
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function loader($composer)
|
||||
{
|
||||
# Loads the default path if the parameter is set to true.
|
||||
# Default path vendor/autoloader.php
|
||||
if( $composer === true )
|
||||
{
|
||||
self::requireVendorAutoloadFile();
|
||||
}
|
||||
# Loads the parameter if it specifies a valid file path.
|
||||
elseif( is_file($composer) )
|
||||
{
|
||||
require $composer;
|
||||
}
|
||||
# The exception is throw when the parameter contains an invalid path.
|
||||
else
|
||||
{
|
||||
self::invalidComposerPathReport($composer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected require vendor autoload file
|
||||
*/
|
||||
protected static function requireVendorAutoloadFile()
|
||||
{
|
||||
if( is_file(self::$path) )
|
||||
{
|
||||
require self::$path; // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected invalid composer path report
|
||||
*/
|
||||
protected static function invalidComposerPathReport($composer)
|
||||
{
|
||||
$path = Base::suffix($composer) . self::$path;
|
||||
|
||||
Helper::report('Error', Lang::default('ZN\CoreDefaultLanguage')::select('Error', 'fileNotFound', $path) ,'AutoloadComposer');
|
||||
|
||||
throw new Exception('Error', 'fileNotFound', $path);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,307 @@
|
||||
<?php namespace ZN;
|
||||
/**
|
||||
* 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\Singleton;
|
||||
|
||||
class Config
|
||||
{
|
||||
use Singleton;
|
||||
|
||||
/**
|
||||
* Set configs
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $setConfigs = [];
|
||||
|
||||
/**
|
||||
* Get config
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $config = [];
|
||||
|
||||
/**
|
||||
* Keeps default configuration
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected static $default = false;
|
||||
|
||||
/**
|
||||
* Magic call static
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function __callStatic($method, $parameters)
|
||||
{
|
||||
$method = ucfirst($method);
|
||||
|
||||
if( is_array($parameters[0] ?? NULL) || count($parameters) >= 2 )
|
||||
{
|
||||
return self::set($method, ...$parameters);
|
||||
}
|
||||
|
||||
return self::get($method, ...$parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* private merge configs
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function _config($file)
|
||||
{
|
||||
if( ! defined('PROJECT_TYPE') )
|
||||
{
|
||||
return false; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if( CONFIG_DIR === NULL )
|
||||
{
|
||||
return false; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if( empty(self::$config[$file]) )
|
||||
{
|
||||
$path = Base::suffix($file, '.php');
|
||||
$conf = is_array($con = Base::import(CONFIG_DIR . $path)) ? $con : [];
|
||||
|
||||
self::$config[$file] = PROJECT_TYPE === 'EIP' ? array_merge
|
||||
(
|
||||
is_array($set = Base::import(SETTINGS_DIR . $path)) ? $set : [],
|
||||
$conf
|
||||
) : $conf; // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Default Configuration
|
||||
*
|
||||
* @param mixed $class
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function default($class)
|
||||
{
|
||||
self::$default = $class;
|
||||
|
||||
return self::singleton();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get config
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $configs = NULL
|
||||
* @param mixed $settings = NULL
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get(string $file, ?string $configs = NULL, $settings = NULL )
|
||||
{
|
||||
self::_config($file);
|
||||
|
||||
if( ! empty($settings) )
|
||||
{
|
||||
self::set($file, $configs, $settings);
|
||||
}
|
||||
|
||||
if( isset(self::$setConfigs[$file]) )
|
||||
{
|
||||
if( ! empty(self::$setConfigs[$file]) ) foreach( self::$setConfigs[$file] as $k => $v )
|
||||
{
|
||||
if( isset(self::$config[$file][$k]) && is_array(self::$config[$file][$k]) )
|
||||
{
|
||||
self::$config[$file][$k] = (array) self::$setConfigs[$file][$k] + self::$config[$file][$k];
|
||||
}
|
||||
else
|
||||
{
|
||||
self::$config[$file][$k] = self::$setConfigs[$file][$k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( empty($configs) )
|
||||
{
|
||||
$return = self::$config[$file] ?? NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
$return = self::$config[$file][$configs] ?? NULL;
|
||||
}
|
||||
|
||||
if( $default = self::getDefault() )
|
||||
{
|
||||
$return = (array) $return + (array) $default;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set config
|
||||
*
|
||||
* @param string $file
|
||||
* @param mixed $configs
|
||||
* @param mixed $set = NULL
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function set(string $file, $configs, $set = NULL)
|
||||
{
|
||||
if( empty($configs) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if( ! is_array($configs) )
|
||||
{
|
||||
self::$setConfigs[$file][$configs] = $set;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach( $configs as $k => $v )
|
||||
{
|
||||
self::$setConfigs[$file][$k] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
return self::$setConfigs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ini set
|
||||
*
|
||||
* @param mixed $key
|
||||
* @param mixed $val = NULL
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function iniSet($key, $val = NULL)
|
||||
{
|
||||
if( empty($key) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if( ! is_array($key) )
|
||||
{
|
||||
if( is_array($val) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if( $val !== '' )
|
||||
{
|
||||
ini_set($key, $val ?? '');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach( $key as $k => $v )
|
||||
{
|
||||
if( $v !== '' )
|
||||
{
|
||||
ini_set($k, $v ?? '');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ini get
|
||||
*
|
||||
* @param mixed $key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function iniGet($key)
|
||||
{
|
||||
if( ! is_array($key) )
|
||||
{
|
||||
return ini_get($key);
|
||||
}
|
||||
else
|
||||
{
|
||||
$keys = [];
|
||||
|
||||
foreach( $key as $k )
|
||||
{
|
||||
$keys[$k] = ini_get($k);
|
||||
}
|
||||
|
||||
return $keys;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ini get all
|
||||
*
|
||||
* @param string $extension = NULL
|
||||
* @param bool $details = true
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function iniGetAll(?string $extension = NULL, bool $details = true) : array
|
||||
{
|
||||
if( empty($extension) )
|
||||
{
|
||||
return ini_get_all();
|
||||
}
|
||||
else
|
||||
{
|
||||
return ini_get_all($extension, $details);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ini restore
|
||||
*
|
||||
* @param string $str
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function iniRestore(string $str)
|
||||
{
|
||||
ini_restore($str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Get Default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected static function getDefault()
|
||||
{
|
||||
$default = self::$default;
|
||||
|
||||
self::$default = NULL;
|
||||
|
||||
if( is_string($default) )
|
||||
{
|
||||
return get_class_vars($default);
|
||||
}
|
||||
elseif( is_object($default) )
|
||||
{
|
||||
return get_object_vars($default); // @codeCoverageIgnore
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN\Config;
|
||||
/**
|
||||
* 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\Configurable;
|
||||
|
||||
class Auth
|
||||
{
|
||||
use Configurable;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN\Config;
|
||||
/**
|
||||
* 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\Configurable;
|
||||
|
||||
class Authentication
|
||||
{
|
||||
use Configurable;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN\Config;
|
||||
/**
|
||||
* 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\Configurable;
|
||||
|
||||
class Authorization
|
||||
{
|
||||
use Configurable;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN\Config;
|
||||
/**
|
||||
* 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\Configurable;
|
||||
|
||||
class Autoloader
|
||||
{
|
||||
use Configurable;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN\Config;
|
||||
/**
|
||||
* 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\Configurable;
|
||||
|
||||
class CDNLinks
|
||||
{
|
||||
use Configurable;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN\Config;
|
||||
/**
|
||||
* 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\Configurable;
|
||||
|
||||
class Cryptography
|
||||
{
|
||||
use Configurable;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN\Config;
|
||||
/**
|
||||
* 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\Configurable;
|
||||
|
||||
class Database
|
||||
{
|
||||
use Configurable;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN\Config;
|
||||
/**
|
||||
* 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\Configurable;
|
||||
|
||||
class Expressions
|
||||
{
|
||||
use Configurable;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN\Config;
|
||||
/**
|
||||
* 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\Configurable;
|
||||
|
||||
class Filesystem
|
||||
{
|
||||
use Configurable;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN\Config;
|
||||
/**
|
||||
* 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\Configurable;
|
||||
|
||||
class Htaccess
|
||||
{
|
||||
use Configurable;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN\Config;
|
||||
/**
|
||||
* 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\Configurable;
|
||||
|
||||
class Ini
|
||||
{
|
||||
use Configurable;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN\Config;
|
||||
/**
|
||||
* 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\Configurable;
|
||||
|
||||
class Masterpage
|
||||
{
|
||||
use Configurable;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN\Config;
|
||||
/**
|
||||
* 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\Configurable;
|
||||
|
||||
class Project
|
||||
{
|
||||
use Configurable;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN\Config;
|
||||
/**
|
||||
* 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\Configurable;
|
||||
|
||||
class Projects
|
||||
{
|
||||
use Configurable;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN\Config;
|
||||
/**
|
||||
* 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\Configurable;
|
||||
|
||||
class Robots
|
||||
{
|
||||
use Configurable;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN\Config;
|
||||
/**
|
||||
* 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\Configurable;
|
||||
|
||||
class Routing
|
||||
{
|
||||
use Configurable;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN\Config;
|
||||
/**
|
||||
* 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\Configurable;
|
||||
|
||||
class Security
|
||||
{
|
||||
use Configurable;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN\Config;
|
||||
/**
|
||||
* 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\Configurable;
|
||||
|
||||
class Services
|
||||
{
|
||||
use Configurable;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN\Config;
|
||||
/**
|
||||
* 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\Configurable;
|
||||
|
||||
class Starting
|
||||
{
|
||||
use Configurable;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN\Config;
|
||||
/**
|
||||
* 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\Configurable;
|
||||
|
||||
class Storage
|
||||
{
|
||||
use Configurable;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN\Config;
|
||||
/**
|
||||
* 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\Configurable;
|
||||
|
||||
class ViewObjects
|
||||
{
|
||||
use Configurable;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php namespace ZN;
|
||||
/**
|
||||
* 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 stdClass;
|
||||
use ZN\Inclusion\Project\View;
|
||||
|
||||
#[\AllowDynamicProperties]
|
||||
|
||||
class Controller
|
||||
{
|
||||
/**
|
||||
* Magic Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if( defined('static::restore') )
|
||||
{
|
||||
Restoration::mode(static::restore); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if( defined('static::extract') || Config::starting('extractViewData') === true ) foreach( View::$data as $key => $val )
|
||||
{
|
||||
$this->$key = $val; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
View::getZNClassInstance($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restart create class map
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
public function restart()
|
||||
{
|
||||
return Autoloader::restart();
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic Get
|
||||
*
|
||||
* @param string $class
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function __get($class)
|
||||
{
|
||||
if( ! isset($this->$class) )
|
||||
{
|
||||
$this->$class = Singleton::class($class);
|
||||
}
|
||||
|
||||
return $this->$class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php namespace ZN\Controller;
|
||||
/**
|
||||
* 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\Singleton;
|
||||
use ZN\Autoloader;
|
||||
|
||||
#[\AllowDynamicProperties]
|
||||
|
||||
class Base
|
||||
{
|
||||
/**
|
||||
* Magic get
|
||||
*
|
||||
* @param string $class
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($class)
|
||||
{
|
||||
if( ! isset($this->$class) )
|
||||
{
|
||||
$this->$class = Singleton::class($class);
|
||||
}
|
||||
|
||||
return $this->$class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload ClassMap
|
||||
*
|
||||
* @param void
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function reload()
|
||||
{
|
||||
Autoloader::restart();
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php namespace ZN\Controller;
|
||||
/**
|
||||
* 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\ErrorHandling\Errors;
|
||||
use ZN\Datatype;
|
||||
use ZN\Exception;
|
||||
|
||||
class Call extends Base
|
||||
{
|
||||
/**
|
||||
* Magic call
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $param
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __call($method, $param)
|
||||
{
|
||||
throw new Exception
|
||||
(
|
||||
'Error',
|
||||
'undefinedFunction',
|
||||
Datatype::divide(str_ireplace(INTERNAL_ACCESS, '', get_called_class()), '\\', -1)."::$method()"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN\Controller;
|
||||
/**
|
||||
* 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\Factory as FactoryAbility;
|
||||
|
||||
class Factory extends Base
|
||||
{
|
||||
use FactoryAbility;
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
<?php namespace ZN;
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* Provides predefined language content for core classes.
|
||||
*/
|
||||
class CoreDefaultLanguage
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Butcher
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The language of the Core structures.
|
||||
|
|
||||
*/
|
||||
|
||||
public $en =
|
||||
[
|
||||
'butcher:notFoundExternalButcheryThemes' => 'The External/Butchery/ directory does not contain any theme directory!',
|
||||
'butcher:cantMultipleExtractTheme' => '% directory does not have the proper theme for multiple extraction!',
|
||||
'butcher:cantExtractTheme' => 'The theme can not be extract! It may have been created before.',
|
||||
'butcher:extractThemeSuccess' => 'Theme integration has been successfully completed.',
|
||||
'kernel:invalidOpenFunction' => 'Your controller does not have a valid boot method! Please check your [openFunction] configuration under the Config/Routing.php path.',
|
||||
'zn:upgradeBackupNotFound' => 'A valid upgrade backup was not found!',
|
||||
'benchmark:elapsedTime' => 'System Load Time',
|
||||
'benchmark:memoryUsage' => 'Memory Usage',
|
||||
'benchmark:maxMemoryUsage' => 'Maximum Memory Usage',
|
||||
'benchmark:resultTable' => 'BENCHMARK RESULT TABLE',
|
||||
'benchmark:performanceTips' => 'PERFORMANCE ENHANCING TIPS',
|
||||
'benchmark:laterProcess' => 'Use the following settings are recommended after completion of your project.',
|
||||
'benchmark:configAutoloader' => 'Config/Autoloader.php',
|
||||
'benchmark:configHtaccess' => 'Config/Htaccess.php',
|
||||
'benchmark:second' => 'Seconds',
|
||||
'benchmark:byte' => 'Bytes',
|
||||
'benchmark:countFile' => 'Count Load Files',
|
||||
'success' => 'The operation completed successfully.',
|
||||
'invalidCommand' => '`%` Invalid Command!',
|
||||
'emptyCommand' => 'The command parameter is empty!',
|
||||
'canNotCommandClass' => '[Command classes] can only be used with [console] commands!',
|
||||
'error' => 'Operation failed!',
|
||||
'classError' => 'Error: `%` class was not found!',
|
||||
'controllerNameError' => 'Error: A controller can not be identified by the file `%` name!',
|
||||
'notFoundController' => 'Error: URL does not contain a valid controller information! `%` controller could not be found!',
|
||||
'callUserFuncArrayError' => 'Error: URL does not contain a valid function or method information! `%` method could not be found!',
|
||||
'notIsFileError' => 'Error: URL does not contain a valid path! `%` file could not be found!',
|
||||
'fileNotWrite' => 'Error: `%` file can not create! Please check the permits of file creation!',
|
||||
'undefinedFunction' => 'Error: Call to undefined function `%`!',
|
||||
'undefinedFunctionExtension' => 'Error: `%` extension is not loaded! Install to use the `%` functions.',
|
||||
'invalidVersion' => 'Error: In order to use `%` methods need to be installed PHP version `#`!',
|
||||
'driverError' => '`%` driver not found!',
|
||||
'hashParameter' => '`%` parameter should contain the hash algos(md5, sha1) data type!',
|
||||
'emailParameter' => '`%` parameter should contain the email data type!',
|
||||
'objectParameter' => '`%` parameter should contain the object data type!',
|
||||
'resourceParameter' => '`%` parameter should contain the resource data type!',
|
||||
'callableParameter' => '`%` parameter should contain the callable data type!',
|
||||
'fileParameter' => '`%` parameter should contain the file data type!',
|
||||
'emptyParameter' => '`%` parameter should contain a value!',
|
||||
'emptyVariable' => '`%` variable should contain a value!',
|
||||
'charsetParameter' => '`%` parameter should contain a valid charset!',
|
||||
'invalidInput' => '`%` input information is invalid!',
|
||||
'typeHint' => 'Invalid parameter error! & parameter should be %!',
|
||||
'templateWizard' => 'Syntax error! Check the :, # and @ symbols.
|
||||
The use of these symbols can be forgotten.
|
||||
These symbols requires / prefix in normal use.',
|
||||
'invalidRequest' => 'Error: [Invalid Request!] Access via page URL is turned off.',
|
||||
'fileNotFound' => 'Error: `%` file was not found!',
|
||||
'folderNotFound' => 'Error: `%` folder was not found!',
|
||||
'fileAllready' => '`%` file already exists!',
|
||||
'folderAllready' => '`%` folder already exists!',
|
||||
'folderChangeDir' => '`%` Can not change the working directory!',
|
||||
'folderChangeName' => 'The name of the `%` file can not be changed!',
|
||||
'fileRemoteUpload' => '`%` file is not installed on the server!',
|
||||
'fileRemoteDownload' => '`%` file is not downloaded from the server!',
|
||||
'argumentSequence' => '`%` The argument must be such sequence'
|
||||
];
|
||||
|
||||
public $tr =
|
||||
[
|
||||
'butcher:notFoundExternalButcheryThemes' => 'External/Butchery/ dizini herhangi bir tema dizini içermiyor!',
|
||||
'butcher:cantMultipleExtractTheme' => '% dizini çoklu çıkarma işlemine uygun tema yapısına sahip değil!',
|
||||
'butcher:cantExtractTheme' => 'Tema çıkartılamıyor! Daha önce oluşturulmuş olabilir.',
|
||||
'butcher:extractThemeSuccess' => 'Tema entegrasyonu başarı ile tamamlandı.',
|
||||
'kernel:invalidOpenFunction' => 'Kontrolcünüz geçerli bir açılış yöntemi içermiyor! Lütfen Config/Routing.php yolu altında yer alan [openFunction] yapılandırmanızı kontrol edin.',
|
||||
'zn:upgradeBackupNotFound' => 'Geçerli bir yükseltme yedeği bulunamadı!',
|
||||
'benchmark:elapsedTime' => 'Sistem Yüklenme Süresi',
|
||||
'benchmark:memoryUsage' => 'Hafıza Kullanımı',
|
||||
'benchmark:maxMemoryUsage' => 'Azami Hafıza Kullanımı',
|
||||
'benchmark:resultTable' => 'BENCHMARK SONUÇ TABLOSU',
|
||||
'benchmark:performanceTips' => 'PERFORMANS ARTIRMA İPUÇLARI',
|
||||
'benchmark:laterProcess' => 'Projenizin tamamlanmasından sonra aşağıdaki ayarların kullanımı önerilir.',
|
||||
'benchmark:configAutoloader' => 'Config/Autoloader.php',
|
||||
'benchmark:configHtaccess' => 'Config/Htaccess.php',
|
||||
'benchmark:second' => 'Saniye',
|
||||
'benchmark:byte' => 'Bayt',
|
||||
'benchmark:countFile' => 'Yüklenen Dosya Sayısı',
|
||||
'success' => 'İşlem başarı ile tamamlandı.',
|
||||
'invalidCommand' => '`%` Geçersiz komut!',
|
||||
'emptyCommand' => 'Komut parametresi boş!',
|
||||
'canNotCommandClass' => '[Komut sınıfları] sadece [konsol] komutları ile kullanılabilir!',
|
||||
'error' => 'İşlem başarısız.',
|
||||
'classError' => 'Hata: `%` sınıfı bulunamadı!',
|
||||
'controllerNameError' => 'Hata: Bir controller dosyası `%` kelimesi ile isimlendirilemez!',
|
||||
'notFoundController' => 'Hata: URL geçerli bir kontrolcü bilgisi içermiyor! `%` kontrolcüsü bulunamadı!',
|
||||
'callUserFuncArrayError' => 'Hata: URL geçerli fonksiyon veya metot bilgisi içermiyor! `%` metodu bulunamadı!',
|
||||
'notIsFileError' => 'Hata: URL geçerli bir yol içermiyor! `%` dosyası bulunamadı!',
|
||||
'fileNotWrite' => 'Hata: `%` dosyası oluşturulamıyor! Lütfen dosya oluşturma yetkilerini kontrol edin!',
|
||||
'undefinedFunction' => 'Hata: `%` fonksiyonu tanımlı değil!',
|
||||
'undefinedFunctionExtension' => 'Hata: `%` eklentisi yüklü değil! `%` fonksiyonlarını kullanmak için yükleyiniz.',
|
||||
'invalidVersion' => 'Hata: `%` yöntemlerini kullanabilmeniz için en az `#` PHP sürümünün yüklü olması gerekmektedir!',
|
||||
'driverError' => '`%` sürücüsü bulunamadı!',
|
||||
'hashParameter' => '`%` parametresi şifreleme algoritmalarıdan(md5, sha1) birini içermelidir!',
|
||||
'emailParameter' => '`%` parametresi e-posta veri türü içermelidir!',
|
||||
'objectParameter' => '`%` parametresi object veri türü içermelidir!',
|
||||
'resourceParameter' => '`%` parametresi kaynak(resource) veri türü içermelidir!',
|
||||
'callableParameter' => '`%` parametresi çağrılabilir(callable) veri türü içermelidir!',
|
||||
'fileParameter' => '`%` parametresi dosya bilgisi içermelidir!',
|
||||
'emptyParameter' => '`%` parametresi bir değer içermelidir!',
|
||||
'emptyVariable' => '`%` değişkeni bir değer içermelidir!',
|
||||
'charsetParameter' => '`%` parametresi geçerli karakter seti içermelidir!',
|
||||
'invalidInput' => '`%` geçersiz girdi bilgisi!',
|
||||
'typeHint' => 'Geçersiz parametre hatası! & parametresi % türü olmalıdır!',
|
||||
'templateWizard' => 'Sözdizimi hatası! :, # and @ sembollerini kontrol edin.
|
||||
Bu sembollerin kullanımı unutulmuş olabilir.
|
||||
Bu semboller normal kullanımda / ön eki gerektirir.',
|
||||
'invalidRequest' => 'Hata: [Geçersiz İstek!] Sayfa URL üzerinden erişime kapatılmıştır.',
|
||||
'fileNotFound' => 'Hata: `%` dosyasi bulunamadi!',
|
||||
'folderNotFound' => 'Hata: `%` dizini bulunamadi!',
|
||||
'fileAllready' => '`%` dosyası zaten var!',
|
||||
'folderAllready' => '`%` dizini zaten var!',
|
||||
'folderChangeDir' => '`%` çalışma dizini olarak değiştirilemiyor!',
|
||||
'folderChangeName' => '`%` dosyasının adı değiştirilemiyor!',
|
||||
'fileRemoteUpload' => '`%` dosyası sunucuya yüklenemiyor!',
|
||||
'fileRemoteDownload' => '`%` dosyası sunucudan indirilemiyor!',
|
||||
'argumentSequence' => '`%` Argüman dizilimi böyle olmalıdır'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php namespace ZN;
|
||||
/**
|
||||
* 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 Datatype
|
||||
{
|
||||
/**
|
||||
* Case Array
|
||||
*
|
||||
* @param array $array
|
||||
* @param string $type - options[lower|upper|title]
|
||||
* @param string $keyval - options[all|key|value]
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function caseArray(array $array, string $type = 'lower', string $keyval = 'all') : array
|
||||
{
|
||||
$callback = function($data) use($type)
|
||||
{
|
||||
return mb_convert_case($data, Helper::toConstant($type, 'MB_CASE_'));
|
||||
};
|
||||
|
||||
$arrayVals = array_values($array); $arrayKeys = array_keys($array);
|
||||
|
||||
switch( $keyval )
|
||||
{
|
||||
case 'key' : $arrayKeys = array_map($callback, $arrayKeys); break;
|
||||
case 'value': $arrayVals = array_map($callback, $arrayVals); break;
|
||||
case 'all' :
|
||||
default : $arrayKeys = array_map($callback, $arrayKeys);
|
||||
$arrayVals = array_map($callback, $arrayVals);
|
||||
}
|
||||
|
||||
return array_combine($arrayKeys, $arrayVals);
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiple Key
|
||||
*
|
||||
* @param array $array
|
||||
* @param string $keySplit = '|'
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function multikey(array $array, string $keySplit = '|') : array
|
||||
{
|
||||
$newArray = [];
|
||||
|
||||
foreach( $array as $k => $v )
|
||||
{
|
||||
$keys = explode($keySplit, $k);
|
||||
|
||||
foreach( $keys as $val )
|
||||
{
|
||||
$newArray[$val] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
return $newArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Divide
|
||||
*
|
||||
* @param string $str = NULL
|
||||
* @param string $separator = '|'
|
||||
* @param string $index = '0'
|
||||
* @param string $count = '1'
|
||||
*/
|
||||
public static function divide(?string $str = NULL, string $separator = '|', string $index = '0', string $count = '1')
|
||||
{
|
||||
$arrayEx = explode($separator, $str ?? '');
|
||||
|
||||
if( $index === 'all' )
|
||||
{
|
||||
return $arrayEx;
|
||||
}
|
||||
|
||||
switch( true )
|
||||
{
|
||||
case $index < 0 : $ind = (count($arrayEx) + ($index)); break;
|
||||
case $index === 'last' : $ind = (count($arrayEx) - 1); break;
|
||||
case $index === 'first': $ind = 0; break;
|
||||
default : $ind = $index;
|
||||
}
|
||||
|
||||
if( $count === '1' )
|
||||
{
|
||||
return $arrayEx[$ind] ?? false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$return = '';
|
||||
|
||||
if( $count === 'all' )
|
||||
{
|
||||
$count = count($arrayEx) - $ind;
|
||||
}
|
||||
elseif( $count < 0 )
|
||||
{
|
||||
$count = count($arrayEx) + $count + 1;
|
||||
}
|
||||
|
||||
for( $i = 0; $i < $count; $i++ )
|
||||
{
|
||||
if( ! isset($arrayEx[$ind + $i]) )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
$return .= $arrayEx[$ind + $i] . $separator;
|
||||
}
|
||||
|
||||
return Base::removeSuffix($return, $separator);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Split Upper Case
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function splitUpperCase(string $string) : array
|
||||
{
|
||||
return preg_split('/(?=[A-Z])/', $string, -1, PREG_SPLIT_NO_EMPTY);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php namespace ZN\ErrorHandling;
|
||||
/**
|
||||
* 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\Lang;
|
||||
use ZN\ErrorHandling\Exceptions;
|
||||
|
||||
class DebugException
|
||||
{
|
||||
/**
|
||||
* Magic constructor
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $message = NULL
|
||||
* @param mixed $changed = NULL
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(string $file, ?string $message = NULL, $changed = NULL)
|
||||
{
|
||||
if( $data = Lang::default('ZN\CoreDefaultLanguage')::select($file, $message, $changed) )
|
||||
{
|
||||
$message = $data;
|
||||
}
|
||||
else
|
||||
{
|
||||
$message = $file;
|
||||
}
|
||||
|
||||
$debug = (object) debug_backtrace(2)[1];
|
||||
|
||||
echo Exceptions::continue($message, $debug->file, $debug->line);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php namespace ZN\ErrorHandling;
|
||||
/**
|
||||
* 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 ErrorHandlingDefaultConfiguration
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Error Reporting
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Includes error reporting settings.
|
||||
|
|
||||
*/
|
||||
|
||||
public $errorReporting = E_ALL;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Escape Errors
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Error numbers for which the error indication is to be prevented.
|
||||
|
|
||||
*/
|
||||
|
||||
public $escapeErrors = [];
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Exit Errors
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| It is specified which error numbers will stop the code stream.
|
||||
|
|
||||
*/
|
||||
|
||||
public $exitErrors = [0, 2];
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php namespace ZN\ErrorHandling;
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* Provides predefined language content for core classes.
|
||||
*/
|
||||
class ErrorHandlingDefaultLanguage
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Butcher
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The language of the Core structures.
|
||||
|
|
||||
*/
|
||||
|
||||
public $en =
|
||||
[
|
||||
'type' => 'Type',
|
||||
'line' => 'Line',
|
||||
'message' => 'Error',
|
||||
'file' => 'File',
|
||||
'trace' => 'Trace'
|
||||
];
|
||||
|
||||
public $tr =
|
||||
[
|
||||
'type' => 'Tür',
|
||||
'line' => 'Satır',
|
||||
'message' => 'Hata',
|
||||
'file' => 'Dosya',
|
||||
'trace' => 'İz'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
<?php namespace ZN\ErrorHandling;
|
||||
/**
|
||||
* 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\Lang;
|
||||
|
||||
class Errors
|
||||
{
|
||||
/**
|
||||
* Get error message
|
||||
*
|
||||
* @param string $langFile
|
||||
* @param string $errorMsg = NULL
|
||||
* @param mixed $ex = NULL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function message(string $langFile, ?string $errorMsg = NULL, $ex = NULL) : string
|
||||
{
|
||||
$style = 'border:solid 1px #E1E4E5;';
|
||||
$style .= 'background:#FEFEFE;';
|
||||
$style .= 'padding:10px;';
|
||||
$style .= 'margin-bottom:10px;';
|
||||
$style .= 'font-family:Calibri, Ebrima, Century Gothic, Consolas, Courier New, Courier, monospace, Tahoma, Arial;';
|
||||
$style .= 'color:#666;';
|
||||
$style .= 'text-align:left;';
|
||||
$style .= 'font-size:14px;';
|
||||
|
||||
$exStyle = 'color:#900;';
|
||||
|
||||
if( ! is_array($ex) )
|
||||
{
|
||||
$ex = '<span style="'.$exStyle .'">'.$ex.'</span>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$newArray = [];
|
||||
|
||||
if( ! empty($ex) ) foreach( $ex as $k => $v )
|
||||
{
|
||||
$newArray[$k] = $v;
|
||||
}
|
||||
|
||||
$ex = $newArray;
|
||||
}
|
||||
|
||||
$str = "<div style=\"$style\">";
|
||||
|
||||
if( $errorMsg !== NULL )
|
||||
{
|
||||
$str .= Lang::default('ZN\CoreDefaultLanguage')::select($langFile, $errorMsg, $ex);
|
||||
}
|
||||
else
|
||||
{
|
||||
$str .= $langFile;
|
||||
}
|
||||
|
||||
$str .= '</div><br>';
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get last error
|
||||
*
|
||||
* @param string $type = NULL
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function last(?string $type = NULL)
|
||||
{
|
||||
$result = error_get_last();
|
||||
|
||||
if( $type === NULL )
|
||||
{
|
||||
return $result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $result[$type] ?? false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Error log
|
||||
*
|
||||
* @param string $message
|
||||
* @param int $type = 0
|
||||
* @param string $destination = NULL
|
||||
* @param string $header = NULL
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function log(string $message, int $type = 0, ?string $destination = NULL, ?string $header = NULL) : bool
|
||||
{
|
||||
return error_log($message, $type, $destination, $header);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get error report
|
||||
*
|
||||
* @param int $level = NULL
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function report(?int $level = NULL) : int
|
||||
{
|
||||
if( ! empty($level) )
|
||||
{
|
||||
return error_reporting($level);
|
||||
}
|
||||
|
||||
return error_reporting();
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception handler
|
||||
*
|
||||
* @param void
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function handler(int $errorTypes = E_ALL | E_STRICT)
|
||||
{
|
||||
set_error_handler([new Exceptions, 'table'], $errorTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger error
|
||||
*
|
||||
* @param string $msg
|
||||
* @param int $errorType = E_USER_NOTICE
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function trigger(string $msg, int $errorType = E_USER_NOTICE) : bool
|
||||
{
|
||||
return trigger_error($msg, $errorType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore handler
|
||||
*
|
||||
* @param void
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function restore()
|
||||
{
|
||||
restore_error_handler();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,434 @@
|
||||
<?php namespace ZN\ErrorHandling;
|
||||
/**
|
||||
* 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\Lang;
|
||||
use ZN\Config;
|
||||
use ZN\Helper;
|
||||
use ZN\Datatype;
|
||||
use ZN\Inclusion;
|
||||
|
||||
class Exceptions extends \Exception implements ExceptionsInterface
|
||||
{
|
||||
/**
|
||||
* Error codes
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $errorCodes =
|
||||
[
|
||||
1 => 'ERROR',
|
||||
2 => 'WARNING',
|
||||
4 => 'PARSE',
|
||||
8 => 'NOTICE',
|
||||
16 => 'CORE_ERROR',
|
||||
32 => 'CORE_WARNING',
|
||||
64 => 'COMPILE_ERROR',
|
||||
128 => 'COMPILE_WARNING',
|
||||
256 => 'USER_ERROR',
|
||||
512 => 'USER_WARNING',
|
||||
1024 => 'USER_NOTICE',
|
||||
2048 => 'STRICT',
|
||||
4096 => 'RECOVERABLE_ERROR',
|
||||
8192 => 'DEPRECATED',
|
||||
16384 => 'USER_DEPRECATED',
|
||||
32767 => 'ALL'
|
||||
];
|
||||
|
||||
/**
|
||||
* Magic to string
|
||||
*
|
||||
* @param void
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->importExceptionTemplate($this->getMessage(), $this->getFile(), $this->getLine(), $this->getTrace());
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw exception
|
||||
*
|
||||
* @param string $message = NULL
|
||||
* @param string $key = NULL
|
||||
* @param mixed $send = NULL
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function throws(?string $message = NULL, ?string $key = NULL, $send = NULL)
|
||||
{
|
||||
$debug = self::throwFinder(debug_backtrace(2), 0, 2);
|
||||
|
||||
if( $lang = Lang::default('ZN\CoreDefaultLanguage')::select($message, $key, $send) )
|
||||
{
|
||||
$message = '['.self::cleanInternalPrefixFromClassName($debug['class']).'::'.$debug['function'].'()] '.$lang;
|
||||
}
|
||||
|
||||
self::table('self', $message, $debug['file'], $debug['line']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get exception table
|
||||
*
|
||||
* @param mixed $no = NULL
|
||||
* @param string $msg = NULL
|
||||
* @param string $file = NULL
|
||||
* @param string $line = NULL
|
||||
* @param array $trace = NULL
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function table($no = NULL, ?string $msg = NULL, ?string $file = NULL, ?string $line = NULL, ?array $trace = NULL)
|
||||
{
|
||||
if( is_object($no) )
|
||||
{
|
||||
$msg = $no->getMessage();
|
||||
$file = $no->getFile();
|
||||
$line = $no->getLine();
|
||||
$trace = $no->getTrace();
|
||||
|
||||
$no = 'NULL';
|
||||
}
|
||||
|
||||
$lang = Lang::default('ZN\ErrorHandling\ErrorHandlingDefaultLanguage')::select('Templates');
|
||||
$message = $lang['line'].':'.$line.', '.$lang['file'].':'.$file.', '.$lang['message'].':'.$msg;
|
||||
|
||||
Helper::report('ExceptionError', $message, 'ExceptionError');
|
||||
|
||||
$table = self::importExceptionTemplate($msg, $file, $line, $no, $trace);
|
||||
|
||||
$projectError = Config::default('ZN\ErrorHandling\ErrorHandlingDefaultConfiguration')::get('Project');
|
||||
|
||||
if
|
||||
(
|
||||
in_array($no, $projectError['exitErrors'] ?? [], true) ||
|
||||
in_array(self::$errorCodes[$no] ?? NULL, $projectError['exitErrors'] ?? [], true)
|
||||
)
|
||||
{
|
||||
defined('ZN_REDIRECT_NOEXIT') || exit($table); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
echo $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Continue exception
|
||||
*
|
||||
* @param string $msg
|
||||
* @param string $file
|
||||
* @param string $line
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function continue($msg, $file, $line)
|
||||
{
|
||||
return self::importExceptionTemplate($msg, $file, $line, NULL, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore exception
|
||||
*
|
||||
* @param void
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function restore() : bool
|
||||
{
|
||||
return restore_exception_handler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set exception handler
|
||||
*
|
||||
* @param void
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function handler()
|
||||
{
|
||||
set_exception_handler([__CLASS__, 'table']);
|
||||
}
|
||||
|
||||
/**
|
||||
* protected exception template
|
||||
*
|
||||
* @param string $msg
|
||||
* @param string $file
|
||||
* @param string $line
|
||||
* @param string $no
|
||||
* @param array $trace
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function importExceptionTemplate($msg, $file, $line, $no, $trace)
|
||||
{
|
||||
$projects = Config::default('ZN\ErrorHandling\ErrorHandlingDefaultConfiguration')::get('Project');
|
||||
|
||||
if( ! $projects['errorReporting'] )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if( in_array($no, $projects['escapeErrors'], true) || in_array(self::$errorCodes[$no] ?? NULL, $projects['escapeErrors'], true) )
|
||||
{
|
||||
return false; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$wizardErrorData = self::getTemplateWizardErrorData($file, $line);
|
||||
|
||||
$exceptionData =
|
||||
[
|
||||
'type' => self::$errorCodes[$no] ?? 'ERROR',
|
||||
'msg' => $msg,
|
||||
'file' => $wizardErrorData->file,
|
||||
'line' => $wizardErrorData->line,
|
||||
'trace' => $trace
|
||||
];
|
||||
|
||||
ob_end_clean();
|
||||
|
||||
return Inclusion\View::use('Table', $exceptionData, true, __DIR__ . '/Resources/');
|
||||
}
|
||||
|
||||
/**
|
||||
* protected clean class name
|
||||
*
|
||||
* @param string $class
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function cleanInternalPrefixFromClassName($class)
|
||||
{
|
||||
return str_ireplace(INTERNAL_ACCESS, '', Datatype::divide($class, '\\', -1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw finder
|
||||
*
|
||||
* @param array $trace
|
||||
* @param int $p1 = 2
|
||||
* @param int $p2 = 0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function throwFinder($trace, $p1 = 3, $p2 = 5)
|
||||
{
|
||||
$classInfo = $trace[$p1];
|
||||
$fileInfo = $trace[$p2];
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
if( ! isset($classInfo['class']) && isset($classInfo['function']) )
|
||||
{
|
||||
$classInfo['class'] = $classInfo['function'];
|
||||
$fileInfo['file'] = $classInfo['file'];
|
||||
$fileInfo['line'] = $classInfo['line'];
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return
|
||||
[
|
||||
'class' => self::cleanInternalPrefixFromClassName($classInfo['class']),
|
||||
'function' => $classInfo['function'],
|
||||
'file' => $fileInfo['file'],
|
||||
'line' => $fileInfo['line'],
|
||||
'trace' => $trace
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle template wizard
|
||||
*
|
||||
* @param void
|
||||
*
|
||||
* @return string|null
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
protected static function getTemplateWizardErrorData($file, $line)
|
||||
{
|
||||
if( strstr($file, DS . 'Buffering.php') )
|
||||
{
|
||||
$trace = debug_backtrace()[6]['args'] ?? [NULL];
|
||||
$args = debug_backtrace()[1]['args'][4] ?? [];
|
||||
|
||||
self::searchErrorWizardFile($args, $file, $line);
|
||||
|
||||
self::isWizardOrStandartFileExists($file, $trace);
|
||||
}
|
||||
|
||||
return (object)
|
||||
[
|
||||
'file' => $file,
|
||||
'line' => $line
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected search error wizard file
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
protected static function searchErrorWizardFile($args, &$file, &$line)
|
||||
{
|
||||
foreach( $args as $key => $value )
|
||||
{
|
||||
if( is_array($value) )
|
||||
{
|
||||
if( ! isset($line) && isset($value['file']) && stristr($value['file'], DS . 'Buffering.php') )
|
||||
{
|
||||
$line = $value['line'] ?? NULL;
|
||||
}
|
||||
|
||||
$find = $value['args'][0] ?? NULL;
|
||||
|
||||
if( is_string($find) && preg_match('/(Views\/)*.*?\.\wizard(\.php)*/', $find) )
|
||||
{
|
||||
$file = $find;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected is wizard or standart file exists
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
protected static function isWizardOrStandartFileExists(&$file, $trace)
|
||||
{
|
||||
if( ! is_file($file) )
|
||||
{
|
||||
$file = Base::prefix($file, VIEWS_DIR);
|
||||
|
||||
if( ! is_file($file) )
|
||||
{
|
||||
if( ! is_file($rfile = $file . '.php') )
|
||||
{
|
||||
if( ! is_file($rfile = $file . '.wizard.php') )
|
||||
{
|
||||
if( isset($trace[0]) && is_file($rfile = Base::suffix(Base::prefix($trace[0], VIEWS_DIR), '.php')) )
|
||||
{
|
||||
$file = $rfile;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( ! is_file($rfile) )
|
||||
{
|
||||
$file = VIEWS_DIR . CURRENT_CONTROLLER . '/' . CURRENT_CFUNCTION . '.wizard.php';
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$file = $rfile;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$file = $rfile;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display exception table
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $line
|
||||
* @param string $key
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function display($file, $line, $key)
|
||||
{
|
||||
?>
|
||||
<a href="#openExceptionMessage<?php echo $key?>" class="list-group-item panel-header" style="color:#999;" data-toggle="collapse">
|
||||
<span><i class="fa fa-angle-down fa-fw panel-text"></i>
|
||||
<?php echo $file ?? NULL; ?></span>
|
||||
</a>
|
||||
<div id="openExceptionMessage<?php echo $key?>" class="collapse<?php echo $key !== 0 ? '' : ' in'?>">
|
||||
<pre style="color:#ccc; background:#222; margin-top:-20px; border:0px">
|
||||
<?php
|
||||
|
||||
$content = is_file($file) ? file($file) : NULL;
|
||||
$newdata = '<?PHP' . EOL;
|
||||
$intline = $line;
|
||||
|
||||
for( $i = (($startLine = ($intline - 10)) < 0 ? 0 : $startLine); $i < ($intcount = $intline + 10); $i++ )
|
||||
{
|
||||
if( ! isset($content[$i]) )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
$index = $i + 1;
|
||||
$line = $content[$i];
|
||||
|
||||
if( $index == $intline )
|
||||
{
|
||||
$problem = ' {!!!!}';
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$problem = ' ';
|
||||
}
|
||||
|
||||
$newdata .= $index.'.' . $problem .
|
||||
str_repeat(' ', strlen($intcount) - strlen($i + 1)) .
|
||||
$line;
|
||||
}
|
||||
|
||||
echo self::displayHighlightErrorContent($newdata)
|
||||
|
||||
?></pre></div><?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected convert php tag to wizard tag
|
||||
*/
|
||||
protected static function convertPHPTagToWizardTag(&$content)
|
||||
{
|
||||
$content = str_replace(['<?php', '?>', '<?='], ['{[', ']}', '{[='], $content ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected important fields
|
||||
*/
|
||||
protected static function hiddenImportantFields(&$content)
|
||||
{
|
||||
$content = preg_replace('/\'(user|password|port|database|host|dsn|key)\'(\s+=>\s+)\'(.*?)\'(,*\s*(\n\r|\n))/', '\'$1\'$2\'********\'$4', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected display highlight error content
|
||||
*/
|
||||
protected static function displayHighlightErrorContent($content)
|
||||
{
|
||||
self::convertPHPTagToWizardTag($content);
|
||||
self::hiddenImportantFields($content);
|
||||
|
||||
$errorBlock = '<div class="error-block col-lg-12"></div>';
|
||||
|
||||
return preg_replace('/(<br\s\/>|'.CRLF.'|'.CR.'|'.LF.')+/', EOL, str_replace(['<?PHP', '{!!!!}'], [NULL, $errorBlock], Helper::highlight($content,
|
||||
[
|
||||
'default:color' => '#ccc',
|
||||
'keyword:color' => '#00BFFF',
|
||||
'string:color' => '#fff'
|
||||
])));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php namespace ZN\ErrorHandling;
|
||||
/**
|
||||
* 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 ExceptionsInterface
|
||||
{
|
||||
/**
|
||||
* Throw exception
|
||||
*
|
||||
* @param string $message = NULL
|
||||
* @param string $key = NULL
|
||||
* @param mixed $send = NULL
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function throws(?string $message = NULL, ?string $key = NULL, $send = NULL);
|
||||
|
||||
/**
|
||||
* Get exception table
|
||||
*
|
||||
* @param mixed $no = NULL
|
||||
* @param string $msg = NULL
|
||||
* @param string $file = NULL
|
||||
* @param string $line = NULL
|
||||
* @param array $trace = NULL
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function table($no = NULL, ?string $msg = NULL, ?string $file = NULL, ?string $line = NULL, ?array $trace = NULL);
|
||||
|
||||
/**
|
||||
* Restore exception
|
||||
*
|
||||
* @param void
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function restore() : bool;
|
||||
|
||||
/**
|
||||
* Set exception handler
|
||||
*
|
||||
* @param void
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function handler();
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php unset($trace['params']); ?>
|
||||
|
||||
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
|
||||
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
|
||||
<script type="text/javascript" src="https://code.jquery.com/jquery-latest.js"></script>
|
||||
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
|
||||
<style>
|
||||
code{
|
||||
background:none;
|
||||
}
|
||||
.pointer
|
||||
{
|
||||
cursor:pointer;
|
||||
}
|
||||
.text-color
|
||||
{
|
||||
color:#00BFFF
|
||||
}
|
||||
.panel-header
|
||||
{
|
||||
background-color: #1b1717;
|
||||
border: 1px solid #222;
|
||||
}
|
||||
.panel-top-header
|
||||
{
|
||||
background-color: #333;
|
||||
border:solid 1px #222;
|
||||
}
|
||||
.panel-text
|
||||
{
|
||||
color:#ccc;
|
||||
}
|
||||
.h-panel-header
|
||||
{
|
||||
margin-top: 15px;
|
||||
margin-bottom: 15px;
|
||||
font-size: 14px;
|
||||
}
|
||||
.error-block
|
||||
{
|
||||
position:absolute;
|
||||
margin-top:-19px;
|
||||
margin-left:-10px;
|
||||
margin-right:-100px;
|
||||
width:96.37%;
|
||||
height:20px;
|
||||
background:white;
|
||||
opacity:.1
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="col-lg-12" style="z-index:1000000; margin-top:15px">
|
||||
<div class="panel panel-default panel-top-header">
|
||||
|
||||
<div class="panel-heading" style="background:#222; border:none;">
|
||||
<h3 class="panel-title panel-text h-panel-header">
|
||||
<i class="fa fa-exclamation-triangle fa-fw"></i>
|
||||
<?php echo '<span class="text-color">'.($type ?? 'ERROR').'</span> » ' ?>
|
||||
<?php echo $msg ?? NULL; ?></h3>
|
||||
</div>
|
||||
|
||||
<div class="panel-body" style="margin-bottom:-17px;">
|
||||
<div class="list-group">
|
||||
<?php
|
||||
$i = 0;
|
||||
if( is_array($trace) ) foreach( $trace as $key => $debug )
|
||||
{
|
||||
if
|
||||
(
|
||||
is_array($debug) &&
|
||||
! empty($debug['file']) &&
|
||||
! strstr($debug['file'], DIRECTORY_INDEX) &&
|
||||
! strstr($debug['file'], 'Facade.php') &&
|
||||
! strstr($debug['file'], 'Buffering.php') &&
|
||||
! strstr($debug['file'], 'ZN.php') &&
|
||||
! strstr($debug['file'], 'Singleton.php') &&
|
||||
! strstr($debug['file'], 'Kernel.php') &&
|
||||
! strstr($debug['file'], 'Wizard.php') &&
|
||||
! strstr($debug['file'], 'View.php') &&
|
||||
! strstr($debug['file'], 'In.php') &&
|
||||
! strstr($debug['file'], 'Factory.php') &&
|
||||
$debug['file'] !== $file
|
||||
)
|
||||
{
|
||||
ZN\ErrorHandling\Exceptions::display($debug['file'], $debug['line'], $i);
|
||||
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
ZN\ErrorHandling\Exceptions::display($file, $line, $i === 0 ? $i : count($trace));
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php defined('ZN_REDIRECT_NOEXIT') || exit;
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN;
|
||||
/**
|
||||
* 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 Exception extends \Exception implements ExceptionInterface
|
||||
{
|
||||
use Exclusion;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php namespace ZN\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\Lang;
|
||||
use Exception;
|
||||
|
||||
class FileNotFoundException extends Exception
|
||||
{
|
||||
public function __construct($file)
|
||||
{
|
||||
parent::__construct(Lang::default('ZN\CoreDefaultLanguage')::select('Exception', 'fileNotFound', $file));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php namespace ZN\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\Lang;
|
||||
use Exception;
|
||||
|
||||
class FolderNotFoundException extends Exception
|
||||
{
|
||||
public function __construct($file)
|
||||
{
|
||||
parent::__construct(Lang::select('Exception', 'folderNotFound', $file));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN\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;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php namespace ZN\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 InvalidLocationException extends Exception
|
||||
{
|
||||
const lang =
|
||||
[
|
||||
'tr' => 'The location can be one of [project] or [external]!',
|
||||
'en' => 'Konum [project] veya [external] değerlerinden biri olabilir!'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN\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 Exception;
|
||||
|
||||
class UndefinedConstException extends Exception
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN;
|
||||
/**
|
||||
* 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 Throwable;
|
||||
|
||||
interface ExceptionInterface extends Throwable
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN;
|
||||
/**
|
||||
* 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 Project\Commands\Command as ProjectCommand;
|
||||
|
||||
class ExternalCommand extends ProjectCommand
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 Ajax
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\Hypertext\AjaxBuilder';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 Arrays
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\DataTypes\Arrays';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 Async
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\Console\Async';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 Benchmark
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\Comparison\Benchmark';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 Buffer
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\Buffering\Process';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 Butcher
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\Butcher';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 CDN
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\Services\CDN';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 CURL
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\Services\CURL';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 Cache
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\Cache\Processor';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 Captcha
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\Captcha\Render';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 Cart
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\Shopping\Cart';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 Cleaner
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\Helpers\Cleaner';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 Coalesce
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\Coalesce';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 Collection
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\DataTypes\Collection';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 Compress
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\Compression\Force';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 Converter
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\Helpers\Converter';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 Cookie
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\Storage\Cookie';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 Crontab
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\Crontab\Job';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 Crypto
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\Cryptography\Crypto';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 DB
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\Database\DB';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 DBForge
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\Database\DBForge';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 DBTool
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\Database\DBTool';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 DT
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\DateTime\DT';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 Date
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\DateTime\Date';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 Debugger
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\Helpers\Debugger';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 Document
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\Filesystem\Document';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 Email
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\Email\Sender';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 Encode
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\Cryptography\Encode';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 Errors
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\ErrorHandling\Errors';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 Events
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\EventHandler\Event';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 Excel
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\Filesystem\Converter';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 Exceptions
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\ErrorHandling\Exceptions';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 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 FTP
|
||||
{
|
||||
use ZN\Ability\Facade;
|
||||
|
||||
const target = 'ZN\Remote\FTP';
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user