Esempio n. 1
0
 public function getModelInstance()
 {
     if (!$this->setup) {
         $this->runSetup();
         $this->setup = true;
     }
     return InjectionContainer::resolve(Nibii::getClassName($this->options['model'], $this->type));
 }
Esempio n. 2
0
 public function testMixedConstructor()
 {
     InjectionContainer::bind(TestInterface::class)->to(TestClass::class);
     $object = InjectionContainer::resolve(\ntentan\panie\tests\classes\MixedConstructor::class, ['string' => 'It is a string', 'number' => 2000]);
     $this->assertInstanceOf(TestClass::class, $object->getInterface());
     $this->assertEquals('It is a string', $object->getString());
     $this->assertEquals(2000, $object->getNumber());
 }
Esempio n. 3
0
 public function runSetup()
 {
     $model = InjectionContainer::resolve(Nibii::getClassName($this->options['model'], self::BELONGS_TO));
     if ($this->options['foreign_key'] == null) {
         $this->options['foreign_key'] = $model->getDescription()->getPrimaryKey()[0];
     }
     if ($this->options['local_key'] == null) {
         $this->options['local_key'] = Text::singularize($model->getTable()) . '_id';
     }
 }
Esempio n. 4
0
 public function bind(Controller $controller, $type, $name)
 {
     $this->bound = false;
     $object = \ntentan\panie\InjectionContainer::resolve($type);
     if (is_a($object, '\\ntentan\\Model')) {
         $fields = $this->getModelFields($object);
     } else {
         $fields = $this->getClassFields($object);
     }
     $requestData = Input::post() + Input::get();
     foreach ($fields as $field) {
         if (isset($requestData[$field])) {
             $object->{$field} = $requestData[$field] == '' ? null : $requestData[$field];
             $this->bound = true;
         }
     }
     return $object;
 }
Esempio n. 5
0
 /**
  * Create a new instance of this Model
  * @return \ntentan\nibii\RecordWrapper
  */
 public static function createNew()
 {
     $class = get_called_class();
     return InjectionContainer::resolve($class);
 }
Esempio n. 6
0
 private function loadController($params = [])
 {
     $controller = $params['controller'];
     $action = isset($params['action']) ? $params['action'] : null;
     // Try to get the classname based on router parameters
     $controllerClassName = InjectionContainer::singleton(interfaces\ControllerClassResolverInterface::class)->getControllerClassName($controller);
     // Try to resolve the classname
     $resolvedControllerClass = InjectionContainer::getResolvedClassName($controllerClassName);
     if ($resolvedControllerClass) {
         // use resolved class name
         $params['controller_path'] = $controller;
         $controllerInstance = InjectionContainer::resolve($controllerClassName);
     } else {
         if (class_exists($controller)) {
             // use controller class
             $controllerInstance = InjectionContainer::resolve($controller);
         } else {
             $this->attemptedControllers[] = $controllerClassName;
             return false;
         }
     }
     $this->routerVariables += $params;
     $controllerInstance->executeControllerAction($action, $params);
     return true;
 }
Esempio n. 7
0
File: Db.php Progetto: ntentan/atiaa
 public static function getConnection($parameters)
 {
     Config::set('ntentan:db', $parameters);
     return InjectionContainer::resolve(self::getDriverClassName($parameters['driver']));
 }
Esempio n. 8
0
 public static function load($path)
 {
     return InjectionContainer::resolve(self::getClassName($path));
 }
Esempio n. 9
0
 public static function getDefaultInstance()
 {
     return \ntentan\panie\InjectionContainer::resolve(DriverAdapter::class);
     /*$driver = Db::getDefaultSettings()['driver'];
       if ($driver) {
           $class = "\\ntentan\\nibii\\adapters\\" . Text::ucamelize($driver) . "Adapter";
           $instance = new $class();
       } else {
           throw new \Exception("No datastore specified");
       }
       return $instance;*/
 }
Esempio n. 10
0
 private function validate($data, $mode)
 {
     $valid = true;
     $validator = \ntentan\panie\InjectionContainer::resolve(ModelValidator::class, ['model' => $this->wrapper, 'mode' => $mode]);
     if (!$validator->validate($data)) {
         $valid = false;
     }
     if ($valid) {
         $valid = $this->wrapper->onValidate();
     }
     if ($valid === false) {
         $valid = $validator->getInvalidFields();
     }
     return $valid;
 }
Esempio n. 11
0
 private function getJunctionModel()
 {
     return InjectionContainer::resolve($this->options['junction_model']);
 }