Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit 3cd8a03

Browse files
author
Pádraic Brady
committed
Merge branch 'master' into hotfix/ZF-3821
Conflicts: tests/Zend/InfoCard/XmlParsingTest.php
22 parents e7d6206 + e2d24ab + ec1abfc + 290ea90 + 9f4ca1b + edaa760 + c4c0c95 + d21f055 + 5b18029 + e6b97af + 010fb36 + 64c7b8d + 636523e + 4cc2cd6 + e34098a + 16367cd + 943c77f + 8226e5b + 0b47726 + c800904 + f52dcb8 + 126ccb2 commit 3cd8a03

14 files changed

+460
-31
lines changed

src/Dispatchable.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
namespace Zend\Stdlib;
3+
4+
interface Dispatchable
5+
{
6+
public function dispatch(RequestDescription $request, ResponseDescription $response = null);
7+
}

src/Exception.php

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,7 @@
11
<?php
2-
/**
3-
* Zend Framework
4-
*
5-
* LICENSE
6-
*
7-
* This source file is subject to the new BSD license that is bundled
8-
* with this package in the file LICENSE.txt.
9-
* It is also available through the world-wide-web at this URL:
10-
* http://framework.zend.com/license/new-bsd
11-
* If you did not receive a copy of the license and are unable to
12-
* obtain it through the world-wide-web, please send an email
13-
* to license@zend.com so we can send you a copy immediately.
14-
*
15-
* @category Zend
16-
* @package Zend_Stdlib
17-
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
18-
* @license http://framework.zend.com/license/new-bsd New BSD License
19-
*/
202

21-
/**
22-
* @namespace
23-
*/
24-
namespace Zend\Stdlib;
3+
namespace Zend\Stdlib;
254

26-
/**
27-
* Marker interface for exceptions
28-
*
29-
* @category Zend
30-
* @package Zend_Stdlib
31-
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
32-
* @license http://framework.zend.com/license/new-bsd New BSD License
33-
*/
34-
interface Exception
5+
interface Exception
356
{
367
}

