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

Commit

Permalink
Merge branch 'master' into ValidatorMessages
Browse files Browse the repository at this point in the history
  • Loading branch information
Matej Szendi committed Nov 4, 2013
186 parents d5025c5 + fc19ae0 + 7d5a2cf + e35be49 + b1baf86 + 26aba26 + 306f3e6 + 104e613 + 9e0f279 + a19bb44 + 8553b0b + 02a1820 + e9dd8c9 + 5b5a91a + db9fc36 + f8b7f2b + 09edbcb + 6a99da4 + 4a9dd4d + cc4af6e + 8a07675 + c30b083 + 0c6e411 + be4dae7 + 7465e5d + 1b64e7d + 1f50979 + 92b6722 + 1d54f79 + ab5cea3 + 4f0b000 + c18caa3 + 98036b5 + 3b5c10e + a248769 + 560d3a2 + ddfdb8f + fd4ce84 + 9e4c786 + 0c0695c + 500c51d + 2f2ebee + 145abe5 + bf5d8d7 + fe0fb99 + 5f7322a + c3af80d + cf95a03 + 6a80fae + 10ed584 + 053ab77 + 495f1ba + d688369 + 56b2490 + 47a689e + f52f94e + fec9c74 + 28a9d88 + ac66d19 + 041ae5a + 63454d4 + da02d07 + 698a4d6 + 35967e7 + 427640f + 64a533c + e408635 + c004297 + b38b581 + 9a9f950 + 47a731a + 0967316 + 37f548b + 0df2db0 + e43587e + 5784352 + 93b4f40 + 3208a48 + f5dfded + 8301af5 + d4a4329 + eaf7585 + 12feb56 + 387d3ed + eb7fedd + a9a0285 + 44fa883 + 08a171a + a4b0e54 + 730ce14 + c24c880 + 80e40b3 + 20961e5 + 8cb611e + c958861 + b8b41bc + f82d7c5 + 7784cd5 + 4ed737c + 785b23e + b537b08 + 34ecc47 + 45265ad + df6c341 + efa67eb + 736f9f8 + d3b33d9 + be06520 + be3997d + e7fb236 + 5b19875 + ed60259 + ae0af2f + 761379e + 118bbd6 + 9ce360b + 4d4425a + cc47b49 + c4aa2e1 + c152f67 + bd774aa + a95f940 + fb3126d + f420aa3 + 288aa3f + 9fa9257 + 82606a6 + cbe2b1f + 46ed6e3 + 085bc16 + 5f35882 + 61d8584 + 24a5c98 + c8f7092 + ebdb37c + 3c57460 + d38a8d4 + 5725284 + 9bc667a + 5eedb7e + 0e7a856 + fc7c32a + d1f2eb1 + 5c87eda + 71d8d27 + a365923 + 7f777b6 + c62bcc9 + 4bd3bc3 + a183e11 + 84e6810 + edad949 + 043bfb5 + 8e6f606 + 1c2b629 + e4251d2 + e8c20f9 + 6de8d76 + e529dce + 24f43fa + 336bb38 + d86e872 + 41e010c + 6a5ab3d + ca50dd5 + 8b8277a + 379140a + 145dec3 + 34c979d + 838aade + 7e77c89 + 4357e91 + 6f1e5af + a847f61 + 88ffcfe + 73019c6 + 6b1491a + 480b639 + 3820b60 + 9484b97 + fa449ae + b1fa38d + 9d8b6c8 + 63f2d90 + 531f278 + 5555750 commit a7f47b6
Show file tree
Hide file tree
Showing 78 changed files with 283 additions and 71 deletions.
3 changes: 2 additions & 1 deletion src/Definition/CompilerDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,9 @@ protected function processClass($class)
preg_match($interfaceInjectorPattern, $rIface->getName(), $matches);
if ($matches) {
foreach ($rIface->getMethods() as $rMethod) {
if ($rMethod->getName() === '__construct') {
if (($rMethod->getName() === '__construct') || !count($rMethod->getParameters())) {
// constructor not allowed in interfaces
// ignore methods without parameters
continue;
}
$def['methods'][$rMethod->getName()] = true;
Expand Down
3 changes: 2 additions & 1 deletion src/Definition/RuntimeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,9 @@ protected function processClass($class)
preg_match($interfaceInjectorPattern, $rIface->getName(), $matches);
if ($matches) {
foreach ($rIface->getMethods() as $rMethod) {
if ($rMethod->getName() === '__construct') {
if (($rMethod->getName() === '__construct') || !count($rMethod->getParameters())) {
// constructor not allowed in interfaces
// Don't call interface methods without a parameter (Some aware interfaces define setters in ZF2)
continue;
}
$def['methods'][$rMethod->getName()] = Di::METHOD_IS_AWARE;
Expand Down
24 changes: 24 additions & 0 deletions src/Di.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,19 @@ protected function createInstanceViaConstructor($class, $params, $alias = null)
$callParameters = $this->resolveMethodParameters($class, '__construct', $params, $alias, self::METHOD_IS_CONSTRUCTOR, true);
}

if (!class_exists($class)) {
if (interface_exists($class)) {
throw new Exception\ClassNotFoundException(sprintf(
'Cannot instantiate interface "%s"',
$class
));
}
throw new Exception\ClassNotFoundException(sprintf(
'Class "%s" does not exist; cannot instantiate',
$class
));
}

// Hack to avoid Reflection in most common use cases
switch (count($callParameters)) {
case 0:
Expand Down Expand Up @@ -587,6 +600,17 @@ protected function resolveMethodParameters($class, $method, array $callTimeUserP

if ($requestedClass != $class && $this->instanceManager->hasConfig($requestedClass)) {
$iConfig['requestedClass'] = $this->instanceManager->getConfig($requestedClass);

if (array_key_exists('parameters', $iConfig['requestedClass'])) {
$newParameters = array();

foreach($iConfig['requestedClass']['parameters'] as $name=>$parameter) {
$newParameters[$requestedClass.'::'.$method.'::'.$name] = $parameter;
}

$iConfig['requestedClass']['parameters'] = $newParameters;
}

if ($requestedAlias) {
$iConfig['requestedAlias'] = $this->instanceManager->getConfig($requestedAlias);
}
Expand Down
1 change: 0 additions & 1 deletion test/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @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_Di
*/

namespace ZendTest\Di;
Expand Down
1 change: 0 additions & 1 deletion test/Definition/ArrayDefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @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_Di
*/

namespace ZendTest\Di\Definition;
Expand Down
1 change: 0 additions & 1 deletion test/Definition/BuilderDefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @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_Di
*/

namespace ZendTest\Di\Definition;
Expand Down
1 change: 0 additions & 1 deletion test/Definition/ClassDefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @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_Di
*/
namespace ZendTest\Di\Definition;

Expand Down
14 changes: 13 additions & 1 deletion test/Definition/CompilerDefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @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_Di
*/

namespace ZendTest\Di\Definition;
Expand Down Expand Up @@ -119,4 +118,17 @@ public function testStaticMethodsNotIncludedInDefinitions()
$this->assertTrue($definition->hasMethod('ZendTest\Di\TestAsset\SetterInjection\StaticSetter', 'setFoo'));
$this->assertFalse($definition->hasMethod('ZendTest\Di\TestAsset\SetterInjection\StaticSetter', 'setName'));
}

/**
* Test if methods from aware interfaces without params are excluded
*/
public function testExcludeAwareMethodsWithoutParameters()
{
$definition = new CompilerDefinition();
$definition->addDirectory(__DIR__ . '/../TestAsset/AwareClasses');
$definition->compile();

$this->assertTrue($definition->hasMethod('ZendTest\Di\TestAsset\AwareClasses\B', 'setSomething'));
$this->assertFalse($definition->hasMethod('ZendTest\Di\TestAsset\AwareClasses\B', 'getSomething'));
}
}
11 changes: 10 additions & 1 deletion test/Definition/RuntimeDefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @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_Di
*/

namespace ZendTest\Di\Definition;
Expand Down Expand Up @@ -93,4 +92,14 @@ public function testExceptionDefaultValue()
)
);
}

/**
* Test if methods from aware interfaces without params are excluded
*/
public function testExcludeAwareMethodsWithoutParameters()
{
$definition = new RuntimeDefinition();
$this->assertTrue($definition->hasMethod('ZendTest\Di\TestAsset\AwareClasses\B', 'setSomething'));
$this->assertFalse($definition->hasMethod('ZendTest\Di\TestAsset\AwareClasses\B', 'getSomething'));
}
}
1 change: 0 additions & 1 deletion test/DefinitionListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @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_Di
*/

namespace ZendTest\Di;
Expand Down
67 changes: 66 additions & 1 deletion test/DiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @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_Di
*/

namespace ZendTest\Di;
Expand Down Expand Up @@ -474,6 +473,41 @@ public function testNewInstanceWillUsePreferredClassForInterfaceHints()
$this->assertSame($a, $d->a);
}

public function testNewInstanceWillThrowAnClassNotFoundExceptionWhenClassIsAnInterface()
{
$definitionArray = array (
'ZendTest\Di\TestAsset\ConstructorInjection\D' => array(
'supertypes' => array(),
'instantiator' => '__construct',
'methods' => array('__construct' => 3),
'parameters' => array(
'__construct' =>
array (
'ZendTest\Di\TestAsset\ConstructorInjection\D::__construct:0' => array(
0 => 'd',
1 => 'ZendTest\Di\TestAsset\DummyInterface',
2 => true,
3 => NULL,
),
),
),
),
'ZendTest\Di\TestAsset\DummyInterface' => array(
'supertypes' => array(),
'instantiator' => NULL,
'methods' => array(),
'parameters' => array(),
),
);
$definitionList = new DefinitionList(array(
new Definition\ArrayDefinition($definitionArray)
));
$di = new Di($definitionList);

$this->setExpectedException('Zend\Di\Exception\ClassNotFoundException', 'Cannot instantiate interface');
$di->get('ZendTest\Di\TestAsset\ConstructorInjection\D');
}

public function testMatchPreferredClassWithAwareInterface()
{
$di = new Di();
Expand Down Expand Up @@ -842,4 +876,35 @@ public function testGetWithParamsWillUseSharedInstance()
$returnedC = $di->get($retrievedInstanceClass, array('params' => array('test')));
$this->assertInstanceOf($retrievedInstanceClass, $returnedC);
}

public function testGetInstanceWithParamsHasSameNameAsDependencyParam()
{
$config = new Config(array(
'definition' => array(
'class' => array(
'ZendTest\Di\TestAsset\AggregateClasses\AggregateItems' => array(
'addItem' => array(
'item' => array('type'=>'ZendTest\Di\TestAsset\AggregateClasses\ItemInterface',
'required'=>true)
)
)
)
),
'instance' => array(
'ZendTest\Di\TestAsset\AggregateClasses\AggregateItems' => array(
'injections' => array(
'ZendTest\Di\TestAsset\AggregateClasses\Item'
)
),
'ZendTest\Di\TestAsset\AggregatedParamClass' => array(
'parameters' => array(
'item' => 'ZendTest\Di\TestAsset\AggregateClasses\AggregateItems'
)
)
)
));

$di = new Di(null, null, $config);
$this->assertCount(1, $di->get('ZendTest\Di\TestAsset\AggregatedParamClass')->aggregator->items);
}
}
1 change: 0 additions & 1 deletion test/InstanceManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @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_Di
*/

