/** * Gets a project by name * * @param string $name The project name * * @return \Codex\Projects\Project * @throws \Codex\Exception\CodexException */ public function get($name) { if (!$this->has($name)) { throw CodexException::projectNotFound((string) $name); } return parent::get($name); }
/** * Shorthand helper method for getting projects, refs or documents * * <strong>Example:</strong> * <code> * <?php * $projects = codex()->get('*'); # Codex\Projects\Projects * $project = codex()->get('codex'); # Codex\Projects\Project * $refs = codex()->get('codex/*'); # Codex\Projects\Refs * $ref = codex()->get('codex/!'); # Codex\Projects\Ref (default ref) * $ref = codex()->get('codex/master'); # Codex\Projects\Ref * $ref = codex()->get('codex/1.0.0'); # Codex\Projects\Ref * $documents = codex()->get('codex::index); # Codex\Documents\Document (from default ref) * $documents = codex()->get('codex/master::*'); # Codex\Documents\Documents * $document = codex()->get('codex/master::!'); # Codex\Documents\Document (default document) * $document = codex()->get('codex/master::index'); # Codex\Documents\Document * $document = codex()->get('codex/master::develop/hooks'); # Codex\Documents\Document * </code> * * <strong>Syntax:</strong> * {project?}/{$ref?}::{documentPath?} * * <strong>Special modifiers:</strong> * * = The collection (projects, refs or documents) * ! = The default of the collection (project, def or document) * * <strong>Syntax examples:</strong> * codex/master::getting-started/installation * * @param $query * * @return \Codex\Documents\Document|\Codex\Documents\Documents|\Codex\Projects\Project|\Codex\Projects\Projects * @throws \Codex\Exception\CodexException * @example * <?php * $projects = codex()->get('*'); # Codex\Projects\Projects * $project = codex()->get('codex'); # Codex\Projects\Project * $refs = codex()->get('codex/*'); # Codex\Projects\Refs * $ref = codex()->get('codex/!'); # Codex\Projects\Ref (default ref) * $ref = codex()->get('codex/master'); # Codex\Projects\Ref * $ref = codex()->get('codex/1.0.0'); # Codex\Projects\Ref * $documents = codex()->get('codex::index); # Codex\Documents\Document (from default ref) * $documents = codex()->get('codex/master::*'); # Codex\Documents\Documents * $document = codex()->get('codex/master::!'); # Codex\Documents\Document (default document) * $document = codex()->get('codex::!'); # Codex\Documents\Document (from default ref, default document) * $document = codex()->get('codex/master::index'); # Codex\Documents\Document * $document = codex()->get('codex/master::develop/hooks'); # Codex\Documents\Document */ public function get($query) { // project/ref::path/to/document $segments = explode('::', $query); $psegments = explode('/', $segments[0]); $projectName = $psegments[0]; $projectRef = isset($psegments[1]) ? $psegments[1] : false; $documentPathName = isset($segments[1]) ? $segments[1] : false; # # Projects / Project if ($projectName === '*') { // get('*') return $this->projects; } elseif ($projectName === '!') { $projectName = config('codex.default_project'); } if (false === $this->projects->has($projectName)) { throw CodexException::projectNotFound($projectName); } $project = $this->projects->get($projectName); # # Refs / Ref if ($projectRef === false) { if ($documentPathName === false) { // get('codex') return $project; } $projectRef = '!'; // make it so that the default ref will be chosen when using get('codex::path/to/document') } if ($projectRef === '*') { // get('codex/*') return $project->refs; } if ($projectRef === '!') { $ref = $project->refs->getDefault(); } else { if (false === $project->refs->has($projectRef)) { throw CodexException::refNotFound($projectRef); } $ref = $project->refs->get($projectRef); } if ($documentPathName === false) { // get('codex/!') // get('codex/ref') return $ref; } # # Documents / Document if ($documentPathName === '*') { return $ref->documents; } elseif ($documentPathName === '!') { $documentPathName = $project->config('index'); } elseif (false === $ref->documents->has($documentPathName)) { throw CodexException::documentNotFound($documentPathName); } return $ref->documents->get($documentPathName); }