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

Commit 4635543

Browse files
committed
Merge branch 'master' into router-rewrite
Conflicts: library/Zend/Controller/Router/AbstractRouter.php library/Zend/Controller/Router/Rewrite.php library/Zend/Controller/Router/Route/AbstractRoute.php library/Zend/Controller/Router/Route/Chain.php library/Zend/Controller/Router/Route/Hostname.php library/Zend/Controller/Router/Route/Module.php tests/Zend/Controller/Router/Rewrite/TestAsset/DummyRoute.php tests/Zend/Controller/Router/RewriteTest.php tests/Zend/Controller/Router/Route/ChainTest.php tests/Zend/Controller/Router/Route/HostnameTest.php tests/Zend/Controller/Router/Route/ModuleTest.php
3 parents bdba5c2 + edaa760 + c4c0c95 commit 4635543

File tree

7 files changed

+392
-2
lines changed

7 files changed

+392
-2
lines changed

src/SignalHandler.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,11 @@ protected function _validateStringCallback($callback)
141141
throw new InvalidCallbackException('Provided callback is not a function or a class');
142142
}
143143

144-
$object = new $callback();
145-
if (!is_callable($object)) {
144+
// check __invoke before instantiating
145+
if (!method_exists($callback, '__invoke')) {
146146
throw new InvalidCallbackException('Class provided as a callback does not implement __invoke');
147147
}
148+
$object = new $callback();
148149

149150
$this->_callback = $object;
150151
$this->_isValidCallback = true;

src/SplPriorityQueue.php

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
18+
* @license http://framework.zend.com/license/new-bsd New BSD License
19+
*/
20+
21+
/**
22+
* @namespace
23+
*/
24+
namespace Zend\Stdlib;
25+
26+
/**
27+
* Serializable version of SplPriorityQueue
28+
*
29+
* @category Zend
30+
* @package Zend_Stdlib
31+
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
32+
* @license http://framework.zend.com/license/new-bsd New BSD License
33+
*/
34+
class SplPriorityQueue extends \SplPriorityQueue
35+
{
36+
/**
37+
* @var array Used for serialization
38+
*/
39+
private $_data = array();
40+
41+
/**
42+
* Serialize to an array
43+
*
44+
* Array will be priority => data pairs
45+
*
46+
* @return array
47+
*/
48+
public function toArray()
49+
{
50+
$this->setExtractFlags(self::EXTR_BOTH);
51+
$array = array();
52+
while ($this->valid()) {
53+
$array[] = $this->current();
54+
$this->next();
55+
}
56+
$this->setExtractFlags(self::EXTR_DATA);
57+
58+
// Iterating through a priority queue removes items
59+
foreach ($array as $item) {
60+
$this->insert($item['data'], $item['priority']);
61+
}
62+
63+
// Return only the data
64+
$return = array();
65+
foreach ($array as $item) {
66+
$return[$item['priority']] = $item['data'];
67+
}
68+
69+
return $return;
70+
}
71+
72+
/**
73+
* Serialize
74+
*
75+
* @return array
76+
*/
77+
public function __sleep()
78+
{
79+
$this->_data = array();
80+
$this->setExtractFlags(self::EXTR_BOTH);
81+
while ($this->valid()) {
82+
$this->_data[] = $this->current();
83+
$this->next();
84+
}
85+
$this->setExtractFlags(self::EXTR_DATA);
86+
87+
// Iterating through a priority queue removes items
88+
foreach ($this->_data as $item) {
89+
$this->insert($item['data'], $item['priority']);
90+
}
91+
92+
return array('_data');
93+
}
94+
95+
/**
96+
* Deserialize
97+
*
98+
* @return void
99+
*/
100+
public function __wakeup()
101+
{
102+
foreach ($this->_data as $item) {
103+
$this->insert($item['data'], $item['priority']);
104+
}
105+
$this->_data = array();
106+
}
107+
}

src/SplQueue.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
18+
* @license http://framework.zend.com/license/new-bsd New BSD License
19+
*/
20+
21+
/**
22+
* @namespace
23+
*/
24+
namespace Zend\Stdlib;
25+
26+
/**
27+
* Serializable version of SplQueue
28+
*
29+
* @category Zend
30+
* @package Zend_Stdlib
31+
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
32+
* @license http://framework.zend.com/license/new-bsd New BSD License
33+
*/
34+
class SplQueue extends \SplQueue
35+
{
36+
/**
37+
* @var array Used for serialization
38+
*/
39+
private $_data = array();
40+
41+
/**
42+
* Return an array representing the queue
43+
*
44+
* @return array
45+
*/
46+
public function toArray()
47+
{
48+
$array = array();
49+
foreach ($this as $item) {
50+
$array[] = $item;
51+
}
52+
return $array;
53+
}
54+
55+
/**
56+
* Serialize
57+
*
58+
* @return array
59+
*/
60+
public function __sleep()
61+
{
62+
$this->_data = $this->toArray();
63+
return array('_data');
64+
}
65+
66+
/**
67+
* Unserialize
68+
*
69+
* @return void
70+
*/
71+
public function __wakeup()
72+
{
73+
foreach ($this->_data as $item) {
74+
$this->push($item);
75+
}
76+
$this->_data = array();
77+
}
78+
}

src/SplStack.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
18+
* @license http://framework.zend.com/license/new-bsd New BSD License
19+
*/
20+
21+
/**
22+
* @namespace
23+
*/
24+
namespace Zend\Stdlib;
25+
26+
/**
27+
* Serializable version of SplStack
28+
*
29+
* @category Zend
30+
* @package Zend_Stdlib
31+
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
32+
* @license http://framework.zend.com/license/new-bsd New BSD License
33+
*/
34+
class SplStack extends \SplStack
35+
{
36+
/**
37+
* @var array Used in serialization
38+
*/
39+
private $_data = array();
40+
41+
/**
42+
* Serialize to an array representing the stack
43+
*
44+
* @return void
45+
*/
46+
public function toArray()
47+
{
48+
$array = array();
49+
foreach ($this as $item) {
50+
$array[] = $item;
51+
}
52+
return $array;
53+
}
54+
55+
/**
56+
* Serialize
57+
*
58+
* @return array
59+
*/
60+
public function __sleep()
61+
{
62+
$this->_data = $this->toArray();
63+
return array('_data');
64+
}
65+
66+
/**
67+
* Unserialize
68+
*
69+
* @return void
70+
*/
71+
public function __wakeup()
72+
{
73+
foreach ($this->_data as $item) {
74+
$this->unshift($item);
75+
}
76+
$this->_data = array();
77+
}
78+
}

test/SplPriorityQueueTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
namespace ZendTest\Stdlib;
3+
4+
use Zend\Stdlib\SplPriorityQueue;
5+
6+
class SplPriorityQueueTest extends \PHPUnit_Framework_TestCase
7+
{
8+
public function setUp()
9+
{
10+
$this->queue = new SplPriorityQueue();
11+
$this->queue->insert('foo', 3);
12+
$this->queue->insert('bar', 4);
13+
$this->queue->insert('baz', 2);
14+
$this->queue->insert('bat', 1);
15+
}
16+
17+
public function testSerializationAndDeserializationShouldMaintainState()
18+
{
19+
$s = serialize($this->queue);
20+
$unserialized = unserialize($s);
21+
$count = count($this->queue);
22+
$this->assertSame($count, count($unserialized), 'Expected count ' . $count . '; received ' . count($unserialized));
23+
24+
$expected = array();
25+
foreach ($this->queue as $item) {
26+
$expected[] = $item;
27+
}
28+
$test = array();
29+
foreach ($unserialized as $item) {
30+
$test[] = $item;
31+
}
32+
$this->assertSame($expected, $test, 'Expected: ' . var_export($expected, 1) . "\nReceived:" . var_export($test, 1));
33+
}
34+
35+
public function testCanRetrieveQueueAsArray()
36+
{
37+
$expected = array(
38+
4 => 'bar',
39+
3 => 'foo',
40+
2 => 'baz',
41+
1 => 'bat',
42+
);
43+
$test = $this->queue->toArray();
44+
$this->assertSame($expected, $test, var_export($test, 1));
45+
}
46+
}

test/SplQueueTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
namespace ZendTest\Stdlib;
3+
4+
use Zend\Stdlib\SplQueue;
5+
6+
class SplQueueTest extends \PHPUnit_Framework_TestCase
7+
{
8+
public function setUp()
9+
{
10+
$this->queue = new SplQueue();
11+
$this->queue->push('foo');
12+
$this->queue->push('bar');
13+
$this->queue->push('baz');
14+
}
15+
16+
public function testSerializationAndDeserializationShouldMaintainState()
17+
{
18+
$s = serialize($this->queue);
19+
$unserialized = unserialize($s);
20+
$count = count($this->queue);
21+
$this->assertSame($count, count($unserialized));
22+
23+
$expected = array();
24+
foreach ($this->queue as $item) {
25+
$expected[] = $item;
26+
}
27+
$test = array();
28+
foreach ($unserialized as $item) {
29+
$test[] = $item;
30+
}
31+
$this->assertSame($expected, $test);
32+
}
33+
34+
public function testCanRetrieveQueueAsArray()
35+
{
36+
$expected = array('foo', 'bar', 'baz');
37+
$this->assertSame($expected, $this->queue->toArray());
38+
}
39+
}

0 commit comments

Comments
 (0)