public function setType($type) { if (in_array($type, ResourceType::asArray())) { $this->type = $type; } else { throw new Exception("Resource must be once of " . implode(', ', ResourceType::asArray())); } }
public function buildFromFiles() { /** @var $resource IResource **/ $repository = new Repository(); $driver = new DatabaseDriver($this->getDatabaseConnection()); $repository->setDriver($driver); foreach (ResourceType::asArray() as $type) { $repository->truncate($type); $reader = FilesystemFactory::getReader($type); $resources = $reader->read(); foreach ($resources as $resource) { $repository->add($resource); } // $resources = $repository->getAll($type); // $writer = FilesystemFactory::getWriter($type); // foreach ($resources as $resource) { // $writer->write($resource); // } } }