예제 #1
0
 public static function config($path)
 {
     static $config;
     if ($config === NULL) {
         $configFile = __DIR__ . '/' . 'Config.php';
         if (!file_exists($configFile)) {
             throw new \Exception('Configuration file not found, please create app/Config.php to continue.');
         }
         $config = new DotData(require $configFile);
     }
     return $config->get($path);
 }
예제 #2
0
 /**
  * @param $association
  * @param ClassMetadataInfo $meta
  * @param $instance
  * @param Data $params
  * @throws \Doctrine\ORM\Mapping\MappingException
  */
 private function handleAssociation($association, ClassMetadataInfo $meta, $instance, Data $params)
 {
     $data = $params->get($association);
     if (is_array($data) && isset($data[0])) {
         foreach ($data as $index => $set) {
             $assoc = $this->getAssocicationHandler($association, $meta);
             $assoc->handle($association, $meta, $instance, new Data([$association => $set]));
         }
     } else {
         $assoc = $this->getAssocicationHandler($association, $meta);
         $assoc->handle($association, $meta, $instance, $params);
     }
 }
 public function handle($association, ClassMetadataInfo $meta, $instance, Data $params)
 {
     if ($params->get($association) === null) {
         return;
     }
     $this->association = $association;
     $this->meta = $meta;
     $this->instance = $instance;
     $this->params = $params;
     switch (true) {
         case $this->isSelfReferential():
             $this->selfReferential();
             break;
         case $this->isUniDirectional():
             $this->uniDirectional();
             break;
         case $this->isBiDirectional():
             $this->biDirectional();
             break;
     }
 }
예제 #4
0
 /**
  * Returns the value of option
  *
  * @param string $name Name of option
  * @param mixed $default Default value
  * @return array|mixed|null Value of option
  */
 public function getOption($name, $default = null)
 {
     $data = new Data((array) get_option($this->registry['option_name']));
     return $data->get($name, $default);
 }
 /**
  * Return a translation string from files using dot notation
  *
  * @param $id
  * @param string $lang
  * @param null $default
  * @return array|mixed|null
  */
 public function get_translation($id, $lang = 'en', $default = null)
 {
     PerchUtil::debug('Using translation: ' . $lang . '.' . $id, 'success');
     return $this->translations->get($lang . '.' . $id, $default ? $default : $id);
 }
예제 #6
0
 /**
  * Validate defined rules in app
  * @return bool
  * @throws SyntaxException
  */
 public final function validate()
 {
     // validate csrf token if required
     if ($this->_tokenRequired && !$this->_tokenOk) {
         App::$Session->getFlashBag()->add('warning', __('Hack attention: security token is wrong!'));
         return false;
     }
     // get all rules as array from method rules()
     $rules = $this->rules();
     // get default values of attributes
     $defaultAttr = $this->getAllProperties();
     // start validation: on this step class attribute values will be changed to input data if it valid
     $success = $this->runValidate($rules);
     // get not-passed validation fields as array
     $badAttributes = $this->getBadAttribute();
     // prevent warnings
     if (Obj::isArray($badAttributes) && count($badAttributes) > 0) {
         foreach ($badAttributes as $attr) {
             if (Str::contains('.', $attr)) {
                 // sounds like dot-separated array attr
                 $attrName = strstr($attr, '.', true);
                 // get attr name
                 $attrArray = trim(strstr($attr, '.'), '.');
                 // get dot-based array path
                 $defaultValue = new DotData($defaultAttr);
                 // load default attr
                 $dotData = new DotData($this->{$attrName});
                 // load local attr variable
                 $dotData->set($attrArray, $defaultValue->get($attr));
                 // set to local prop. variable default value
                 $this->{$attrName} = $dotData->export();
                 // export to model
             } else {
                 $this->{$attr} = $defaultAttr[$attr];
                 // just set ;)
             }
             // add message about wrong attribute to session holder, later display it
             $attrLabel = $attr;
             if ($this->getLabel($attr) !== null) {
                 $attrLabel = $this->getLabel($attr);
             }
             App::$Session->getFlashBag()->add('warning', __('Field "%field%" is incorrect', ['field' => $attrLabel]));
         }
     }
     return $success;
 }
예제 #7
0
 /**
  * Return a config value.
  *
  * @param string $key
  * @param string $default
  *
  * @return array|mixed|null
  */
 public function get($key, $default = '')
 {
     return $this->data->get($key, $default);
 }