Ejemplo n.º 1
0
 private function searchForInclude(&$arrayYaml = null)
 {
     if (empty($arrayYaml)) {
         $arrayYaml = $this->yamlarh->getArrayToReturn();
     }
     $includeYaml = null;
     foreach ($arrayYaml as $key => $value) {
         if (is_array($value) && $key !== $this->yamlarh->getParamaterKey() . $this->nodeName && count($value) > 0) {
             $includeYaml[$key] = $this->searchForInclude($value);
             continue;
         }
         if ($key !== $this->yamlarh->getParamaterKey() . $this->nodeName) {
             $includeYaml[$key] = $value;
             continue;
         }
         if (!is_array($value)) {
             $value = array($value);
         }
         $includeYaml = array();
         foreach ($value as $includeFile) {
             $currentFile = new File($this->yamlarh->getFilename());
             $includeFile = new File($includeFile);
             if (!$includeFile->isFile()) {
                 $includeFile->setFolder($currentFile->getFolder() . $includeFile->getFolder());
             }
             $yamlArh = $this->getNewYamlarh($includeFile->absolute());
             $includeYaml = array_merge($yamlArh->parse(), $arrayYaml, $includeYaml);
         }
         unset($includeYaml[$this->yamlarh->getParamaterKey() . $this->nodeName]);
     }
     return $includeYaml;
 }
 public function getFileCreation()
 {
     if (!$this->isInCloudFoundry()) {
         return null;
     }
     $file = new File(sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'db.ct');
     $file->createFolder();
     if (!$file->isFile()) {
         $file->setContent(0);
     }
     return $file;
 }
Ejemplo n.º 3
0
 /**
  * @return mixed
  * @throws BeanPropertyException
  * @throws \Arhframe\Util\UtilException
  */
 public function inject()
 {
     $data = $this->getData();
     $asArray = true;
     if (is_array($data)) {
         $file = $data['file'];
         $asArray = empty($data['asObject']) ? true : false;
     } else {
         $file = $data;
     }
     $file = $this->getFilePath($file);
     if ($file === null) {
         throw new BeanPropertyException("Error when injecting json in bean, file '%s' doesn't exist.", $file);
     }
     $file = new File($file);
     return json_decode($file->getContent(), $asArray);
 }
Ejemplo n.º 4
0
 private function loadFromFile($filename)
 {
     $currentFile = new File($this->yamlarh->getFilename());
     $file = new File($filename);
     if (!$file->isFile()) {
         $file->setFolder($currentFile->getFolder() . $file->getFolder());
     }
     if (!$file->isFile()) {
         throw new SphringException("Property file '%s' cannot be found.", $file->getName());
     }
     $properties = FileLoader::loadFile($file);
     if ($properties === null && in_array($file->getExtension(), self::$extIni)) {
         $ini = new \Zend_Config_Ini($file->absolute());
         $properties = $ini->toArray();
     } elseif ($properties === null) {
         return;
     }
     $this->injectInYamlarh($properties);
 }
Ejemplo n.º 5
0
 private function loadBeansFromCache()
 {
     $origFile = new File($this->getSphring()->getYamlarh()->getFilename());
     $this->cacheFileContext = new File(sys_get_temp_dir() . DIRECTORY_SEPARATOR . SphringCacheEnum::CACHE_FOLDER . DIRECTORY_SEPARATOR . sprintf(SphringCacheEnum::CACHE_FILE_BEAN, $origFile->getHash('md5')));
     if (!$this->cacheFileContext->isFile()) {
         return;
     }
     $origFile = new File($this->getSphring()->getYamlarh()->getFilename());
     if ($origFile->getTime() != $this->cacheFileContext->getTime()) {
         return;
     }
     $beans = unserialize($this->cacheFileContext->getContent());
     $this->getSphring()->setBeansObject($beans);
     $proxies = [];
     //fast table writing
     $key = array_keys($beans);
     $size = sizeOf($key);
     for ($i = 0; $i < $size; $i++) {
         $bean = $beans[$key[$i]];
         $proxies[$bean->getId()] = $bean->getObject();
     }
     $this->getSphring()->setProxyBeans($proxies);
 }
Ejemplo n.º 6
0
 private function cacheSphringBean()
 {
     $origFile = new File($this->sphring->getYamlarh()->getFilename());
     $cacheFileBean = new File(sys_get_temp_dir() . DIRECTORY_SEPARATOR . SphringCacheEnum::CACHE_FOLDER . DIRECTORY_SEPARATOR . sprintf(SphringCacheEnum::CACHE_FILE_BEAN, $origFile->getHash('md5')));
     if (!$this->cacheManager->isCacheSphringBean()) {
         if ($cacheFileBean->isFile()) {
             $cacheFileBean->remove();
         }
         return;
     }
     $origFile = new File($this->sphring->getYamlarh()->getFilename());
     if ($cacheFileBean->isFile() && $origFile->getTime() == $cacheFileBean->getTime()) {
         return;
     }
     $beans = $this->sphring->getBeansObject();
     $origFile = $this->sphring->getYamlarh()->getFilename();
     $time = $this->getTime();
     touch($origFile, $time);
     $cacheFileBean->setContent(serialize($beans));
     touch($cacheFileBean->absolute(), $time);
 }
Ejemplo n.º 7
0
 /**
  * @param $fileName
  * @param File $file
  * @throws \Exception
  */
 private function getFromImport($fileName, File $file)
 {
     if (is_file($fileName)) {
         $fileFinalName = $fileName;
     } else {
         $fileFinalName = $file->getFolder() . '/' . $fileName;
     }
     $fileTmp = new File($fileFinalName);
     if (!$fileTmp->isFile()) {
         $fileFinalName = $file->getFolder() . '/' . $fileName;
     }
     if (!is_file($fileFinalName)) {
         throw new \Exception("The yml file " . $file->absolute() . " can't found yml file " . $fileName . " for import");
     }
     $this->parseFile(new File($fileFinalName));
 }
Ejemplo n.º 8
0
 private static function loadFileJson(File $file)
 {
     return json_decode($file->getContent(), true);
 }