Ejemplo n.º 1
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.º 2
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.º 3
0
 private static function loadFileJson(File $file)
 {
     return json_decode($file->getContent(), true);
 }