This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added number of parameter filter. Fixed #3352
- Loading branch information
Showing
6 changed files
with
165 additions
and
0 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
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
60 changes: 60 additions & 0 deletions
60
library/Zend/Stdlib/Hydrator/Filter/NumberOfParameterFilter.php
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,60 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_Service | ||
*/ | ||
|
||
namespace Zend\Stdlib\Hydrator\Filter; | ||
|
||
use ReflectionMethod; | ||
use ReflectionException; | ||
use Zend\Stdlib\Exception\InvalidArgumentException; | ||
use Zend\Stdlib\Hydrator\Filter\FilterInterface; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_Stdlib | ||
* @subpackage Hydrator | ||
*/ | ||
class NumberOfParameterFilter implements FilterInterface | ||
{ | ||
/** | ||
* The number of parameters beeing accepted | ||
* @var int | ||
*/ | ||
protected $numberOfParameters = null; | ||
|
||
/** | ||
* @param int $numberOfParameters Number of accepted parameters | ||
*/ | ||
public function __construct($numberOfParameters = 0) | ||
{ | ||
$this->numberOfParameters = 0; | ||
} | ||
|
||
/** | ||
* @param string $property the name of the property | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function filter($property) | ||
{ | ||
try { | ||
$reflectionMethod = new ReflectionMethod($property); | ||
} catch( ReflectionException $exception) { | ||
throw new InvalidArgumentException( | ||
"Method $property doesn't exist" | ||
); | ||
} | ||
|
||
if ($reflectionMethod->getNumberOfParameters() !== $this->numberOfParameters) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
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
43 changes: 43 additions & 0 deletions
43
tests/ZendTest/Stdlib/TestAsset/ClassMethodsInvalidParameter.php
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,43 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_Stdlib | ||
*/ | ||
namespace ZendTest\Stdlib\TestAsset; | ||
|
||
class ClassMethodsInvalidParameter | ||
{ | ||
public function hasAlias($alias) | ||
{ | ||
return $alias; | ||
} | ||
|
||
public function getTest($foo) | ||
{ | ||
return $foo; | ||
} | ||
|
||
public function isTest($bar) | ||
{ | ||
return $bar; | ||
} | ||
|
||
public function hasBar() | ||
{ | ||
return true; | ||
} | ||
|
||
public function getFoo() | ||
{ | ||
return "Bar"; | ||
} | ||
|
||
public function isBla() | ||
{ | ||
return false; | ||
} | ||
} |
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,35 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_Stdlib | ||
*/ | ||
|
||
namespace ZendTest\Stdlib\TestAsset; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_Stdlib | ||
* @subpackage UnitTests | ||
* @group Zend_Stdlib | ||
*/ | ||
class ReflectionFilter | ||
{ | ||
protected $foo = null; | ||
protected $bar = null; | ||
protected $blubb = null; | ||
protected $quo = null; | ||
|
||
public function __construct() | ||
{ | ||
$this->foo = "bar"; | ||
$this->bar = "foo"; | ||
$this->blubb = "baz"; | ||
$this->quo = "blubb"; | ||
} | ||
|
||
} | ||
|