path = $path; $this->createdBy = new NullAccount(); $this->createdAt = new \DateTimeImmutable(); $this->source = new NullCollection(); } /** * Load info data from path. * * @return void * * @throws PathException this exception is thrown in case the info file path doesn't exist * * @since 1.0.0 */ public function load() : void { if (!\is_file($this->path)) { throw new PathException($this->path); } $contents = \file_get_contents($this->path); /** @var array $info */ $info = \json_decode($contents === false ? '[]' : $contents, true); if ($info === false) { return; } $this->title = $info['name']; $this->version = $info['version']; $this->website = $info['website']; $this->hasExport = $info['export']; $this->hasImport = $info['import']; } /** * Get info path * * @return string * * @since 1.0.0 */ public function getPath() : string { return $this->path; } /** * Get settings. * * @return ExchangeSetting[] * * @since 1.0.0 */ public function getSettings() : array { return $this->settings; } /** * Adding new setting. * * @param ExchangeSetting $setting Setting * * @return int * * @since 1.0.0 */ public function addSetting(ExchangeSetting $setting) : int { $this->settings[] = $setting; \end($this->settings); $key = (int) \key($this->settings); \reset($this->settings); return $key; } /** * Get array * * @return array * * @since 1.0.0 */ public function toArray() : array { return [ 'id' => $this->id, 'path' => $this->path, 'title' => $this->title, 'version' => $this->version, 'website' => $this->website, 'hasExport' => $this->hasExport, 'hasImport' => $this->hasImport, ]; } }