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

Commit 756e79e

Browse files
committed
Merge branch 'git/namespace-pass3' into git/development-2.0
2 parents 0c93331 + 0e997bd commit 756e79e

File tree

11 files changed

+725
-0
lines changed

11 files changed

+725
-0
lines changed

src/Exception.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
* Marker interface for exceptions
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+
interface Exception
35+
{
36+
}

src/Filter.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
* Interface for filters
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+
interface Filter
35+
{
36+
public function filter($value);
37+
public function connect($context, $handler = null);
38+
public function detach(SignalHandler $filter);
39+
public function getFilters();
40+
public function clearFilters();
41+
}

src/FilterChain.php

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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) 2010-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+
* FilterChain: subject/observer filter chain system
28+
*
29+
* @uses Zend\Stdlib\Filter
30+
* @category Zend
31+
* @package Zend_Stdlib
32+
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
33+
* @license http://framework.zend.com/license/new-bsd New BSD License
34+
*/
35+
class FilterChain implements Filter
36+
{
37+
/**
38+
* @var array All filters
39+
*/
40+
protected $_filters = array();
41+
42+
/**
43+
* Filter a value
44+
*
45+
* Notifies all subscribers passes the single value provided
46+
* as an argument. Each subsequent subscriber is passed the return value
47+
* of the previous subscriber, and the value of the last subscriber is
48+
* returned.
49+
*
50+
* @param mixed $value Value to filter
51+
* @param mixed $argv Any additional arguments
52+
* @return mixed
53+
*/
54+
public function filter($value, $argv = null)
55+
{
56+
if (!is_array($argv)) {
57+
$argv = func_get_args();
58+
$argv = array_slice($argv, 1);
59+
}
60+
61+
foreach ($this->_filters as $filter) {
62+
$callbackArgs = $argv;
63+
array_unshift($callbackArgs, $value);
64+
$value = $filter->call($callbackArgs);
65+
}
66+
return $value;
67+
}
68+
69+
/**
70+
* Subscribe
71+
*
72+
* @param string|object $context Function name, class name, or object instance
73+
* @param null|string $handler If $context is a class or object, the name of the method to call
74+
* @return Handler Pub-Sub handle (to allow later unsubscribe)
75+
*/
76+
public function connect($context, $handler = null)
77+
{
78+
if (empty($context)) {
79+
throw new InvalidCallbackException('No callback provided');
80+
}
81+
$filter = new SignalHandler(null, $context, $handler);
82+
if ($index = array_search($filter, $this->_filters)) {
83+
return $this->_filters[$index];
84+
}
85+
$this->_filters[] = $filter;
86+
return $filter;
87+
}
88+
89+
/**
90+
* Unsubscribe a filter
91+
*
92+
* @param SignalHandler $filter
93+
* @return bool Returns true if filter found and unsubscribed; returns false otherwise
94+
*/
95+
public function detach(SignalHandler $filter)
96+
{
97+
if (false === ($index = array_search($filter, $this->_filters))) {
98+
return false;
99+
}
100+
unset($this->_filters[$index]);
101+
return true;
102+
}
103+
104+
/**
105+
* Retrieve all filters
106+
*
107+
* @return SignalHandler[]
108+
*/
109+
public function getFilters()
110+
{
111+
return $this->_filters;
112+
}
113+
114+
/**
115+
* Clear all filters
116+
*
117+
* @return void
118+
*/
119+
public function clearFilters()
120+
{
121+
$this->_filters = array();
122+
}
123+
}

src/InvalidCallbackException.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
* Invalid callback exception
28+
*
29+
* @uses Exception
30+
* @uses Zend\Stdlib\Exception
31+
* @category Zend
32+
* @package Zend_Stdlib
33+
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
34+
* @license http://framework.zend.com/license/new-bsd New BSD License
35+
*/
36+
class InvalidCallbackException
37+
extends \Exception
38+
implements Exception
39+
{
40+
}

0 commit comments

Comments
 (0)