This repository has been archived by the owner on Jan 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of git://github.com/zendframework/zf2
- Loading branch information
Showing
14 changed files
with
460 additions
and
31 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,7 @@ | ||
<?php | ||
namespace Zend\Stdlib; | ||
|
||
interface Dispatchable | ||
{ | ||
public function dispatch(RequestDescription $request, ResponseDescription $response = null); | ||
} |
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 |
---|---|---|
@@ -1,36 +1,7 @@ | ||
<?php | ||
/** | ||
* Zend Framework | ||
* | ||
* LICENSE | ||
* | ||
* This source file is subject to the new BSD license that is bundled | ||
* with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* http://framework.zend.com/license/new-bsd | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@zend.com so we can send you a copy immediately. | ||
* | ||
* @category Zend | ||
* @package Zend_Stdlib | ||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
/** | ||
* @namespace | ||
*/ | ||
namespace Zend\Stdlib; | ||
namespace Zend\Stdlib; | ||
|
||
/** | ||
* Marker interface for exceptions | ||
* | ||
* @category Zend | ||
* @package Zend_Stdlib | ||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
interface Exception | ||
interface Exception | ||
{ | ||
} |
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,9 @@ | ||
<?php | ||
|
||
namespace Zend\Stdlib\Exception; | ||
|
||
use Zend\Stdlib\Exception; | ||
|
||
class DomainException extends \DomainException implements Exception | ||
{ | ||
} |
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,11 @@ | ||
<?php | ||
|
||
namespace Zend\Stdlib\Exception; | ||
|
||
use Zend\Stdlib\Exception; | ||
|
||
class InvalidArgumentException | ||
extends \InvalidArgumentException | ||
implements Exception | ||
{ | ||
} |
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,110 @@ | ||
<?php | ||
|
||
namespace Zend\Stdlib; | ||
|
||
use Traversable; | ||
|
||
class Message implements MessageDescription | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $metadata = array(); | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $content = ''; | ||
|
||
/** | ||
* Set message metadata | ||
* | ||
* Non-destructive setting of message metadata; always adds to the metadata, never overwrites | ||
* the entire metadata container. | ||
* | ||
* @param string|int|array|Traversable $spec | ||
* @param mixed $value | ||
* @return Message | ||
*/ | ||
public function setMetadata($spec, $value = null) | ||
{ | ||
if (is_scalar($spec)) { | ||
$this->metadata[$spec] = $value; | ||
return $this; | ||
} | ||
if (!is_array($spec) && !$spec instanceof Traversable) { | ||
throw new Exception\InvalidArgumentException(sprintf( | ||
'Expected a string, array, or Traversable argument in first position; received "%s"', | ||
(is_object($spec) ? get_class($spec) : gettype($spec)) | ||
)); | ||
} | ||
foreach ($spec as $key => $value) { | ||
$this->metadata[$key] = $value; | ||
} | ||
return $this; | ||
} | ||
|
||
/** | ||
* Retrieve all metadata or a single metadatum as specified by key | ||
* | ||
* @param null|string|int $key | ||
* @param null|mixed $default | ||
* @return mixed | ||
*/ | ||
public function getMetadata($key = null, $default = null) | ||
{ | ||
if (null === $key) { | ||
return $this->metadata; | ||
} | ||
|
||
if (!is_scalar($key)) { | ||
throw new Exception\InvalidArgumentException('Non-scalar argument provided for key'); | ||
} | ||
|
||
if (array_key_exists($key, $this->metadata)) { | ||
return $this->metadata[$key]; | ||
} | ||
|
||
return $default; | ||
} | ||
|
||
/** | ||
* Set message content | ||
* | ||
* @param mixed $value | ||
* @return Message | ||
*/ | ||
public function setContent($value) | ||
{ | ||
$this->content = $value; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Get message content | ||
* | ||
* @return mixed | ||
*/ | ||
public function getContent() | ||
{ | ||
return $this->content; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function toString() | ||
{ | ||
$request = ''; | ||
foreach ($this->getMetadata() as $key => $value) { | ||
$request .= sprintf( | ||
"%s: %s\r\n", | ||
(string) $key, | ||
(string) $value | ||
); | ||
} | ||
$request .= "\r\n" . $this->getContent(); | ||
return $request; | ||
} | ||
|
||
} |
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,13 @@ | ||
<?php | ||
|
||
namespace Zend\Stdlib; | ||
|
||
interface MessageDescription | ||
{ | ||
public function setMetadata($spec, $value = null); | ||
public function getMetadata($key = null); | ||
|
||
public function setContent($content); | ||
public function getContent(); | ||
|
||
} |
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,109 @@ | ||
<?php | ||
|
||
namespace Zend\Stdlib; | ||
|
||
use ArrayObject; | ||
|
||
class Parameters extends ArrayObject implements ParametersDescription | ||
{ | ||
/** | ||
* Constructor | ||
* | ||
* Enforces that we have an array, and enforces parameter access to array | ||
* elements. | ||
* | ||
* @param array $values | ||
* @return void | ||
*/ | ||
public function __construct(array $values = null) | ||
{ | ||
if (null === $values) { | ||
$values = array(); | ||
} | ||
parent::__construct($values, ArrayObject::ARRAY_AS_PROPS); | ||
} | ||
|
||
/** | ||
* Populate from native PHP array | ||
* | ||
* @param array $values | ||
* @return void | ||
*/ | ||
public function fromArray(array $values) | ||
{ | ||
$this->exchangeArray($values); | ||
} | ||
|
||
/** | ||
* Populate from query string | ||
* | ||
* @param string $string | ||
* @return void | ||
*/ | ||
public function fromString($string) | ||
{ | ||
$array = array(); | ||
parse_str($string, $array); | ||
$this->fromArray($array); | ||
} | ||
|
||
/** | ||
* Serialize to native PHP array | ||
* | ||
* @return array | ||
*/ | ||
public function toArray() | ||
{ | ||
return $this->getArrayCopy(); | ||
} | ||
|
||
/** | ||
* Serialize to query string | ||
* | ||
* @return string | ||
*/ | ||
public function toString() | ||
{ | ||
return http_build_query($this); | ||
} | ||
|
||
/** | ||
* Retrieve by key | ||
* | ||
* Returns null if the key does not exist. | ||
* | ||
* @param string $name | ||
* @return mixed | ||
*/ | ||
public function offsetGet($name) | ||
{ | ||
if (isset($this[$name])) { | ||
return parent::offsetGet($name); | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @param mixed $default optional default value | ||
* @return mixed | ||
*/ | ||
public function get($name, $default = null) | ||
{ | ||
if (isset($this[$name])) { | ||
return parent::offsetGet($name); | ||
} | ||
return $default; | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @param mixed $value | ||
* @return $this | ||
*/ | ||
public function set($name, $value) | ||
{ | ||
$this[$name] = $value; | ||
return $this; | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
namespace Zend\Stdlib; | ||
|
||
use ArrayAccess, | ||
Countable, | ||
Serializable, | ||
Traversable; | ||
|
||
/* | ||
* Basically, an ArrayObject. You could simply define something like: | ||
* class QueryParams extends ArrayObject implements Parameters {} | ||
* and have 90% of the functionality | ||
*/ | ||
interface ParametersDescription extends ArrayAccess, Countable, Serializable, Traversable | ||
{ | ||
public function __construct(array $values = null); | ||
|
||
/* Allow deserialization from standard array */ | ||
public function fromArray(array $values); | ||
|
||
/* Allow deserialization from raw body; e.g., for PUT requests */ | ||
public function fromString($string); | ||
|
||
/* Allow serialization back to standard array */ | ||
public function toArray(); | ||
|
||
/* Allow serialization to query format; e.g., for PUT or POST requests */ | ||
public function toString(); | ||
|
||
public function get($name, $default = null); | ||
|
||
public function set($name, $value); | ||
} |
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,8 @@ | ||
<?php | ||
|
||
namespace Zend\Stdlib; | ||
|
||
class Request extends Message implements RequestDescription | ||
{ | ||
// generic request implementation | ||
} |
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,7 @@ | ||
<?php | ||
|
||
namespace Zend\Stdlib; | ||
|
||
interface RequestDescription extends MessageDescription | ||
{ | ||
} |
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,8 @@ | ||
<?php | ||
|
||
namespace Zend\Stdlib; | ||
|
||
class Response extends Message implements ResponseDescription | ||
{ | ||
// generic response implementation | ||
} |
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,8 @@ | ||
<?php | ||
|
||
namespace Zend\Stdlib; | ||
|
||
interface ResponseDescription extends MessageDescription | ||
{ | ||
|
||
} |
Oops, something went wrong.