Example #1
0
 public function bind(\ntentan\Controller $controller, $type)
 {
     if ($type == 'ntentan\\Model') {
         $type = InjectionContainer::singleton(\ntentan\nibii\interfaces\ClassResolverInterface::class)->getModelClassName($controller->getWyfPackage(), null);
     }
     return parent::bind($controller, $type);
 }
Example #2
0
 public static function get($type)
 {
     if (isset(self::$binders[$type])) {
         return self::getCustomBinder(self::$binders[$type]);
     } else {
         return InjectionContainer::singleton(ModelBinderInterface::class);
     }
 }
Example #3
0
 public function getModelInstance()
 {
     if (!$this->setup) {
         $this->runSetup();
         $this->setup = true;
     }
     return InjectionContainer::resolve(Nibii::getClassName($this->options['model'], $this->type));
 }
Example #4
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';
     }
 }
Example #5
0
File: Wyf.php Project: ntentan/wyf
 public static function init($parameters = [])
 {
     Router::mapRoute('wyf_auth', 'auth/{action}', ['default' => ['controller' => controllers\AuthController::class]]);
     Router::mapRoute('wyf_api', 'api/{*path}', ['default' => ['controller' => controllers\ApiController::class, 'action' => 'rest']]);
     Router::mapRoute('wyf_main', function ($route) {
         $routeArray = explode('/', $route);
         $routeDetails = self::getController($routeArray, realpath(__DIR__ . '/../../../../src/app/'), \ntentan\Ntentan::getNamespace() . '\\app');
         return $routeDetails;
     }, ['default' => ['action' => 'index']]);
     TemplateEngine::appendPath(realpath(__DIR__ . '/../views/layouts'));
     TemplateEngine::appendPath(realpath(__DIR__ . '/../views'));
     AssetsLoader::appendSourceDir(realpath(__DIR__ . '/../assets'));
     View::set('wyf_app_name', $parameters['short_name']);
     InjectionContainer::bind(ModelClassResolver::class)->to(ClassNameResolver::class);
     InjectionContainer::bind(ControllerClassResolver::class)->to(ClassNameResolver::class);
 }
Example #6
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;
 }
Example #7
0
 /**
  * Create a new instance of this Model
  * @return \ntentan\nibii\RecordWrapper
  */
 public static function createNew()
 {
     $class = get_called_class();
     return InjectionContainer::resolve($class);
 }
Example #8
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;
 }
Example #9
0
 public function tearDown()
 {
     \ntentan\atiaa\Db::reset();
     \ntentan\panie\InjectionContainer::resetSingletons();
 }
 private function getJunctionModel()
 {
     return InjectionContainer::resolve($this->options['junction_model']);
 }
Example #11
0
File: Db.php Project: ntentan/atiaa
 public static function getConnection($parameters)
 {
     Config::set('ntentan:db', $parameters);
     return InjectionContainer::resolve(self::getDriverClassName($parameters['driver']));
 }
Example #12
0
 public static function setupDefaultBindings()
 {
     InjectionContainer::bind(interfaces\ModelJoinerInterface::class)->to(Resolver::class);
     InjectionContainer::bind(interfaces\TableNameResolverInterface::class)->to(Resolver::class);
     InjectionContainer::bind(interfaces\ModelClassResolverInterface::class)->to(Resolver::class);
 }
Example #13
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;*/
 }
Example #14
0
 public function executeControllerAction($action, $params)
 {
     $name = $this->getName();
     $path = Text::camelize($action);
     $return = null;
     $invokeParameters = [];
     if ($methodDetails = $this->getMethod($path)) {
         panie\InjectionContainer::bind(controllers\ModelBinderInterface::class)->to($methodDetails['binder']);
         $method = new \ReflectionMethod($this, $methodDetails['name']);
         honam\TemplateEngine::prependPath("views/{$name}");
         if (View::getTemplate() == null) {
             View::setTemplate("{$name}_{$action}" . '.tpl.php');
         }
         $methodParameters = $method->getParameters();
         foreach ($methodParameters as $methodParameter) {
             $this->bindParameter($invokeParameters, $methodParameter, $params);
         }
         $method->invokeArgs($this, $invokeParameters);
         $return = View::out();
         echo $return;
         return;
     } else {
         foreach ($this->loadedComponents as $component) {
             //@todo Look at how to prevent this from running several times
             if ($component->hasMethod($path)) {
                 $component->executeControllerAction($path, $params);
                 return;
             }
         }
     }
     throw new exceptions\ControllerActionNotFoundException($this, $path);
 }
Example #15
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;
 }
Example #16
0
 public static function getRouter()
 {
     return panie\InjectionContainer::singleton(controllers\RouterInterface::class);
 }
Example #17
0
 /**
  * Returns an instance of the current caching backend.
  * 
  * @return \ntentan\kaikai\CacheBackendInterface
  */
 private static function getInstance()
 {
     return \ntentan\panie\InjectionContainer::singleton(self::$backendClass);
 }
Example #18
0
 public function tearDown()
 {
     InjectionContainer::reset();
 }