Exemplo n.º 1
0
 public function write(IResource $resource)
 {
     $content = $this->serializer->serialize($resource);
     $path = TARGET_PATH . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR . $resource->getType();
     if (!file_exists($path)) {
         mkdir($path, 0777, true);
         sleep(1);
     }
     if (!$this->save($path . DIRECTORY_SEPARATOR . $resource->getName() . '.model', $content)) {
         mkdir($path, 0777, true);
         sleep(1);
         $this->save($path . DIRECTORY_SEPARATOR . $resource->getName() . '.model', $content);
     }
 }
Exemplo n.º 2
0
 public function read()
 {
     $resources = [];
     $files = scandir($this->path);
     foreach ($files as $file) {
         if (!in_array($file, ['.', '..'])) {
             $resource_data = $this->serializer->deserialize($this->path . DIRECTORY_SEPARATOR . $file);
             $resource = ResourceFactory::get($this->type);
             $resource->setData($resource_data);
             $resources[] = $resource;
         }
     }
     return $resources;
 }