Skip to content

Commit

Permalink
Cleaning up documentations and marking utility method as internal to …
Browse files Browse the repository at this point in the history
…warn potential users
  • Loading branch information
Ocramius committed Jul 5, 2012
1 parent aa00d2f commit f9d681b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
3 changes: 3 additions & 0 deletions library/Zend/Di/Di.php
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,9 @@ protected function resolveMethodParameters($class, $method, array $callTimeUserP
* Utility method used to retrieve the class of a particular instance. This is here to allow extending classes to
* override how class names are resolved
*
* @internal this method is used by the ServiceLocator\DependencyInjectorProxy class to interact with instances
* and is a hack to be used internally until a major refactor does not split the `resolveMethodParameters`. Do not
* rely on its functionality.
* @param Object $instance
* @return string
*/
Expand Down
20 changes: 16 additions & 4 deletions library/Zend/Di/ServiceLocator/DependencyInjectorProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Zend\Di\Di;
use Zend\Di\Exception;

/**
* Proxy used to analyze how instances are created by a given Di.
*/
class DependencyInjectorProxy extends Di
{
/**
Expand Down Expand Up @@ -81,8 +84,9 @@ public function createInstanceViaConstructor($class, $params, $alias = null)
/**
* Override instance creation via callback
*
* @param callback $callback
* @param null|array $params
* @param callback $callback
* @param null|array $params
* @param null|string $alias
* @return GeneratorInstance
* @throws Exception\InvalidCallbackException
*/
Expand Down Expand Up @@ -139,19 +143,27 @@ protected function resolveAndCallInjectionMethodForInstance($instance, $method,
$methodClass = $instance->getClass();
$callParameters = $this->resolveMethodParameters($methodClass, $method, $params, $alias, $methodIsRequired);

if ($callParameters !== false) {
if ($callParameters === false) {
$instance->addMethod(array(
'method' => $method,
'params' => $callParameters,
));
return true;
}

return false;
}

/**
* {@inheritDoc}
*/
protected function getClass($instance)
{
return $instance instanceof GeneratorInstance ? $instance->getClass() : get_class($instance);
if ($instance instanceof GeneratorInstance) {
/* @var $instance GeneratorInstance */
return $instance->getClass();
}

return parent::getClass($instance);
}
}
1 change: 0 additions & 1 deletion library/Zend/Di/ServiceLocator/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ public function getCodeGenerator($filename = null)
}

// Create instantiation code
$creation = '';
$constructor = $meta->getConstructor();
if ('__construct' != $constructor) {
// Constructor callback
Expand Down
3 changes: 3 additions & 0 deletions library/Zend/Di/ServiceLocator/GeneratorInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Zend\Di\ServiceLocator;

/**
* Container for methods and parameters used by by Di to create a particular instance
*/
class GeneratorInstance
{
/**
Expand Down

0 comments on commit f9d681b

Please sign in to comment.