public function handle() { $this->http = new HTTP(new Slice()); $request = $this->request(); $q = $request->query()->get('q'); if (!$q) { $this->response(['error' => '?q must be specified!'], 500); } $repo = new Repository(); $repo->setDriver(new DatabaseDriver(Application::getInstance()->getConnection())); $path_info = explode('/', $q); $type = $path_info[0]; if ('locks' === $type) { $this->response(['locked' => $repo->isLocked()]); return; } if (!$type || !in_array($type, ['chunk', 'snippet', 'content', 'tv', 'template', 'category'])) { $this->response(['error' => 'Type must be specified!'], 500); } $pk = count($path_info) > 1 ? $path_info[1] : null; if ('GET' === $request->method()) { if (!$pk) { $items = $repo->getAll($type); $this->response(array_map(function ($item) { return $item->getData(); }, $items)); } else { $this->response($repo->getOnce($type, $pk)->getData()); } } elseif ('POST' === $request->method()) { } }
/** * Load resources all types from local database * * @return mixed */ public function loadLocal() { $repository = new Repository(); $driver = new DatabaseDriver($this->getDatabaseConnection()); $repository->setDriver($driver); foreach (ResourceType::asArray() as $type) { $resources = $repository->getAll($type); $writer = FilesystemFactory::getWriter($type); foreach ($resources as $resource) { $writer->write($resource); } } return []; }