/** * Returns the registered projects. * * @return Project[] * The projects. * * @throws \commpress\Cli\Service\Database\Exception\DatabaseQueryException * If something goes wrong while querying the data. */ public function getProjects() { $result = $this->database->query('SELECT * FROM ' . self::TABLE_PROJECTS); if (!$result) { throw new DatabaseQueryException('Failed to load projects from database.'); } $projects = []; while ($row = $result->fetchArray(SQLITE3_ASSOC)) { $project = new Project(); // TODO: Get rid of the new operator (Builder-Pattern). $project->setId($row[Project::FIELD_ID]); $project->setFullName($row[Project::FIELD_NAME]); $project->setShortName($row[Project::FIELD_SHORT_NAME]); $project->setGitRepositoryUrl($row[Project::FIELD_REPOSITORY_URL]); $project->setVhostName($row[Project::FIELD_VHOST_NAME]); $projects[] = $project; } return $projects; }
/** * Creates a new Project entity and returns it. * * @param array $data * The project data. * * @return \commpress\Cli\Entity\Project * The new Project entity instance. */ public static function buildEntity(array $data) { $project = new Project(); if (!empty($data[Entity::FIELD_ID])) { $project->setId($data[Project::FIELD_ID]); } $project->setFullName($data[Project::FIELD_NAME]); $project->setShortName($data[Project::FIELD_SHORT_NAME]); $project->setGitRepositoryUrl($data[Project::FIELD_REPOSITORY_URL]); $project->setVhostName($data[Project::FIELD_VHOST_NAME]); return $project; }