Beispiel #1
0
 /**
  */
 public function loadSettings()
 {
     // Get directory path of app
     $files = array_diff(scandir($this->path), array('..', '.'));
     foreach ($files as $file) {
         $string = new CamelCase(explode('.', $file)[0]);
         $key = $string->uncamelize();
         $this->add($key, include $this->path . DIRECTORY_SEPARATOR . $file);
     }
 }
Beispiel #2
0
 /**
  * Returns the name of this app.
  *
  * @param bool $uncamelize
  *            Set this flag to true to get the apps name in an uncamelized format
  *
  * @return string
  */
 public function getName(bool $uncamelize = false)
 {
     if ($uncamelize == true) {
         $string = new CamelCase($this->name);
         return $string->uncamelize();
     } else {
         return $this->name;
     }
 }
Beispiel #3
0
 /**
  * Get a singleton app object
  *
  * @param string $name
  *            Name of app instance to get
  *
  * @return \Core\Framework\Amvc\App\AbstractApp
  */
 public function &getAppInstance(string $name)
 {
     if (empty($name)) {
         throw new AppHandlerException('AppHandler::getAppInstance() method needs a camelized appname.');
     }
     $string = new CamelCase($name);
     $name = $string->camelize();
     // App instances are singletons!
     if (!array_key_exists($name, $this->instances)) {
         // Create class name
         $class = '\\AppHandler\\' . $name . '\\' . $name;
         //
         $filename = BASEDIR . str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';
         if (!file_exists($filename)) {
             throw new AppHandlerException(sprintf('AppHandler could not find an app classfile "%s" for app "%s"', $name, $filename));
         }
         // Default arguments for each app instance
         $args = [$name, $this, $this->config->getStorage($name), 'core.page', 'core.di'];
         $instance = $this->di->instance($class, $args);
         if (!$instance instanceof AbstractApp) {
             throw new AppHandlerException('AppHandler must be an instance of AbstractApp class!');
         }
         $instance->setName($name);
         $this->instances[$name] = $instance;
     }
     return $this->instances[$name];
 }
Beispiel #4
0
 /**
  * Creates a formcontrol and adds it by it's name to the controls list.
  *
  * @param string $type
  *            The type of control to create
  * @param string $name
  *            Name of the control. Ths name is used to bind the control to a model field.
  *
  * @return \Core\Html\Form\AbstractForm
  */
 public function &addControl($control, $name = '', $label = '', $value = '', $description = '', $unbound = false)
 {
     $string = new CamelCase($control);
     $control = $this->factory->create('FormDesigner\\Controls\\' . $string->camelize() . 'Control');
     // Set name
     $control->setName($name);
     // set contols name
     if ($unbound && method_exists($control, 'setUnbound')) {
         $control->setUnbound();
         $control->removename();
     }
     // Label set?
     if (!empty($label) && method_exists($control, 'setLabel')) {
         $control->setLabel($label);
     }
     if (!empty($value) && method_exists($control, 'setValue')) {
         $control->setValue($value);
     }
     if (!empty($description) && method_exists($control, 'setDescription')) {
         $control->setDescription($description);
     }
     if ($control instanceof Button) {
         $control->noLabel();
     }
     // Create element
     $this->elementFactory('control', $control);
     return $control;
 }
Beispiel #5
0
 /**
  * Sets controller action
  *
  * @param string $action
  */
 public function setAction(string $action)
 {
     $string = new CamelCase($action);
     $this->action = $string->camelize();
 }
Beispiel #6
0
 /**
  * Shorthand method for a FormDesigner instance with auto attached model
  *
  * @return FormDesigner
  */
 protected function getFormDesigner($id = '')
 {
     /* @var $fd \Core\Html\FormDesigner\FormDesigner */
     $fd = new FormDesigner($this->app->getName(true));
     // Generate form id when id is not provided
     if (!$id) {
         $pieces = [];
         $string = new CamelCase($this->app->getName());
         $pieces[] = $string->uncamelize();
         $string->setString($this->name);
         $pieces[] = $string->uncamelize();
         // get calling method name
         $dbt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
         if (isset($dbt[1]['function'])) {
             $string->setString($dbt[1]['function']);
             $pieces[] = $string->uncamelize();
         }
         $id = implode('-', $pieces);
     }
     if ($id) {
         $fd->setId($id);
     }
     // Create forms eaction url
     if (isset($this->route)) {
         $fd->html->setAction($this->app->url($this->route, $this->params));
     }
     // Set session token
     $fd->setToken($this->di->get('core.security.form.token.name'), $this->di->get('core.security.form.token'));
     return $fd;
 }
Beispiel #7
0
 /**
  * Get a singleton app object
  *
  * @param string $name
  *            Name of app instance to get
  *
  * @return \Core\Framework\Amvc\App\AbstractApp
  */
 public function &getAppInstance(string $name)
 {
     if (empty($name)) {
         throw new FrameworkException('Core::getAppInstance() needs an app name');
     }
     $string = new CamelCase($name);
     $name = $string->camelize();
     // App instances are singletons!
     if (!array_key_exists($name, $this->apps)) {
         // Create class name
         $class = '\\Apps\\' . $name . '\\' . $name;
         //
         $filename = $this->basedir . str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';
         if (!file_exists($filename)) {
             throw new FrameworkException(sprintf('Apps could not find an app classfile "%s" for app "%s"', $name, $filename));
         }
         // Default arguments for each app instance
         $args = [$name, $this->config->createStorage($name), $this];
         $instance = $this->di->instance($class, $args);
         if (!$instance instanceof AbstractApp) {
             throw new FrameworkException('Apps must be an instance of AbstractApp class!');
         }
         $instance->setName($name);
         $instance->language->setCode($this->config->get('Core', 'site.language.default'));
         $this->apps[$name] = $instance;
     }
     return $this->apps[$name];
 }
Beispiel #8
0
 /**
  * Creates and returns a singleton rule object
  *
  * @param string $rule_name
  *            Name of the rule
  *
  * @return RuleInterface
  */
 public function &createRule($rule_name) : RuleInterface
 {
     // Make sure that the rules name is camelcased
     $string = new CamelCase($rule_name);
     $rule_name = $string->camelize();
     // Rules have to be singletons
     if (empty(self::$rules[$rule_name])) {
         // Without a leading \ in the rulename it is assumened that we use a Core FW builtin rule
         // otherwise the $rule_name points to a class somewhere outsite of the frameworks default rules.
         $rule_class = strpos($rule_name, '\\') == 0 ? __NAMESPACE__ . '\\Rules\\' . $rule_name . 'Rule' : $rule_name;
         // Create the rule obejct instance
         $rule_object = new $rule_class($this);
         // The rule object must be a child of RuleAbstract!
         if (!$rule_object instanceof RuleInterface) {
             throw new ValidatorException('Validator rules MUST be a either implement the \\Core\\Validator\\Rules\\RuleInterface or be an instance of \\Core\\Validator\\Rules\\AbstractRule which implements this interface.');
         }
         // Add rule to the rules stack
         self::$rules[$rule_name] = $rule_object;
     } else {
         // Reset existing rules
         self::$rules[$rule_name]->reset();
     }
     return self::$rules[$rule_name];
 }