-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added cURL communication component. Added Object component for manipulation with objects. Added DateTime component. Added form Button component. Added Tag component. Update few components.
- Loading branch information
Showing
9 changed files
with
640 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
/** | ||
* -------------------------------- | ||
* PEL - Phalcon Extensions Library | ||
* -------------------------------- | ||
* | ||
* This code is distributed under New BSD license. | ||
* License is bundled with this package in file LICENSE.txt. | ||
* | ||
* @author Jiri Pazdernik <[email protected]> | ||
*/ | ||
|
||
namespace Pel; | ||
|
||
/** | ||
* Class extending default PHP ArrayObject class | ||
* | ||
* @author Jiri Pazdernik <[email protected]> | ||
*/ | ||
class ArrayObject extends \ArrayObject | ||
{ | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @see \ArrayObject class | ||
* @param array $input | ||
* @param integer $flags | ||
* @param string $iteratorClass | ||
*/ | ||
public function __construct($input = array(), $flags = \ArrayObject::ARRAY_AS_PROPS, $iteratorClass = "ArrayIterator") | ||
{ | ||
$items = array(); | ||
|
||
foreach ($input as $key => $item) { | ||
if (is_array($item)) { | ||
$item = new ArrayObject($item, $flags, $iteratorClass); | ||
} | ||
$items[$key] = $item; | ||
} | ||
|
||
parent::__construct($items, $flags, $iteratorClass); | ||
} | ||
|
||
/** | ||
* Return data as an array | ||
* | ||
* @param boolean $recursive TRUE for convert children to array | ||
* @return array | ||
*/ | ||
public function toArray($recursive = false) | ||
{ | ||
$result = array(); | ||
|
||
foreach ($this as $key => $val) { | ||
if ((true === $recursive) && is_object($val) && method_exists($val, "toArray")) { | ||
$val = $val->toArray(); | ||
} | ||
|
||
$result[$key] = $val; | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
|
||
namespace Pel\Comm; | ||
|
||
class Curl | ||
{ | ||
|
||
// request methods | ||
const REQUEST_METHOD_GET = "GET"; | ||
const REQUEST_METHOD_POST = "POST"; | ||
const REQUEST_METHOD_PUT = "PUT"; | ||
|
||
protected $_errorNo = 0; | ||
|
||
protected $_errorMsg = null; | ||
|
||
protected $_headers = array(); | ||
|
||
protected $_info = null; | ||
|
||
protected $_response = null; | ||
|
||
public function __construct() | ||
{ | ||
|
||
} | ||
|
||
public function addHeader($value) | ||
{ | ||
$this->_headers[] = $value; | ||
} | ||
|
||
/*public function __getUrl($url, $params = null) | ||
{ | ||
if (null === $params) { | ||
return $url; | ||
} | ||
if (is_array($params)) { | ||
$parts = array(); | ||
foreach ($params as $key => $val) { | ||
$val = urlencode($val); | ||
} | ||
} | ||
}*/ | ||
|
||
public function getLastError() | ||
{ | ||
return $this->_errorNo; | ||
} | ||
|
||
public function getLastErrorMessage() | ||
{ | ||
return $this->_errorMsg; | ||
} | ||
|
||
public function getLastInfo() | ||
{ | ||
return $this->_info; | ||
} | ||
|
||
public function getLastResponse() | ||
{ | ||
return $this->_response; | ||
} | ||
|
||
public function get($url) | ||
{ | ||
return $this->send($url, null, self::REQUEST_METHOD_GET); | ||
} | ||
|
||
public function post($url, $data = null) | ||
{ | ||
return $this->send($url, $data); | ||
} | ||
|
||
public function put($url, $data = null) | ||
{ | ||
return $this->send($url, $data, self::REQUEST_METHOD_PUT); | ||
} | ||
|
||
public function send($url, $data = null, $method = self::REQUEST_METHOD_POST) | ||
{ | ||
$curl = curl_init(); | ||
|
||
if (null !== $data) { | ||
if (($method === self::REQUEST_METHOD_POST) || ($method === self::REQUEST_METHOD_PUT)) { | ||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); | ||
/*} else { | ||
if (is_array($data)) { | ||
$data = | ||
}*/ | ||
} | ||
//curl_setopt($curl, CURLOPT_POSTFIELDS, $data); | ||
} | ||
|
||
curl_setopt($curl, CURLOPT_COOKIESESSION, true); | ||
//curl_setopt($curl, CURLOPT_HEADER, true); // headers in response | ||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); | ||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); | ||
curl_setopt($curl, CURLOPT_HTTPHEADER, $this->_headers); | ||
curl_setopt($curl, CURLOPT_URL, $url); | ||
|
||
$this->_response = curl_exec($curl); | ||
$this->_errorNo = curl_errno($curl); | ||
$this->_errorMsg = curl_error($curl); | ||
$this->_info = curl_getinfo($curl); | ||
|
||
//zd($this->_errorNo); | ||
//zd($this->_errorMsg); | ||
//zd($this->_info); | ||
|
||
curl_close($curl); | ||
|
||
return $this->_response; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Pel\Common; | ||
|
||
class Object | ||
{ | ||
|
||
/** | ||
* Cast instance to another class | ||
* | ||
* @param object $instance | ||
* @param string $className | ||
* @return mixed | ||
*/ | ||
public static function cast($instance, $className) | ||
{ | ||
return unserialize(sprintf( | ||
'O:%d:"%s"%s', | ||
strlen($className), | ||
$className, | ||
strstr(strstr(serialize($instance), '"'), ':') | ||
)); | ||
} | ||
|
||
} |
Oops, something went wrong.