/** * Creates a new Document class * * @param \Docit\Core\Contracts\Factory $docit The factory class * @param \Illuminate\Contracts\Filesystem\Filesystem $files The filesystem * @param \Docit\Core\Project $project The project instance * @param \Illuminate\Contracts\Container\Container $container The container class * @param string $path The absolute path to the document * @param string $pathName The relative path to the document */ public function __construct(Factory $docit, Filesystem $files, Project $project, Container $container, $path, $pathName) { $this->container = $container; $this->docit = $docit; $this->project = $project; $this->files = $files; $this->path = $path; $this->pathName = $pathName; $this->runHook('document:ready', [$this]); $this->attributes = $docit->config('default_document_attributes'); $this->content = $this->files->get($this->path); $this->runHook('document:done', [$this]); }
/** * @param \Docit\Core\Factory $factory * @param \Illuminate\Contracts\Filesystem\Filesystem $files * @param \Illuminate\Contracts\Container\Container $container * @param string $name * @param array $config */ public function __construct(Factory $factory, Filesystem $files, Container $container, $name, $config) { $this->container = $container; $this->factory = $factory; $this->files = $files; $this->name = $name; $this->config = $config; $this->path = $path = Path::join($factory->getRootDir(), $name); $this->runHook('project:ready', [$this]); # Resolve refs $directories = $this->files->directories($this->path); $branches = []; $this->refs = []; $this->versions = array_filter(array_map(function ($dirPath) use($path, $name, &$branches) { $version = Str::create(Str::ensureLeft($dirPath, '/'))->removeLeft($path)->removeLeft(DIRECTORY_SEPARATOR); $version = (string) $version->removeLeft($name . '/'); $this->refs[] = $version; try { return new version($version); } catch (\RuntimeException $e) { $branches[] = $version; } }, $directories), 'is_object'); $this->branches = $branches; // check which version/branch to show by default $defaultRef = count($this->versions) > 0 ? head($this->versions) : head($branches); switch ($this->config['default']) { case Project::SHOW_LAST_VERSION: usort($this->versions, function (version $v1, version $v2) { return version::gt($v1, $v2) ? -1 : 1; }); $defaultRef = head($this->versions); break; case Project::SHOW_LAST_VERSION_OTHERWISE_MASTER_BRANCH: if (count($this->versions) > 0) { usort($this->versions, function (version $v1, version $v2) { return version::gt($v1, $v2) ? -1 : 1; }); } $defaultRef = count($this->versions) > 0 ? head($this->versions) : head($branches); break; case Project::SHOW_MASTER_BRANCH: $defaultRef = 'master'; break; case Project::SHOW_CUSTOM: $defaultRef = $this->config['custom']; break; } $this->ref = $this->defaultRef = (string) $defaultRef; # Resolve menu $this->runHook('project:done', [$this]); }