/** * handle method * * @param \Codex\Contracts\Menus\Menu|\Codex\Menus\Menu $menu */ public function handle(Menu $menu, Project $project = null) { $menu->setAttribute('title', $project === null ? 'Pick...' : $project->getDisplayName()); $menu->setAttribute('subtitle', 'project'); foreach ($this->codex->projects->all() as $project) { # Add to menu $name = (string) $project->config('display_name'); $names = []; if (strpos($name, ' :: ') !== false) { $names = explode(' :: ', $name); $name = array_shift($names); } $href = $project->url(); $metas = compact('project'); $id = Str::slugify($name, '_'); if (!$menu->has($id)) { $node = $menu->add($id, $name, 'root', count($names) === 0 ? $metas : [], count($names) === 0 ? compact('href') : []); } $parentId = $id; while (count($names) > 0) { $name = array_shift($names); $id .= '::' . $name; $id = Str::slugify($id, '_'); if (!$menu->has($id)) { $node = $menu->add($id, $name, $parentId, $metas, count($names) === 0 ? compact('href') : []); } $parentId = $id; } } }
/** * Ref constructor. * * @param \Codex\Codex $codex * @param \Codex\Projects\Project $project * @param \Codex\Projects\Refs $refs * @param string $name */ public function __construct(Codex $codex, Project $project, Refs $refs, $name) { $this->setCodex($codex); $this->setFiles($project->getFiles()); $this->name = $name; $this->project = $project; $this->refs = $refs; $this->path = $project->path($name); $this->hookPoint('refs:construct', [$this]); $this->resolve(); $this->hookPoint('refs:constructed', [$this]); }
/** * Get the names of all enabled processors for this document * * @return array */ public function getEnabledProcessors() { $enabled = $this->project->config('processors.enabled', []); $enabled2 = $this->attr('processors.enabled', []); $disabled = $this->attr('processors.disabled', []); return array_diff(array_unique(array_merge($enabled, $enabled2)), $disabled); }
protected function resolveRefs() { // Scan refs (directories) and instaniate / add em to the collection $directories = $this->getFiles()->directories(); foreach ($directories as $directory) { /** @var Ref $ref */ $ref = $this->app->make('codex.ref', ['name' => $directory, 'project' => $this->project, 'refs' => $this]); $this->items->put($directory, $ref); // if the ref is a (semver) version, we add it to versions, so we can easily reference it laster (sort etc) if ($ref->isVersion()) { $this->versions[] = $ref; } elseif ($ref->isBranch()) { $this->branches[] = $ref; } } // Resolve default ref $defaultRef = $this->items->first()->getName(); // DEFAULT_FIRST_DIRECTORY switch ($this->project->config('default')) { case static::DEFAULT_AUTO: break; case static::DEFAULT_MASTER: $defaultRef = 'master'; break; case static::DEFAULT_LAST_VERSION: $defaultRef = collect($this->versions)->sort(function (Ref $one, Ref $two) { return version::gt($one->getVersion(), $two->getVersion()) ? -1 : 1; })->first()->getName(); break; case static::DEFAULT_FIRST_DIRECTORY: $defaultRef = $this->items->first()->getName(); break; case static::DEFAULT_CUSTOM: $defaultRef = $this->project->config('custom'); break; } $this->default = (string) $defaultRef; }
public function hasAccess(Project $project) { if ($project->config('auth.enabled', false) !== true) { return true; } $driverName = $project->config('auth.driver', config('codex-auth.default_driver')); if (!$this->isLoggedIn($driverName)) { return false; } $user = $this->getUser($driverName); $user->getGroups(); if (in_array($user->getEmail(), $project->config('auth.allow.emails', []), true)) { return true; } if (in_array($user->getNickname(), $project->config('auth.allow.usernames', []), true)) { return true; } $diff = count(array_diff($user->getGroups(), $allowedGroups = $project->config('auth.allow.groups', []))); if ($diff !== $allowedGroups) { return true; } return false; }
/** * This will get the configured macros. It merges (if defined) the global config, project config and document attributes. * * Project macros will overide global macros with the same name. * Document macros will overide project macros with the same name. * Other then that, everything will be merged/inherited. * * @return array The collected macros as id(used for regex) > handler(the class string name with @ method callsign) */ protected function getAllMacroDefinitions() { $tags = $this->codex->config('processors.macros', []); $tags = array_merge($tags, $this->project->config('processors.macros', [])); return array_merge($tags, $this->document->attr('processors.macros', [])); }
protected function hasEnabledAuth(Project $project) { return $project->config('auth.enabled', false) === true; }