Esempio n. 1
0
 /**
  * Document constructor.
  *
  * @param \Codex\Codex|\Codex\Contracts\Codex    $codex
  * @param \Codex\Projects\Project                $project
  * @param \Codex\Projects\Ref                    $ref
  * @param \Illuminate\Contracts\Cache\Repository $cache
  * @param                                        $path
  * @param                                        $pathName
  *
  * @throws \Codex\Exception\CodexException
  */
 public function __construct(Codex $codex, Project $project, Ref $ref, Repository $cache, $path, $pathName)
 {
     $this->setCodex($codex);
     $this->setFiles($project->getFiles());
     $this->ref = $ref;
     $this->project = $project;
     $this->path = $path;
     $this->pathName = $pathName;
     $this->cache = $cache;
     $this->extension = path_get_extension($path);
     $this->processed = new Collection();
     $this->hookPoint('document:construct', [$this]);
     #$this->codex->projects->hasActive() === false && $project->setActive();
     if (!$this->getFiles()->exists($this->getPath())) {
         throw CodexException::documentNotFound("{$this} in [{$project}]");
     }
     $this->attributes = $codex->config('default_document_attributes');
     $this->lastModified = $this->getFiles()->lastModified($this->getPath());
     $this->setCacheMode($this->getCodex()->config('document.cache.mode', self::CACHE_DISABLED));
     //$this->content = $this->getFiles()->get($this->getPath());
     $this->attr('view', null) === null && $this->setAttribute('view', $codex->view('document'));
     $this->hookPoint('document:constructed', [$this]);
 }
Esempio n. 2
0
 /**
  * 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);
 }