Skip to content
eBuildy edited this page Jan 20, 2014 · 7 revisions

The Container is a Class automatically generated with:

  • Your Configuration parameters
  • Your Services
  • eBuildy framework Services

Configuration

Configuration is where you set your routes, data base parameters and all other parameters needed by your application (API keys etc..). eBuildy allows you to load YML files and read annotations from PHP files in order to build your Container.

Exemple of a YML file:

parameters:
  ebuildy:
    debug: true
    
  form:
    template_path: src/Kinou/Common/view/form/
    
  session:
    name: toto

  mailer:
    from: "toto <contact@toto.com>"
    login: contact@toto.com
    password: toto
          
  kloud:
    media_path: storage/media/
    cover_path: storage/cover/
    avatar_path: storage/avatar/

eBuildy does not support YML override stuff, due to potential configuration issue.

Services

This is the Dependency Injection stuff. The container will declare as public method "getNameOfMyService()" the PHP Class you want to load. You can use annotations to "map" a PHP Class to a service name, and the container builder will take care of the rest!

<?php

namespace Kinou\Common\Model;

/**
 * @Service("model.media")
 */
 class MediaModel
 {    
   /**
     * @Inject('security')
     */
     public $securityService;
  }

This will generate the following method in the container:

/**
* @public
* @return Kinou\Common\Model\MediaModel
*/
public function getModelMediaService() {
	if ($this->__modelMedia === null) {
		$this->__modelMedia = new Kinou\Common\Model\MediaModel();
		$this->__modelMedia->container = $this;
		$this->__modelMedia->securityService = $this->getSecurityService();
	}
	return $this->__modelMedia;
}

In opposite to other DIC (such as Symfony2), class autocompletion will work!

eBuildy framework Services

eBuildy provides some default services, such as routing, templating ... You have to add them when you build your container (or not if you want to override everything!).

How to build configuration ?

With the ContainerBuilder PHP Class, for instance:

$configuration = new ContainerBuilder();
    
$configuration  ->loadFile(CONFIG_PATH . $env .'/config.yml')
                        ->loadAnnotations(VENDOR_PATH.'ebuildy/ebuildy/src')
                        ->loadAnnotations(SOURCE_PATH.'Kinou', SOURCE_PATH)
                        ->build(TMP_PATH, 'Container');
        
die("Configuration has been done !");

As you can see, you can mix YML files and annotation very easily!