123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- <?php
- namespace ZN\Services;
- class __USE_STATIC_ACCESS__CURL implements CURLInterface
- {
- //----------------------------------------------------------------------------------------------------
- //
- // Yazar : Ozan UYKUN <ozanbote@windowslive.com> | <ozanbote@gmail.com>
- // Site : www.zntr.net
- // Lisans : The MIT License
- // Telif Hakkı: Copyright (c) 2012-2016, zntr.net
- //
- //----------------------------------------------------------------------------------------------------
-
- /*
- * Tanıtıcı bilgisini tutar.
- *
- * @var resource
- */
- protected $init;
-
- /*
- * Seçenekler bilgisini tutar.
- *
- * @var array
- */
- protected $options = [];
-
- public function __construct()
- {
- if( ! function_exists('curl_exec') )
- {
- die(getErrorMessage('Error', 'undefinedFunction', 'curl_xxx'));
- }
- }
-
- use \CallUndefinedMethodTrait;
-
- /******************************************************************************************
- * INIT *
- *******************************************************************************************
- | Genel Kullanım: Bir CURL oturumunu ilklendirir. |
-
- @param string $url NULL
-
- @return resource
- | |
- ******************************************************************************************/
- public function init($url = CURLOPT_URL)
- {
- $this->init = curl_init($url);
-
- return $this;
- }
-
- /******************************************************************************************
- * EXEC *
- *******************************************************************************************
- | Genel Kullanım: Bir CURL oturumunu işleme sokar. |
-
- @param resource $ch;
-
- @return mixed
- | |
- ******************************************************************************************/
- public function exec()
- {
- if( ! is_resource($this->init) )
- {
- return false;
- }
-
- curl_setopt_array($this->init, $this->options);
- $this->options = [];
-
- if( is_resource($this->init) )
- {
- return curl_exec($this->init);
- }
-
- return false;
- }
-
- /******************************************************************************************
- * ESCAPE *
- *******************************************************************************************
- | Genel Kullanım: Verilen dizgenin URL'sini kodlar. |
-
- @param string $str
-
- @return string
- | |
- ******************************************************************************************/
- public function escape($str = '')
- {
- if( ! isPhpVersion('5.5.0') )
- {
- die(getErrorMessage('Error', 'invalidVersion', ['%' => 'curl_escape', '#' => '5.5.0']));
- }
-
- if( ! is_resource($this->init) )
- {
- return \Errors::set('Error', 'resourceParameter', '1.(ch)');
- }
-
- return curl_escape($this->init, $str);
- }
-
- /******************************************************************************************
- * UNESCAPE *
- *******************************************************************************************
- | Genel Kullanım: Şifrelenmiş URL verisini çözer. |
-
- @param string $str
-
- @return string
- | |
- ******************************************************************************************/
- public function unescape($str = '')
- {
- if( ! isPhpVersion('5.5.0') )
- {
- die(getErrorMessage('Error', 'invalidVersion', ['%' => 'curl_unescape', '#' => '5.5.0']));
- }
-
- if( ! is_resource($this->init) )
- {
- return \Errors::set('Error', 'resourceParameter', '1.(ch)');
- }
-
- return curl_unescape($this->init, $str);
- }
-
- /******************************************************************************************
- * INFO *
- *******************************************************************************************
- | Genel Kullanım: Belirtilen tanıtıcı ile ilgili son aktarım hakkında bilgi verir. |
-
- @param mixed $opt -> CURLINFO_ ön ekinin kullanılmasına gerek yoktur.
-
- CURLINFO_EFFECTIVE_URL yerine 'effective_url' gibi bir kullanım mümkündür.
- | |
- ******************************************************************************************/
- public function info($opt = 0)
- {
- if( ! is_resource($this->init) )
- {
- return \Errors::set('Error', 'resourceParameter', '1.(ch)');
- }
-
- return curl_getinfo($this->init, \Convert::toConstant($opt, 'CURLINFO_'));
- }
-
- /******************************************************************************************
- * ERROR *
- *******************************************************************************************
- | Genel Kullanım: CURL işlemleri esnasına oluşan hatalar hakkında bilgi almak için. |
-
- @param resource $ch
- | |
- ******************************************************************************************/
- public function error()
- {
- if( ! is_resource($this->init) )
- {
- return \Errors::set('Error', 'resourceParameter', '1.(ch)');
- }
-
- return curl_error($this->init);
- }
-
- /******************************************************************************************
- * ERRNO *
- *******************************************************************************************
- | Genel Kullanım: Belirtilen oturumdaki son hatanın kodunu döndürür. |
-
- @param resource $ch
-
- @return int
- | |
- ******************************************************************************************/
- public function errno()
- {
- if( ! is_resource($this->init) )
- {
- return \Errors::set('Error', 'resourceParameter', '1.(ch)');
- }
-
- return curl_errno($this->init);
- }
- /******************************************************************************************
- * PAUSE *
- *******************************************************************************************
- | Genel Kullanım: Bir bağlantıyı dururur. |
-
- @param int $bitmask 0
-
- @return int
- | |
- ******************************************************************************************/
- public function pause($bitmask = 0)
- {
- if( ! isPhpVersion('5.5.0') )
- {
- die(\Errors::message('Error', 'invalidVersion', ['%' => 'curl_pause', '#' => '5.5.0']));
- }
-
- if( ! empty($this->init) )
- {
- return curl_pause($this->init, $bitmask);
- }
- }
-
- /******************************************************************************************
- * RESET *
- *******************************************************************************************
- | Genel Kullanım: Bir CURL tanıcısını yeniden başlatır. |
-
- @param resource $ch
-
- @return void
- | |
- ******************************************************************************************/
- public function reset()
- {
- if( ! isPhpVersion('5.5.0') )
- {
- die(\Errors::message('Error', 'invalidVersion', ['%' => 'curl_reset', '#' => '5.5.0']));
- }
-
- if( ! empty($this->init) )
- {
- return curl_reset($this->init);
- }
- }
-
- /******************************************************************************************
- * OPTION *
- *******************************************************************************************
- | Genel Kullanım: Bir CURL aktarım seçeneği tanımlar. |
- @param mixed $options
- @param mixed $value
-
- @return bool
- | |
- ******************************************************************************************/
- public function option($options = 0, $value = '')
- {
- $this->options[\Convert::toConstant($options, 'CURLOPT_')] = $value;
-
- return $this;
- }
-
- /******************************************************************************************
- * CLOSE *
- *******************************************************************************************
- | Genel Kullanım: CURL oturumunu sonlandırır. |
-
- @param resource $ch
-
- @return void
- | |
- ******************************************************************************************/
- public function close()
- {
- $init = $this->init;
-
- if( is_resource($init) )
- {
- $this->init = NULL;
-
- return curl_close($init);
- }
-
- return false;
- }
- /******************************************************************************************
- * ERROR VAL *
- *******************************************************************************************
- | Genel Kullanım: Dönen hata numarasına göre hatanın içeriğini döndürür. |
-
- @param numeric $errno
-
- @return string
- | |
- ******************************************************************************************/
- public function errval($errno = 0)
- {
- if( ! isPhpVersion('5.5.0') )
- {
- die(\Errors::message('Error', 'invalidVersion', ['%' => 'curl_version', '#' => '5.5.0']));
- }
-
- if( ! is_numeric($errno) )
- {
- return \Errors::set('Error', 'numericParameter', '1.(errno)');
- }
-
- return curl_strerror($errno);
- }
-
- /******************************************************************************************
- * VERSION *
- *******************************************************************************************
- | Genel Kullanım: Geçerli CURL versiyonu hakkında bir dizi döndürür. |
-
- @param mixed $age now
-
- @return array
- | |
- ******************************************************************************************/
- public function version($data = NULL)
- {
- $version = curl_version();
-
- if( $data === NULL )
- {
- return $version;
- }
- else
- {
- if( isset($version[$data]) )
- {
- return $version[$data];
- }
- else
- {
- return false;
- }
- }
- }
-
- //----------------------------------------------------------------------------------------------------
- // __destruct()
- //----------------------------------------------------------------------------------------------------
- //
- // @param void
- //
- //----------------------------------------------------------------------------------------------------
- public function __destruct()
- {
- $this->close();
- }
- }
|