Exemple #1
0
 /**
  * @desc Class contructor
  * @param object IDependencyInjectionContainer instance
  * @access public
  */
 public function __construct(IDependencyInjectionContainer $DI)
 {
     $this->_DI = $DI;
     $this->_db = $DI->getDb();
     $this->_messenger = $DI->getMessenger();
     $this->_lang = $DI->getLanguage(get_called_class());
 }
 protected function setUp()
 {
     $this->object = new ComponentArgument('my_component_key');
     $this->against = new WeakPunch();
     $this->container = $this->getMock('IDependencyInjectionContainer');
     $this->container->expects($this->any())->method('getInstanceOf')->will($this->returnValue($this->against));
 }
 /**
  * Resolve the Component string into an Object instance.
  *
  * @param IDependencyInjectionContainer $container
  * @param IComponentAdapter $adapter
  * @return mixed
  */
 public function resolve(IDependencyInjectionContainer $container, IComponentAdapter $adapter)
 {
     $instance = $container->getInstanceOf($this->component);
     if (is_null($instance)) {
         throw new InjecteeArgumentException("Cannot create '{$this->component}' component, reffered to by '{$adapter->getKey()}' component");
     }
     return $instance;
 }
 /**
  * Resolve the constant value.
  *
  * @param IDependencyInjectionContainer $container
  * @param IComponentAdapter $adapter
  * @return mixed
  */
 public function resolve(IDependencyInjectionContainer $container, IComponentAdapter $adapter)
 {
     $value = $container->getConstant($this->constantId);
     if (is_null($value)) {
         throw new InjecteeArgumentException("No constant with id {$this->constantId} found!");
     }
     return $value;
 }
Exemple #5
0
 /**
  * Constructor
  *
  * @param string $actionType Type of action available
  * @param object $DI Instance of IDependencyInjectionContainer object
  */
 public function __construct($actionType, IDependencyInjectionContainer $DI)
 {
     $this->targetType = StringTools::filterPath($actionType);
     // Get language configuration
     $this->_lang = $DI->getLanguage('Action');
     // Get form helper
     $this->_form = new Form($DI);
 }
Exemple #6
0
 /**
  * Constructor
  *
  * @param object $DI Instance of an IDependencyInjectionContainer
  */
 public function __construct(IDependencyInjectionContainer $DI)
 {
     $this->_sessionManager = $DI->getSessionManager();
     // Clean session
     $config = $DI->getConfigurator();
     $this->cleanFormTokens($config->get('formToken.TTL', 30) * 60);
     // Initialize field types list
     $this->_fieldTypes = array('text' => 'text', 'email' => 'text', 'password' => 'password', 'hidden' => 'hidden', 'honeypot' => 'hidden', 'submit' => 'submit', 'select' => 'select');
 }
Exemple #7
0
 /**
  * Constructor
  *
  * @param int $id ID of the item
  * @param object $DI Instance of IDependencyInjectionContainer
  */
 public function __construct($id, IDependencyInjectionContainer $DI)
 {
     $this->_data['ID'] = $id;
     $this->_data['actions'] = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
     // Get language configuration
     $this->_lang = $DI->getLanguage(get_called_class());
     // Get form helper
     $this->_form = new Form($DI);
     parent::__construct($DI);
 }
Exemple #8
0
 /**
  * Constructor, initialize the member vars. Then call the action found in the query string.
  *
  * @param object An instance of an IDependencyInjectionContainer object.
  *
  * @access public
  */
 public function __construct(IDependencyInjectionContainer $DI)
 {
     $this->_DI = $DI;
     // Load user
     $this->_user = new User($DI);
     // Register configuration
     $this->_config = $DI->getConfigurator();
     // Get language configuration
     $this->_lang = $DI->getLanguage(get_called_class());
     // Get message manager
     $this->_messenger = $DI->getMessenger();
     // Get form helper
     $this->_form = new Form($DI);
 }
 /**
  * Resolve arguments of ReflectionMethod by their optionality or class name.
  *
  * If argument is optional and it's default value is supplied,
  * use its default value. Else the argument must be a Class or Interface,
  * so the container is able to instantiate and provide proper values.
  *
  * @param IDependencyInjectionContainer $container
  * @param ReflectionMethod $method
  * @return array of mixed
  */
 protected function getArgumentsOfMethod(IDependencyInjectionContainer $container, ReflectionMethod $method)
 {
     $result = array();
     $parameters = $method->getParameters();
     foreach ($parameters as $parameter) {
         if ($parameter->isOptional() || $parameter->isDefaultValueAvailable()) {
             $result[] = $parameter->getDefaultValue();
         } else {
             $parameterClass = $parameter->getClass();
             if (!$parameterClass) {
                 throw new InjecteeArgumentException("Argument '{$parameter->getName()}' cannot be instantiated, it is either a Value or an Unknown type");
             }
             $result[] = $container->getInstanceOf($parameterClass->getName());
         }
     }
     return $result;
 }
 public function testForward()
 {
     $route = $this->getMock('IRoute');
     $route->expects($this->once())->method('setPackage')->will($this->returnValue($route));
     $route->expects($this->once())->method('setController')->will($this->returnValue($route));
     $route->expects($this->once())->method('setAction')->will($this->returnValue($route));
     $route->expects($this->once())->method('setParameters')->will($this->returnValue($route));
     $request = $this->getMock('IRequest');
     $runner = $this->getMock('IControllerRunner');
     $runner->expects($this->once())->method('run')->with($this->equalTo($route))->will($this->returnValue('ok'));
     $this->container->expects($this->exactly(3))->method('getInstanceOf')->will($this->onConsecutiveCalls($route, $request, $runner));
     $this->assertThat($this->object->forward('package', 'controller', 'action', array('params')), $this->equalTo('ok'));
 }
Exemple #11
0
 /**
  * Constructor
  *
  * @param oject $DI Instance of IDependencyInjectionContainer
  */
 public function __construct(IDependencyInjectionContainer $DI)
 {
     $this->_lang = $DI->getLanguage('ActionLog');
 }