namespace ZendTest\Di;
Expand Down
1 change: 0 additions & 1 deletion test/ServiceLocator/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @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_Di
*/

namespace ZendTest\Di\ServiceLocator;
Expand Down
1 change: 0 additions & 1 deletion test/ServiceLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @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_Di
*/

namespace ZendTest\Di;
Expand Down
21 changes: 21 additions & 0 deletions test/TestAsset/AggregateClasses/AggregateItems.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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
*/

namespace ZendTest\Di\TestAsset\AggregateClasses;

class AggregateItems implements ItemInterface
{
public $items = array();

public function addItem(ItemInterface $item)
{
$this->items[] = $item;
return $this;
}
}
14 changes: 14 additions & 0 deletions test/TestAsset/AggregateClasses/Item.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?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
*/

namespace ZendTest\Di\TestAsset\AggregateClasses;

class Item implements ItemInterface
{
}
16 changes: 16 additions & 0 deletions test/TestAsset/AggregateClasses/ItemInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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
*/

namespace ZendTest\Di\TestAsset\AggregateClasses;


interface ItemInterface
{

}
22 changes: 22 additions & 0 deletions test/TestAsset/AggregatedParamClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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
*/

namespace ZendTest\Di\TestAsset;

use ZendTest\Di\TestAsset\AggregateClasses\ItemInterface;

class AggregatedParamClass
{
public $aggregator = null;

public function __construct(ItemInterface $item)
{
$this->aggregator = $item;
}
}
14 changes: 14 additions & 0 deletions test/TestAsset/AwareClasses/A.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?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
*/

namespace ZendTest\Di\TestAsset\AwareClasses;

class A
{
}
27 changes: 27 additions & 0 deletions test/TestAsset/AwareClasses/B.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?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
*/

namespace ZendTest\Di\TestAsset\AwareClasses;

class B implements NoParamsAwareInterface
{
/**
* @see \ZendTest\Di\TestAsset\AwareClasses\NoParamsAwareInterface::getSomething()
*/
public function getSomething()
{
}

/**
* @see \ZendTest\Di\TestAsset\AwareClasses\NoParamsAwareInterface::setSomething()
*/
public function setSomething(A $something)
{
}
}
16 changes: 16 additions & 0 deletions test/TestAsset/AwareClasses/NoParamsAwareInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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
*/

namespace ZendTest\Di\TestAsset\AwareClasses;

interface NoParamsAwareInterface
{
public function setSomething(A $something);
public function getSomething();
}
Loading

0 comments on commit a7f47b6

Please sign in to comment.