Exemple #1
0
 /**
  * Load config file
  *
  * Get array from config file and save it to variable
  *
  * @static
  * @access   public
  * @param    string $sConfigPath
  * @param    string $sFormat
  * @return   bool
  * @throws   Exception
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 private static function load($sConfigPath, $sFormat = 'php')
 {
     $oConfigData = static::findConfigFile($sConfigPath, $sFormat);
     // load config data
     if ($oConfigData !== FALSE) {
         switch ($sFormat) {
             # PHP
             case 'php':
                 $aConfig = (include $oConfigData->getPath());
                 break;
                 # YAML
             # YAML
             case "yml":
                 $aConfig = \Spyc::YAMLLoad($oConfigData->getPath());
                 break;
         }
     }
     // assign data to storage
     if (isset($aConfig)) {
         Helper\Arrays::createMultiKeys(static::$aConfigs, $sConfigPath, $aConfig);
         unset($aConfig);
         Log::insert('Config ' . $sConfigPath . ' (' . $sFormat . ') loaded');
         return TRUE;
     }
     // if there is no data to assign (because the config file does not exists), create ERROR message and return FALSE (or throw exception)
     $sMsg = 'Unable to load ' . $sConfigPath . ' config file with "' . $sFormat . '" format.';
     Log::insert($sMsg, Log::ERROR);
     if (Core::getAppMode() === Core::MODE_DEVELOPMENT) {
         throw new Exception($sMsg);
     }
     return FALSE;
 }
Exemple #2
0
 /**
  * Method is called by Form object when this particular form is used (sent).
  *
  * @access   protected
  * @throws   Exception\Fatal
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 protected function whenFormSubmitted()
 {
     // get sent data
     $sentFileData = $this->getSentFileArray();
     // loop trough all sent data
     foreach ($sentFileData as $sLang => $allDefaultValuesForLang) {
         foreach ($allDefaultValuesForLang as $i => $dataBatch) {
             // create file broker (if not exists)
             $broker = Arrays::path($this->aFileBrokers, $sLang . '.' . $i, FALSE);
             if ($broker === FALSE) {
                 $parent = $this->isMultilanguage() ? $this->getFormObject()->getModel()->getLocales() : $this->getFormObject()->getModel();
                 $broker = new $this->sBrokerModel();
                 /* @var $broker ModelCore\FileBroker */
                 if (!$broker instanceof ModelCore\FileBroker) {
                     throw new Exception\Fatal('Given bad class name (`' . get_class($broker) . '`). ' . 'Not a `ModelCore\\FileBroker` class.');
                 }
                 $broker->setParent($parent);
             }
             // if file was uploaded earlier and is in "temporary file" field
             $formValues = $this->getFormObject()->getMethodValue();
             $tempValue = Arrays::get($formValues, 'temp_file_' . $this->getName() . '_' . $sLang . '_' . $i);
             if (!empty($tempValue)) {
                 $oFile = DB::find('\\Model\\File', $tempValue);
                 /* @var $oFile \Model\File */
                 Arrays::createMultiKeys($this->aFileTemp, $sLang . '.' . $i, $oFile);
             }
             // if file has been sent by $_FILE method
             if (isset($dataBatch['tmp_name']) && $dataBatch['tmp_name'] !== '' && $dataBatch['size'] >= 0) {
                 $broker->setTempData($dataBatch);
             }
             // set file to filebroker
             $oFileForBroker = Arrays::path($this->aFileTemp, $sLang . '.' . $i, FALSE);
             if ($oFileForBroker !== FALSE) {
                 $broker->setFile($oFileForBroker);
             }
             // set broker as fields value
             Arrays::createMultiKeys($this->aFileBrokers, $sLang . '.' . $i, $broker);
             $this->setValue($broker, $i, $sLang);
         }
     }
 }
Exemple #3
0
 /**
  * Set field new value.
  *
  * @author     Krzysztof Trzos
  * @access     public
  * @param      mixed   $value
  * @param      integer $valueNumber
  * @param      string  $lang
  * @return     Field
  * @throws     Exception\Fatal
  * @since      1.0.0-alpha
  * @version    1.0.0-alpha
  */
 public function setValue($value, $valueNumber = NULL, $lang = NULL)
 {
     if ($valueNumber === NULL && $lang === NULL) {
         $this->values = $value;
     } else {
         if ($this->isMultilanguage() && !in_array($lang, Core::getLanguages())) {
             throw new Exception\Fatal('Wrong language parameter (' . $lang . ')! For multilanguage fields You must define valid language parameter.');
         }
         if ($lang !== NULL) {
             if ($this->isMultilanguage() && in_array($lang, Core::getLanguages()) || !$this->isMultilanguage() && $lang === 'und') {
                 Helper\Arrays::createMultiKeys($this->values, $lang . '.' . $valueNumber, $value);
             } else {
                 throw new Exception\Fatal('Wrong language parameter (' . $lang . ')!');
             }
         } elseif (is_array($value)) {
             foreach ($value as $sLangKey => $mValuePerLang) {
                 if ($this->isMultilanguage() && in_array($sLangKey, Core::getLanguages()) || !$this->isMultilanguage() && $sLangKey === 'und') {
                     Helper\Arrays::createMultiKeys($this->values, $sLangKey . '.' . $valueNumber, $mValuePerLang);
                 } else {
                     throw new Exception\Fatal('Wrong language parameter (' . $sLangKey . ')!');
                 }
             }
         }
         if ($lang === NULL) {
             $lang = 'und';
         }
         Helper\Arrays::createMultiKeys($this->values, $lang . '.' . $valueNumber, $value);
     }
     $this->getFormObject()->getValidator()->setValue($this->getName(), $this->values);
     $this->getFormObject()->getValidator()->setFieldLabel($this->getName(), $this->getLabel());
     return $this;
 }
Exemple #4
0
 /**
  * @static
  * @access   private
  * @param    array $data
  * @return   array
  * @since    1.2.0-dev
  * @version  1.2.0-dev
  */
 private static function dividePerLang(array $data)
 {
     $output = [];
     foreach ($data as $context => $translatons) {
         foreach ($translatons as $string => $translatedLangs) {
             foreach ($translatedLangs as $lang => $translated) {
                 Helper\Arrays::createMultiKeys($output, $lang . ':;:' . $string . ':;:' . $context, $translated, ':;:');
             }
         }
     }
     return $output;
 }
Exemple #5
0
 /**
  * Refactor errors from Validator.
  *
  * @access   protected
  * @return   boolean
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 protected function refactorErrors()
 {
     if ($this->getValidator()->hasErrors()) {
         $aErrors = $this->getValidator()->getErrors();
         foreach ($aErrors as $sField => $aErrorsForSingleValue) {
             $aExpl = explode(Validator::FIELD_NAME_SEPARATOR, $sField);
             if (count($aExpl) === 3) {
                 Helper\Arrays::createMultiKeys($this->fieldsErrors, implode('.', $aExpl), $aErrorsForSingleValue);
             }
         }
         return TRUE;
     }
     return FALSE;
 }