src/Exception/DomainException.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Zend\Stdlib\Exception;
4+
5+
use Zend\Stdlib\Exception;
6+
7+
class DomainException extends \DomainException implements Exception
8+
{
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Zend\Stdlib\Exception;
4+
5+
use Zend\Stdlib\Exception;
6+
7+
class InvalidArgumentException
8+
extends \InvalidArgumentException
9+
implements Exception
10+
{
11+
}

src/Message.php

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
3+
namespace Zend\Stdlib;
4+
5+
use Traversable;
6+
7+
class Message implements MessageDescription
8+
{
9+
/**
10+
* @var array
11+
*/
12+
protected $metadata = array();
13+
14+
/**
15+
* @var string
16+
*/
17+
protected $content = '';
18+
19+
/**
20+
* Set message metadata
21+
*
22+
* Non-destructive setting of message metadata; always adds to the metadata, never overwrites
23+
* the entire metadata container.
24+
*
25+
* @param string|int|array|Traversable $spec
26+
* @param mixed $value
27+
* @return Message
28+
*/
29+
public function setMetadata($spec, $value = null)
30+
{
31+
if (is_scalar($spec)) {
32+
$this->metadata[$spec] = $value;
33+
return $this;
34+
}
35+
if (!is_array($spec) && !$spec instanceof Traversable) {
36+
throw new Exception\InvalidArgumentException(sprintf(
37+
'Expected a string, array, or Traversable argument in first position; received "%s"',
38+
(is_object($spec) ? get_class($spec) : gettype($spec))
39+
));
40+
}
41+
foreach ($spec as $key => $value) {
42+
$this->metadata[$key] = $value;
43+
}
44+
return $this;
45+
}
46+
47+
/**
48+
* Retrieve all metadata or a single metadatum as specified by key
49+
*
50+
* @param null|string|int $key
51+
* @param null|mixed $default
52+
* @return mixed
53+
*/
54+
public function getMetadata($key = null, $default = null)
55+
{
56+
if (null === $key) {
57+
return $this->metadata;
58+
}
59+
60+
if (!is_scalar($key)) {
61+
throw new Exception\InvalidArgumentException('Non-scalar argument provided for key');
62+
}
63+
64+
if (array_key_exists($key, $this->metadata)) {
65+
return $this->metadata[$key];
66+
}
67+
68+
return $default;
69+
}
70+
71+
/**
72+
* Set message content
73+
*
74+
* @param mixed $value
75+
* @return Message
76+
*/
77+
public function setContent($value)
78+
{
79+
$this->content = $value;
80+
return $this;
81+
}
82+
83+
/**
84+
* Get message content
85+
*
86+
* @return mixed
87+
*/
88+
public function getContent()
89+
{
90+
return $this->content;
91+
}
92+
93+
/**
94+
* @return string
95+
*/
96+
public function toString()
97+
{
98+
$request = '';
99+
foreach ($this->getMetadata() as $key => $value) {
100+
$request .= sprintf(
101+
"%s: %s\r\n",
102+
(string) $key,
103+
(string) $value
104+
);
105+
}
106+
$request .= "\r\n" . $this->getContent();
107+
return $request;
108+
}
109+
110+
}

src/MessageDescription.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Zend\Stdlib;
4+
5+
interface MessageDescription
6+
{
7+
public function setMetadata($spec, $value = null);
8+
public function getMetadata($key = null);
9+
10+
public function setContent($content);
11+
public function getContent();
12+
13+
}

src/Parameters.php

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
3+
namespace Zend\Stdlib;
4+
5+
use ArrayObject;
6+
7+
class Parameters extends ArrayObject implements ParametersDescription
8+
{
9+
/**
10+
* Constructor
11+
*
12+
* Enforces that we have an array, and enforces parameter access to array
13+
* elements.
14+
*
15+
* @param array $values
16+
* @return void
17+
*/
18+
public function __construct(array $values = null)
19+
{
20+
if (null === $values) {
21+
$values = array();
22+
}
23+
parent::__construct($values, ArrayObject::ARRAY_AS_PROPS);
24+
}
25+
26+
/**
27+
* Populate from native PHP array
28+
*
29+
* @param array $values
30+
* @return void
31+
*/
32+
public function fromArray(array $values)
33+
{
34+
$this->exchangeArray($values);
35+
}
36+
37+
/**
38+
* Populate from query string
39+
*
40+
* @param string $string
41+
* @return void
42+
*/
43+
public function fromString($string)
44+
{
45+
$array = array();
46+
parse_str($string, $array);
47+
$this->fromArray($array);
48+
}
49+
50+
/**
51+
* Serialize to native PHP array
52+
*
53+
* @return array
54+
*/
55+
public function toArray()
56+
{
57+
return $this->getArrayCopy();
58+
}
59+
60+
/**
61+
* Serialize to query string
62+
*
63+
* @return string
64+
*/
65+
public function toString()
66+
{
67+
return http_build_query($this);
68+
}
69+
70+
/**
71+
* Retrieve by key
72+
*
73+
* Returns null if the key does not exist.
74+
*
75+
* @param string $name
76+
* @return mixed
77+
*/
78+
public function offsetGet($name)
79+
{
80+
if (isset($this[$name])) {
81+
return parent::offsetGet($name);
82+
}
83+
return null;
84+
}
85+
86+
/**
87+
* @param string $name
88+
* @param mixed $default optional default value
89+
* @return mixed
90+
*/
91+
public function get($name, $default = null)
92+
{
93+
if (isset($this[$name])) {
94+
return parent::offsetGet($name);
95+
}
96+
return $default;
97+
}
98+
99+
/**
100+
* @param string $name
101+
* @param mixed $value
102+
* @return $this
103+
*/
104+
public function set($name, $value)
105+
{
106+
$this[$name] = $value;
107+
return $this;
108+
}
109+
}

src/ParametersDescription.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Zend\Stdlib;
4+
5+
use ArrayAccess,
6+
Countable,
7+
Serializable,
8+
Traversable;
9+
10+
/*
11+
* Basically, an ArrayObject. You could simply define something like:
12+
* class QueryParams extends ArrayObject implements Parameters {}
13+
* and have 90% of the functionality
14+
*/
15+
interface ParametersDescription extends ArrayAccess, Countable, Serializable, Traversable
16+
{
17+
public function __construct(array $values = null);
18+
19+
/* Allow deserialization from standard array */
20+
public function fromArray(array $values);
21+
22+
/* Allow deserialization from raw body; e.g., for PUT requests */
23+
public function fromString($string);
24+
25+
/* Allow serialization back to standard array */
26+
public function toArray();
27+
28+
/* Allow serialization to query format; e.g., for PUT or POST requests */
29+
public function toString();
30+
31+
public function get($name, $default = null);
32+
33+
public function set($name, $value);
34+
}

src/Request.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Zend\Stdlib;
4+
5+
class Request extends Message implements RequestDescription
6+
{
7+
// generic request implementation
8+
}

src/RequestDescription.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Zend\Stdlib;
4+
5+
interface RequestDescription extends MessageDescription
6+
{
7+
}

0 commit comments

Comments
 (0)