/** * {@inheritdoc} */ public function publish($filename, $destination, $merge = self::FOLLOW, $mode = FilesInterface::READONLY) { if (!$this->files->isFile($filename)) { throw new PublishException("Given '{$filename}' is not valid file."); } //wtf? always empty if (empty($relativeFilename)) { $relativeFilename = $this->files->normalizePath($this->files->relativePath($filename, $this->directories->directory('root'))); } //wtf? if (empty($relativeDestination)) { $relativeDestination = $this->files->relativePath($destination, $this->directories->directory('root')); } if ($this->files->exists($destination)) { if ($this->files->md5($destination) == $this->files->md5($filename)) { $this->logger()->debug("File '{relativeFilename}' already published and latest version.", compact('relativeFilename', 'destination')); //Nothing to do return; } if ($merge == self::FOLLOW) { //We are not allowed to replace file $this->logger()->warning("File '{relativeFilename}' already published and can not be replaced.", compact('relativeFilename', 'destination')); return; } } $this->logger()->info("Publish file '{relativeFilename}' to '{relativeDestination}'.", compact('relativeFilename', 'relativeDestination')); $this->ensureDirectory(dirname($destination), $mode); $this->files->copy($filename, $destination); $this->files->setPermissions($destination, $mode); }
/** * {@inheritdoc} */ public function fileReflection($filename) { $fileMD5 = $this->files->md5($filename = $this->files->normalizePath($filename)); $reflection = new ReflectionFile($this->fetchTokens($filename), (array) $this->memory->loadData($fileMD5, self::MEMORY_LOCATION)); //Let's save to cache $this->memory->saveData($fileMD5, $reflection->exportSchema(), static::MEMORY_LOCATION); return $reflection; }
/** * List of core directories with normalized paths, longest directories first. * * @return array */ private function getDirectories() { $directories = $this->core->getDirectories(); foreach ($directories as &$directory) { $directory = $this->files->normalizePath($directory); unset($directory); } //Sorting to get longest first uasort($directories, function ($valueA, $valueB) { return strlen($valueA) < strlen($valueB); }); return $directories; }
/** * @param ContainerInterface $container * @param FilesInterface $file * @param ModuleManager $modules * @param string $class * @param string $name * @param string $description * @param array $dependencies */ public function __construct(ContainerInterface $container, FilesInterface $file, ModuleManager $modules, $class, $name, $description = '', $dependencies = []) { $this->container = $container; $this->files = $file; $this->modules = $modules; $this->class = $class; $this->name = $name; $this->description = $description; $this->dependencies = $dependencies; //By default we will user module class directory $this->location = $this->files->normalizePath(dirname((new \ReflectionClass($this->class))->getFileName())); }
/** * Find view file specified by namespace and view name and associated engine id. * * @param string $namespace * @param string $view * @param string $engine Found engine id, reference. * @return string * @throws ViewException */ public function getFilename($namespace, $view, &$engine = null) { if (!isset($this->namespaces[$namespace])) { throw new ViewException("Undefined view namespace '{$namespace}'."); } //This part better be cached one dat foreach ($this->namespaces[$namespace] as $directory) { foreach ($this->config['engines'] as $engine => $options) { foreach ($options['extensions'] as $extension) { $candidate = $directory . FilesInterface::SEPARATOR . $view . '.' . $extension; if ($this->files->exists($candidate)) { return $this->files->normalizePath($candidate); } } } } throw new ViewException("Unable to find view '{$view}' in namespace '{$namespace}'."); }
/** * Request new migration filename based on user input and current timestamp. * * @param string $name * @return string */ private function createFilename($name) { $name = Inflector::tableize($name); $filename = \Spiral\interpolate(self::FILENAME_FORMAT, ['timestamp' => date(self::TIMESTAMP_FORMAT), 'chunk' => $this->chunkID++, 'name' => $name]); return $this->files->normalizePath($this->config->getDirectory() . '/' . $filename); }
/** * Generate config filename using config directory and config name. PHP extension will be added * here. * * @param string $directory * @param string $name * @return string */ private function configFilename($directory, $name) { return $this->files->normalizePath($directory . FilesInterface::SEPARATOR . $this->name . '.' . Core::EXTENSION); }
/** * @param FilesInterface $files * @param string $directory * @param string $extension */ public function __construct(FilesInterface $files, $directory, $extension = 'cache') { $this->directory = $files->normalizePath($directory); $this->extension = $extension; $this->files = $files; }