|
Project Information
Links
|
sfIocPlugin - IoC container for Symfony frameworkDescriptionsfIocPlugin implements IoC container in PHP and provide easy integration with Symfony Framework. Plugin is inspired by Spring framework IoC container (http://www.springframework.org/), but IS NOT AN ONE-TO-ONE COPY. IoC container is useful for business logic layer implementations and adds more flexibility to your applications. FeaturesThis plugin is a very basic implementation of IoC, but it is enough for solving typical architecture problems.
Requirements
Example
/*
* @Singleton
/
class UserLogic
{
/*
* @Inject
*/
public function __construct(DataFinder $finder)
{
$this->finder = $finder;
}
public function authorize($login, $password)
{
$is_auth = $this->finder
->from('UserAccount')
->where('login',$login)
->where('password'=>$password)
->count() > 0;
if($is_auth)
{
// authorize
}
return $is_auth;
}
}
Bean configuration:
all: # for all environments
UserLogic: { class: DefaultUserLogic }
DataFinder: { class: DBFinder }
test: # for test environment
DataFinder: { class: testFinder } # redeclare DataFinder in test env for unit testing without database
Calling bean methods:
$api = sfContext::getInstance()->get('DefaultBeanFactory')->getBean('UserLogic');
if($api->authorize('john_doe', 'secure'))
{
// secure stuff here
}
|