public function __construct($file, $library) { $this->file = $file; $this->parent = $library; $this->path = $file->getPathname(); $this->name = preg_replace('/\\.[^\\.]+$/', '', basename($this->path)); $this->size = $file->getSize(); $this->modified = Carbon::createFromTimestamp($file->getMTime()); $this->fingerprint = md5($this->path); $this->parse(); $this->settings($this->yaml); $this->base = $this->parent->base; if (empty($this->slug)) { $this->slug = preg_replace("/^[\\d]+[\\_\\-]/", "", $this->name); } $this->slug = new Slug(MarkDb::sluggify($this->parent->slug . '/' . $this->slug), $this->base); $this->words = str_word_count(strip_tags($this->content())); }
/** * Set library settings based on path or existance of .markdb in directory */ public function settings() { if (is_file($this->path . '/.markdb')) { $attributes = \Symfony\Component\Yaml\Yaml::parse(file_get_contents($this->path . '/.markdb')); $this->attributes = $attributes; foreach ($attributes as $key => $value) { if (empty($this->{$key})) { $this->{$key} = $value; } } } if (!isset($this->slug)) { $this->slug = $this->name; } $this->base = empty($this->base) ? $this->parent() ? $this->parent()->base : false : $this->base; $this->slug = new Slug(MarkDb::sluggify(implode('/', array_filter([$this->parent ? $this->parent->slug : null, $this->slug]))), $this->base); if (!empty($this->date)) { $this->date = \Carbon\Carbon::createFromTimestamp(strtotime($this->date)); } }