-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added unit tests, renamed OptionClassInterface to OptionsClassInterfa…
…ce, updated docs
- Loading branch information
Sandro Keil
committed
Nov 18, 2013
1 parent
72aaea5
commit 41c75e8
Showing
19 changed files
with
534 additions
and
34 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
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 |
---|---|---|
@@ -1,4 +1,114 @@ | ||
# AbstractConstructorOptionConfigFactory | ||
Use this factory for easy dependency injection in your instance via constructor. | ||
Use this factory for easy dependency injection to your instance via constructor. | ||
|
||
TODO | ||
## Single constructor argument | ||
Let's assume we have the following module configuration: | ||
|
||
```php | ||
return array( | ||
'cache_module' => array( | ||
'result_config' => array( | ||
'default' => array( | ||
'lifetime' => 50, | ||
'foo' => 'bar', | ||
... | ||
) | ||
) | ||
) | ||
... | ||
); | ||
``` | ||
|
||
We have also a class `ResultCache` with a single constructor argument like `public function __construct(array $config)`. So you can easily inject the above config to this class with this factory. | ||
|
||
|
||
```php | ||
use \Sake\EasyConfig\Service\AbstractConstructorOptionConfigFactory; | ||
|
||
class ResultCacheFactory extends AbstractConstructorOptionConfigFactory | ||
{ | ||
public function getModule() | ||
{ | ||
return 'cache_module'; | ||
} | ||
|
||
public function getScope() | ||
{ | ||
return 'result_config'; | ||
} | ||
|
||
public function getName() | ||
{ | ||
return 'default'; | ||
} | ||
|
||
protected function getInjectionType() | ||
{ | ||
return self::INJECTION_TYPE_SINGLE; | ||
} | ||
|
||
public function getClassName() | ||
{ | ||
return 'MyModule\Service\ResultCache'; | ||
} | ||
} | ||
``` | ||
|
||
## Multiple constructor arguments | ||
Let's assume we have the following module configuration: | ||
|
||
```php | ||
return array( | ||
'cache_module' => array( | ||
'result_config' => array( | ||
'default' => array( | ||
// first constructor argument | ||
'first' => array( | ||
'lifetime' => 50, | ||
'foo' => 'bar', | ||
), | ||
// second constructor argument | ||
'second' => array( | ||
'bar' => 'foo', | ||
), | ||
... | ||
) | ||
) | ||
) | ||
... | ||
); | ||
``` | ||
|
||
We have also a class `ResultCache` with two constructor arguments like `public function __construct(array $config, array $other)`. So you can easily inject the above config to this class with this factory. | ||
|
||
```php | ||
use \Sake\EasyConfig\Service\AbstractConstructorOptionConfigFactory; | ||
|
||
class ResultCacheFactory extends AbstractConstructorOptionConfigFactory | ||
{ | ||
public function getModule() | ||
{ | ||
return 'cache_module'; | ||
} | ||
|
||
public function getScope() | ||
{ | ||
return 'result_config'; | ||
} | ||
|
||
public function getName() | ||
{ | ||
return 'default'; | ||
} | ||
|
||
protected function getInjectionType() | ||
{ | ||
return self::INJECTION_TYPE_MULTI; | ||
} | ||
|
||
public function getClassName() | ||
{ | ||
return 'MyModule\Service\ResultCache'; | ||
} | ||
} | ||
``` |
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 |
---|---|---|
@@ -1,4 +1,55 @@ | ||
# AbstractOptionHydratorConfigFactory | ||
Use this factory for easy dependency injection in your instance via hydrator. | ||
|
||
TODO | ||
Let's assume we have the following module configuration: | ||
|
||
```php | ||
return array( | ||
'mymodule' => array( | ||
'myscope' => array( | ||
'default' => array( | ||
// setter/getter available for foo, time and date_format | ||
'foo' => 'bar', | ||
'time' => 5, | ||
'date_format' => 'Y-m-d' | ||
) | ||
) | ||
) | ||
... | ||
); | ||
``` | ||
|
||
You can easily inject the above options to an instance with this factory. | ||
|
||
```php | ||
use \Sake\EasyConfig\Service\AbstractOptionHydratorConfigFactory; | ||
|
||
class ResultCacheFactory extends AbstractOptionHydratorConfigFactory | ||
{ | ||
public function getModule() | ||
{ | ||
return 'mymodule'; | ||
} | ||
|
||
public function getScope() | ||
{ | ||
return 'myscope'; | ||
} | ||
|
||
public function getName() | ||
{ | ||
return 'default'; | ||
} | ||
|
||
public function getClassName() | ||
{ | ||
return 'MyModule\Service\ClassWithSetter'; | ||
} | ||
|
||
public function getHydrator(ServiceLocatorInterface $serviceLocator) | ||
{ | ||
// use service locator to retrieve other hydrators | ||
return new \Zend\Stdlib\Hydrator\ClassMethods(); | ||
} | ||
} | ||
``` |
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 |
---|---|---|
@@ -1,4 +1,50 @@ | ||
# AbstractServiceManagerConfigFactory | ||
This factory injects options to a service manager instance via a service manager config class. This is useful for plugin manager. | ||
Let's assume we have the following configuration: | ||
|
||
TODO | ||
```php | ||
return array( | ||
'mymodule' => array( | ||
'orm_manager' => array( | ||
'orm_default' => array( | ||
'invokables' => array( | ||
// '[short name]' => 'FCQN of doctrine service' | ||
), | ||
), | ||
), | ||
), | ||
); | ||
``` | ||
You can easily create a configured plugin manager with these options easily. The repository is injected via constructor. See test assets for details. | ||
|
||
```php | ||
use Sake\EasyConfig\Service\AbstractServiceManagerConfigFactory; | ||
|
||
class MyOrmManagerFactory extends AbstractServiceManagerConfigFactory | ||
{ | ||
public function getClassName() | ||
{ | ||
return 'MyModule\Service\OrmManager'; | ||
} | ||
|
||
public function getModule() | ||
{ | ||
return 'mymodule'; | ||
} | ||
|
||
public function getScope() | ||
{ | ||
return 'orm_manager'; | ||
} | ||
|
||
public function getName() | ||
{ | ||
return 'orm_default'; | ||
} | ||
|
||
public function getOptionClass() | ||
{ | ||
return 'MyModule\Service\Options\OrmManagerOptions'; | ||
} | ||
} | ||
``` |
Oops, something went wrong.