On Tue, 4 Dec 2007, Falko Menge wrote:

> However the design with interfaces does not seem to be very elegant 
> because it would require a complete reimplementation of nearly all 
> features of the ezcReflection component in the Static Reflection 
> classes. Thus I propose a dependency injection approach:
>
> We could allow the injection of instances of external Reflection 
> implementations through the constructors of the ezcReflection classes. 
> Such an external Reflection implementation would have to extend the 
> PHP reflection classes as well as the ezcReflection does. If such an 
> instance is given the ezcReflection would leverage it as its data 
> source. Otherwise PHP Reflection would be utilized as usual. 
> Additional features of the external instance could also be leveraged 
> by forwarding calls via overloading.
> 
> class ezcReflectionClass extends ReflectionClass
> {
>      protected $class;
> 
>      /**
>       * @param string|object|ReflectionClass $argument
>       *        name, instance or ReflectionClass object of
>       *        the class to be reflected
>       */
>      public function __construct( $argument )
>      {
>          if ( !$argument instanceof ReflectionClass )
>          {
>              parent::__construct($argument);
>          }
>       $this->class = $argument;
>       ...
>      }

We already do some form of dependency injection in some places, most 
notable where we return classes. Take for example this example from 
DatabaseSchema:

http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchema.html#setOptions
and
http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaOptions.html

or the mailClass property of the ezcMailParser:
http://ezcomponents.org/docs/api/trunk/Mail/ezcMailParserOptions.html#prop-$mailClass
example is:
http://ezcomponents.org/docs/api/trunk/Mail/ezcMailParserOptions.html#prop-$mailClass
(first example).

In those cases, we don't really have to make if () statements to figure 
out which part to call, but just juse this classname. Something similar 
can be done for compatible implementations of reflection, without 
actually having to wrap it like you do above.

regards,
Derick
-- 
Components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/components

Reply via email to