new pisilinux web sites

This commit is contained in:
Erkan IŞIK
2026-07-01 16:44:17 +03:00
commit b58488b586
21740 changed files with 2066209 additions and 0 deletions
+172
View File
@@ -0,0 +1,172 @@
<?php namespace ZN\Services;
/**
* 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\Ability\Driver;
class CDN implements CDNInterface
{
use Driver;
/**
* Driver
*
* @param array driver
*/
const driver =
[
'options' => ['cloudflare'],
'namespace' => 'ZN\Services\CDNDrivers',
'default' => 'ZN\Services\CDNDefaultConfiguration'
];
/**
* Get Links
*
* @return array
*/
public function links() : array
{
return $this->driver->getLinks();
}
/**
* Get link
*
* @param string $key
* @param string $version = 'latest'
*
* @return string|false
*/
public function link(string $key, string $version = 'latest')
{
return $this->driver->getLink($key, $version);
}
/**
* Refresh request api.
*
* @return $this
*/
public function refresh() : CDN
{
$this->driver->refresh();
return $this;
}
/**
* Set json file path.
*
* @param string $jsonFile
*
* @return $this
*/
public function setJsonFile(string $jsonFile) : CDN
{
$this->driver->setJsonFile($jsonFile);
return $this;
}
/**
* Get cdn data.
*
* @param string $configName
* @param string $name
*
* @return string
*/
public static function get(string $configName, string $name) : string
{
$config = Config::default('ZN\Services\CDNDefaultConfiguration')
::get('CDNLinks');
$configData = ! empty($config[$configName]) ? $config[$configName] : '';
if( empty($configData) )
{
return false;
}
$data = array_change_key_case($configData);
$name = strtolower($name);
if( isset($data[$name]) )
{
return $data[$name];
}
else
{
return $data; // @codeCoverageIgnore
}
}
/**
* Get value.
*
* @param string $name
*
* @return string
*/
public static function image(string $name) : string
{
return self::get('images', $name);
}
/**
* Get value.
*
* @param string $name
*
* @return string
*/
public static function style(string $name) : string
{
return self::get('styles', $name);
}
/**
* Get value.
*
* @param string $name
*
* @return string
*/
public static function script(string $name) : string
{
return self::get('scripts', $name);
}
/**
* Get value.
*
* @param string $name
*
* @return string
*/
public static function font(string $name) : string
{
return self::get('fonts', $name);
}
/**
* Get value.
*
* @param string $name
*
* @return string
*/
public static function file(string $name) : string
{
return self::get('files', $name);
}
}
+155
View File
@@ -0,0 +1,155 @@
<?php namespace ZN\Services;
/**
* 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\Protection\Json;
abstract class CDNAbstract
{
/**
* Json file.
*
* @var string
*/
protected $jsonFile = FILES_DIR . 'CDNLinks.json';
/**
* Refresh request api.
*
* @var bool
*/
protected $refresh = false;
/**
* Refresh request api.
*/
public function refresh()
{
$this->refresh = true;
}
/**
* Set json file path.
*
* @param string $jsonFile
*/
public function setJsonFile(string $jsonFile)
{
$this->jsonFile = $jsonFile;
}
/**
* Gets links.
*
* @return array
*/
public function getLinks() : array
{
if( ! $this->isJsonCheck() || $this->refresh === true )
{
$result = $this->getApiResult();
if( ! is_object($result) )
{
throw new Exception\BadRequestURLException(NULL, $this->address); // @codeCoverageIgnore
}
$this->putJsonContent($result);
}
$result = $this->decodeArrrayJsonContent();
return $this->convertArrayByKeyValues($result);
}
/**
* Get link
*
* @param string $key
* @param string $version = 'latest'
*
* @return string|false
*/
public function getLink(string $key, string $version = 'latest')
{
$return = $this->getLinks()[$key] ?? false;
if( $version !== 'latest' )
{
return $this->versionModifier($version, $return);
}
return $return;
}
/**
* Protected version modifier
*/
protected function versionModifier($version, $return)
{
return preg_replace('/([0-9]\.*){2,3}/', $version, $return);
}
/**
* Protected convert array by key values
*/
protected function convertArrayByKeyValues($result)
{
$array = [];
foreach( $result['results'] as $value )
{
$array[$value['name']] = $value['latest'];
}
return $array;
}
/**
* Protected get api result
*/
protected function getApiResult()
{
return Singleton::class('ZN\Services\Restful')->get($this->address);
}
/**
* Protected decode json array content
*/
protected function decodeArrrayJsonContent()
{
return json_decode($this->getJsonContent(), true);
}
/**
* Protected get json content
*/
protected function getJsonContent()
{
return file_get_contents($this->jsonFile);
}
/**
* Protected put json content
*/
protected function putJsonContent($result)
{
file_put_contents($this->jsonFile, json_encode($result));
}
/**
* Protected is json check
*/
protected function isJsonCheck()
{
return is_file($this->jsonFile) && Json::check($this->getJsonContent());
}
}
@@ -0,0 +1,117 @@
<?php namespace ZN\Services;
/**
* 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 CDNDefaultConfiguration
{
/*
|--------------------------------------------------------------------------
| Driver
|--------------------------------------------------------------------------
|
| Specifies the driver to use for the API connection.
|
| Options: cloudflare
|
*/
public $driver = 'cloudflare';
/*
|--------------------------------------------------------------------------
| Scripts
|--------------------------------------------------------------------------
|
| CDN Javascript links.
|
| It can be used with the Import::script() method.
|
| Example: Import::script('jquery', 'react');
|
*/
public $scripts =
[
'jquery' => 'https://code.jquery.com/jquery-latest.js',
'bootstrap' => 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js',
'angular' => 'https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js',
'react' => 'https://cdnjs.cloudflare.com/ajax/libs/react/15.5.4/react.min.js',
'vue' => 'https://cdnjs.cloudflare.com/ajax/libs/vue/2.3.3/vue.min.js',
];
/*
|--------------------------------------------------------------------------
| Styles
|--------------------------------------------------------------------------
|
| CDN CSS links.
|
| It can be used with the Import::style() method.
|
| Example: Import::style('bootstrap', 'awesome');
|
*/
public $styles =
[
'bootstrap' => 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css',
'awesome' => 'https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css',
];
/*
|--------------------------------------------------------------------------
| Fonts
|--------------------------------------------------------------------------
|
| CDN Font links.
|
| It can be used with the CDN::font() method.
|
| Example: CDN::font('robotic');
|
*/
public $fonts = [];
/*
|--------------------------------------------------------------------------
| Images
|--------------------------------------------------------------------------
|
| CDN Image links.
|
| It can be used with the CDN::image() method.
|
| Example: CDN::image('wallpaper');
|
*/
public $images = [];
/*
|--------------------------------------------------------------------------
| Files
|--------------------------------------------------------------------------
|
| CDN Files links.
|
| It can be used with the CDN::file() method.
|
| Example: CDN::file('note');
|
*/
public $files = [];
}
@@ -0,0 +1,22 @@
<?php namespace ZN\Services\CDNDrivers;
/**
* 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\Services\CDNAbstract;
class CloudflareDriver extends CDNAbstract
{
/**
* Api address
*
* @var string
*/
protected $address = 'https://api.cdnjs.com/libraries';
}
+101
View File
@@ -0,0 +1,101 @@
<?php namespace ZN\Services;
/**
* 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 CDNInterface
{
/**
* Get Links
*
* @return array
*/
public function links() : array;
/**
* Get link
*
* @param string $key
* @param string $version = 'latest'
*
* @return string|false
*/
public function link(string $key, string $version = 'latest');
/**
* Refresh request api.
*
* @return $this
*/
public function refresh() : CDN;
/**
* Set json file path.
*
* @param string $jsonFile
*
* @return $this
*/
public function setJsonFile(string $jsonFile) : CDN;
/**
* Get cdn data.
*
* @param string $configName
* @param string $name
*
* @return string
*/
public static function get(string $configName, string $name) : string;
/**
* Get value.
*
* @param string $name
*
* @return string
*/
public static function image(string $name) : string;
/**
* Get value.
*
* @param string $name
*
* @return string
*/
public static function style(string $name) : string;
/**
* Get value.
*
* @param string $name
*
* @return string
*/
public static function script(string $name) : string;
/**
* Get value.
*
* @param string $name
*
* @return string
*/
public static function font(string $name) : string;
/**
* Get value.
*
* @param string $name
*
* @return string
*/
public static function file(string $name) : string;
}
+429
View File
@@ -0,0 +1,429 @@
<?php namespace ZN\Services;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
use ZN\IS;
use ZN\Base;
use ZN\Helper;
use ZN\Request;
use ZN\Support;
use ZN\Services\Exception\InvalidArgumentException;
class CURL implements CURLInterface
{
/**
* Multiple
*
* @var bool
*/
protected $multiple;
/**
* Keeps multiple informations
*
* @var array
*/
protected $multipleInformations;
/**
* Init
*
* @var resource
*/
protected $init;
/**
* Inits
*
* @var resource
*/
protected $inits;
/**
* Options
*
* @var array
*/
protected $options = [];
/**
* Magic Constructor
*/
public function __construct()
{
Support::func('curl_exec', 'CURL');
}
/**
* Magic Destructor
*/
public function __destruct()
{
$this->close();
}
/**
* Magic Call
*
* @param string $method
* @param array $parameters
*
* @return CURL
*/
public function __call($method, $parameters)
{
$option = Helper::toConstant($method, 'CURLOPT_');
$this->options[$option] = $parameters[0] ?? NULL;
return $this;
}
/**
* Multiple
*
* @param callback $callback
*
* @return mixed
*/
public function multiple()
{
$this->multiple = true;
return $this;
}
/**
* Init
*
* @param string $url = NULL
*
* @return CURL
*/
public function init(?string $url = NULL) : CURL
{
if( $url !== NULL && ! IS::URL($url) )
{
$url = Request::getSiteURL($url);
}
if( $this->multiple )
{
$this->multipleInitialize($url);
}
else
{
$this->multipleInformations = NULL;
$this->init = curl_init($url);
}
return $this;
}
/**
* Execute
*
* @return mixed|false
*/
public function exec()
{
if( $this->multiple )
{
return $this->multipleExecute();
}
else
{
return $this->singleExecute();
}
}
/**
* Escape
*
* @param string $str
*
* @return String
*/
public function escape(string $str) : string
{
if( ! Base::isResourceObject($this->init) )
{
throw new InvalidArgumentException(NULL, '$this->init');
}
return curl_escape($this->init, $str);
}
/**
* Unescape
*
* @param string $str
*
* @return string
*/
public function unescape(string $str) : string
{
if( ! Base::isResourceObject($this->init) )
{
throw new InvalidArgumentException(NULL, '$this->init');
}
return curl_unescape($this->init, $str);
}
/**
* Info
*
* @param string $opt = NULL
*
* @return mixed
*/
public function info(?string $opt = NULL)
{
if( isset($this->multipleInformations) )
{
return $this->multipleInformations();
}
return $this->singleInformations($opt);
}
/**
* Error
*
* @return string
*/
public function error() : string
{
if( ! Base::isResourceObject($this->init) )
{
throw new InvalidArgumentException(NULL, '$this->init');
}
return curl_error($this->init);
}
/**
* Error Number
*
* @return int
*/
public function errno() : int
{
if( ! Base::isResourceObject($this->init) )
{
throw new InvalidArgumentException(NULL, '$this->init');
}
return curl_errno($this->init);
}
/**
* Pause
*
* @param string|int $bitmask = 0
*
* @return string
*/
public function pause($bitmask = 0) : int
{
if( ! empty($this->init) )
{
return curl_pause($this->init, Helper::toConstant($bitmask, 'CURLPAUSE_'));
}
return false;
}
/**
* Reset
*
* @return bool
*/
public function reset() : bool
{
if( ! empty($this->init) )
{
curl_reset($this->init);
return true;
}
return false;
}
/**
* Option
*
* @param string $options
* @param mixed $value
*
* @return CURL
*/
public function option(string $options, $value) : CURL
{
$this->options[Helper::toConstant($options, 'CURLOPT_')] = $value;
return $this;
}
/**
* Close
*
* @return bool
*/
public function close() : bool
{
$init = $this->init;
if( Base::isResourceObject($init) )
{
$this->init = NULL;
curl_close($init);
return true;
}
return false;
}
/**
* Error Value
*
* @param int $errno = 0
*
* @return string
*/
public function errval(int $errno = 0) : string
{
return curl_strerror($errno);
}
/**
* Version
*
* @param string $data = NULL
*
* @return array|string|false
*/
public function version($data = NULL)
{
$version = curl_version();
if( $data === NULL )
{
return $version;
}
else
{
return $version[$data] ?? false;
}
}
/**
* Protected single execute
*/
protected function singleExecute()
{
if( ! Base::isResourceObject($this->init) )
{
throw new InvalidArgumentException(NULL, '$this->init');
}
curl_setopt_array($this->init, $this->options);
$this->options = [];
return curl_exec($this->init);
}
/**
* Protected multiple execute
*/
protected function multipleExecute()
{
$multiInit = curl_multi_init();
foreach( $this->inits as $key => $init )
{
curl_multi_add_handle($multiInit, $this->inits[$key]);
}
do
{
curl_multi_exec($multiInit, $running);
curl_multi_select($multiInit);
}
while( $running > 0 );
$return = [];
foreach( $this->inits as $key => $init )
{
$this->multipleInformations[] = curl_multi_info_read($multiInit);
$result[] = curl_multi_getcontent($this->inits[$key]);
curl_multi_remove_handle($multiInit, $this->inits[$key]);
}
curl_multi_close($multiInit);
$this->multiple = NULL;
$this->inits = [];
return $result;
}
/**
* Protected multiple initialize
*/
protected function multipleInitialize($url)
{
$this->inits[$url] = curl_init($url);
if( $this->options )
{
curl_setopt_array($this->inits[$url], $this->options);
$this->options = [];
}
}
/**
* Protected multiple informations
*/
protected function multipleInformations()
{
$return = $this->multipleInformations;
return $return;
}
/**
* Protected single informations
*/
protected function singleInformations($opt)
{
if( ! Base::isResourceObject($this->init) )
{
throw new InvalidArgumentException(NULL, '$this->init');
}
if( $opt === NULL )
{
return curl_getinfo($this->init);
}
return curl_getinfo($this->init, Helper::toConstant($opt, 'CURLINFO_'));
}
}
+130
View File
@@ -0,0 +1,130 @@
<?php namespace ZN\Services;
/**
* 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 CURLInterface
{
/**
* Multiple
*
* @param callback $callback
*
* @return mixed
*/
public function multiple();
/**
* Init
*
* @param string $url = NULL
*
* @return CURL
*/
public function init(?string $url = NULL) : CURL;
/**
* Execute
*
* @return mixed|false
*/
public function exec();
/**
* Escape
*
* @param string $str
*
* @return String
*/
public function escape(string $str) : string;
/**
* Unescape
*
* @param string $str
*
* @return string
*/
public function unescape(string $str) : string;
/**
* Info
*
* @param string $opt = NULL
*
* @return mixed
*/
public function info(?string $opt = NULL);
/**
* Error
*
* @return string
*/
public function error() : string;
/**
* Error Number
*
* @return int
*/
public function errno() : int;
/**
* Pause
*
* @param string|int $bitmask = 0
*
* @return string
*/
public function pause($bitmask = 0) : int;
/**
* Reset
*
* @return bool
*/
public function reset() : bool;
/**
* Option
*
* @param string $options
* @param mixed $value
*
* @return CURL
*/
public function option(string $options, $value) : CURL;
/**
* Close
*
* @return bool
*/
public function close() : bool;
/**
* Error Value
*
* @param int $errno = 0
*
* @return string
*/
public function errval(int $errno = 0) : string;
/**
* Version
*
* @param string $data = NULL
*
* @return array|string|false
*/
public function version($data = NULL);
}
@@ -0,0 +1,21 @@
<?php namespace ZN\Services\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 BadRequestURLException extends Exception
{
const lang =
[
'en' => 'The [%] address contains invalid URL information!',
'tr' => '[%] adresi geçersiz bir URL bilgisi içermektedir!'
];
}
@@ -0,0 +1,23 @@
<?php namespace ZN\Services\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;
const lang =
[
'en' => '`%` parameter should contain the resource data type!',
'tr' => '`%` parametresi kaynak(resource) veri türü içermelidir!'
];
}
+429
View File
@@ -0,0 +1,429 @@
<?php namespace ZN\Services;
/**
* 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\XML;
use ZN\Singleton;
use ZN\Request\Http;
use ZN\Protection\Json;
use ZN\Response\Redirect;
class Restful implements RestfulInterface
{
/**
* URL
*
* @vasr string
*/
protected $url;
/**
* Data
*
* @var array
*/
protected $data;
/**
* Info
*
* @var array
*/
protected $info;
/**
* SSL Verify Peer
*
* @var bool
*/
protected $sslVerifyPeer = false;
/**
* Keeps curl class
*/
protected $curl;
/**
* Magic Call
*
* @param string $method
* @param array $parameters
*
* @return mixed
*/
public function __call($method, $parameters)
{
# Return CURL info.
if( $return = $this->info($method) )
{
return $return;
}
# Set CURL option.
$this->curl->{$method}(...$parameters);
return $this;
}
/**
* Magic Constructor
*/
public function __construct()
{
$this->curl = Singleton::class('ZN\Services\CURL');
}
/**
* Get request headers
*
* @return array
*
* @codeCoverageIgnore
*/
public function getRequestHeaders() : array
{
return apache_request_headers();
}
/**
* Get raw data
*
* @param string $type
*
* @return string|array|object
*/
public function getRawData(string $type = 'string')
{
$rawData = file_get_contents('php://input');
switch( $type )
{
case 'string' : return $rawData; break;
case 'object' : return Json::decodeObject($rawData);
case 'array' : return Json::decodeArray($rawData);
}
return false;
}
/**
* Get raw data object
*
* @return object
*/
public function getRawDataObject()
{
return $this->getRawData('object');
}
/**
* Get raw data array
*
* @return array
*/
public function getRawDataArray()
{
return $this->getRawData('array');
}
/**
* Content Type
*
* @param string $type = 'json'
* @param string $charset = 'utf-8'
*
* @return Restful
*/
public function contentType(string $type = 'json', string $charset = 'utf-8') : Restful
{
header('Content-Type: application/' . $type . '; charset=' . $charset);
return $this;
}
/**
* HTTP Status
*
* @param int ¢ode = NULL
*
* @return Restful
*/
public function httpStatus(?int $code = NULL) : Restful
{
$code = $code ?? Redirect::status();
header('HTTP/1.1 ' . $code . ' ' . Http::code($code));
return $this;
}
/**
* Info
*
* @param string $key = NULL
*
* @return mixed
*/
public function info(?string $key = NULL)
{
return $key === NULL ? $this->info : ($this->info[strtolower($key ?? '')] ?? false);
}
/**
* URL
*
* @param string
*
* @return Restful
*/
public function url(string $url) : Restful
{
$this->url = $url;
return $this;
}
/**
* Data
*
* @param mixed $data
*
* @return Restful
*/
public function data($data) : Restful
{
$this->data = $data;
return $this;
}
/**
* SSL Verify Peer
*
* @param bool $type = false
*
* @return Restful
*/
public function sslVerifyPeer(bool $type = false) : Restful
{
$this->sslVerifyPeer = $type;
return $this;
}
/**
* Get
*
* @param string $url = NULL
*
* @return object
*/
public function get(?string $url = NULL)
{
$response = $this->curl
->init($this->url ?? $url)
->option('returntransfer', true)
->option('ssl_verifypeer', $this->sslVerifyPeer)
->exec();
return $this->_result($response);
}
/**
* Post
*
* @param string $url = NULL
* @param mixed $data = NULL
*
* @return object
*/
public function post(?string $url = NULL, $data = NULL)
{
$response = $this->curl
->init($this->url ?? $url)
->option('returntransfer', true)
->option('post', true)
->option('ssl_verifypeer', $this->sslVerifyPeer)
->option('postfields', $this->buildQuery($data))
->exec();
return $this->_result($response);
}
/**
* Post Json
*
* @param string $url = NULL
* @param mixed $data = NULL
*
* @return object
*/
public function postJson(?string $url = NULL, $data = NULL)
{
return $this->post($url, json_encode($this->data ?? $data));
}
/**
* Put
*
* @param string $url = NULL
* @param mixed $data = NULL
*
* @return object
*/
public function put(?string $url = NULL, $data = NULL)
{
return $this->_customRequest($url, $this->buildQuery($data), __FUNCTION__);
}
/**
* Put Json
*
* @param string $url = NULL
* @param mixed $data = NULL
*
* @return object
*/
public function putJson(?string $url = NULL, $data = NULL)
{
return $this->_customRequest($url, json_encode($this->data ?? $data), 'put');
}
/**
* Patch
*
* @param string $url = NULL
* @param mixed $data = NULL
*
* @return object
*/
public function patch(?string $url = NULL, $data = NULL)
{
return $this->_customRequest($url, $this->buildQuery($data), __FUNCTION__);
}
/**
* Patch Json
*
* @param string $url = NULL
* @param mixed $data = NULL
*
* @return object
*/
public function patchJson(?string $url = NULL, $data = NULL)
{
return $this->_customRequest($url, json_encode($this->data ?? $data), 'patch');
}
/**
* Delete
*
* @param string $url = NULL
* @param mixed $data = NULL
*
* @return object
*/
public function delete(?string $url = NULL, $data = NULL)
{
return $this->_customRequest($url, $this->data ?? $data, __FUNCTION__);
}
/**
* Return
*
* @param callable $callback
*
* @return callable
*/
public function return(callable $callback)
{
return $callback();
}
/**
* Protected build query
*/
protected function buildQuery($data)
{
$data = $this->data ?? $data;
return is_string($data) ? $data : http_build_query($data, '', '&', PHP_QUERY_RFC1738);
}
/**
* Protected Custom Request
*/
protected function _customRequest($url, $data, $type)
{
$response = $this->curl->init($this->url ?? $url)
->option('returntransfer', true)
->option('customrequest', strtoupper($type))
->option('ssl_verifypeer', $this->sslVerifyPeer)
->option('postfields', $data)
->exec();
return $this->_result($response);
}
/**
* Protected Info
*/
protected function _info()
{
$this->info['gethttpcode'] = $this->curl->info('http_code');
$this->info['getfiletime'] = $this->curl->info('filetime');
$this->info['gettotaltime'] = $this->curl->info('total_time');
$this->info['getpretransfertime'] = $this->curl->info('pretransfer_time');
$this->info['getstarttransfertime'] = $this->curl->info('starttransfer_time');
$this->info['getredirecttime'] = $this->curl->info('redirect_time');
$this->info['getuploadsize'] = $this->curl->info('size_upload');
$this->info['getdownloadsize'] = $this->curl->info('size_download');
$this->info['getrequestsize'] = $this->curl->info('request_size');
$this->info['getdownloadspeed'] = $this->curl->info('speed_download');
$this->info['getuploadspeed'] = $this->curl->info('speed_upload');
$this->info['all'] = $this->curl->info(NULL);
}
/**
* Protected Result
*/
protected function _result($response)
{
$this->_info();
$this->curl->close();
$this->_default();
if( Json::check($response) )
{
return json_decode($response);
}
elseif( XML\Check::check($response) )
{
return XML\Parser::simple($response);
}
else
{
return $response;
}
}
/**
* Protected Default
*/
protected function _default()
{
$this->url = NULL;
$this->data = NULL;
$this->sslVerifyPeer = false;
}
}
@@ -0,0 +1,186 @@
<?php namespace ZN\Services;
/**
* 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 RestfulInterface
{
/**
* Get request headers
*
* @return array
*/
public function getRequestHeaders() : array;
/**
* Get raw data
*
* @param string $type
*
* @return string|array|object
*/
public function getRawData(string $type = 'string');
/**
* Get raw data object
*
* @return object
*/
public function getRawDataObject();
/**
* Get raw data array
*
* @return array
*/
public function getRawDataArray();
/**
* Content Type
*
* @param string $type = 'json'
* @param string $charset = 'utf-8'
*
* @return Restful
*/
public function contentType(string $type = 'json', string $charset = 'utf-8') : Restful;
/**
* HTTP Status
*
* @param int ¢ode = NULL
*
* @return Restful
*/
public function httpStatus(?int $code = NULL) : Restful;
/**
* Info
*
* @param string $key = NULL
*
* @return mixed
*/
public function info(?string $key = NULL);
/**
* URL
*
* @param string
*
* @return Restful
*/
public function url(string $url) : Restful;
/**
* Data
*
* @param mixed $data
*
* @return Restful
*/
public function data($data) : Restful;
/**
* SSL Verify Peer
*
* @param bool $type = false
*
* @return Restful
*/
public function sslVerifyPeer(bool $type = false) : Restful;
/**
* Get
*
* @param string $url = NULL
*
* @return object
*/
public function get(?string $url = NULL);
/**
* Post
*
* @param string $url = NULL
* @param mixed $data = NULL
*
* @return object
*/
public function post(?string $url = NULL, $data = NULL);
/**
* Post Json
*
* @param string $url = NULL
* @param mixed $data = NULL
*
* @return object
*/
public function postJson(?string $url = NULL, $data = NULL);
/**
* Put
*
* @param string $url = NULL
* @param mixed $data = NULL
*
* @return object
*/
public function put(?string $url = NULL, $data = NULL);
/**
* Put Json
*
* @param string $url = NULL
* @param mixed $data = NULL
*
* @return object
*/
public function putJson(?string $url = NULL, $data = NULL);
/**
* Patch
*
* @param string $url = NULL
* @param mixed $data = NULL
*
* @return object
*/
public function patch(?string $url = NULL, $data = NULL);
/**
* Patch Json
*
* @param string $url = NULL
* @param mixed $data = NULL
*
* @return object
*/
public function patchJson(?string $url = NULL, $data = NULL);
/**
* Delete
*
* @param string $url = NULL
* @param mixed $data = NULL
*
* @return object
*/
public function delete(?string $url = NULL, $data = NULL);
/**
* Return
*
* @param callable $callback
*
* @return callable
*/
public function return(callable $callback);
}