/** * @param string $moduleName * @param null|string $modulePath * @param null|string $namespace */ public function __construct($moduleName, $modulePath = NULL, $namespace = NULL) { if (empty($modulePath)) { $modulePath = base_path('modules/' . $moduleName); } $this->_path = File::normalizePath($modulePath); $this->_name = $moduleName; if (!is_null($namespace)) { $this->_namespace = $namespace; } }
function snippets_path() { return File::normalizePath(base_path('resources/snippets')); }
/** * @param string $dir directory name (views, i18n, classes, extensions, etc.) * @param string $file filename with subdirectory * @param string $ext extension to search for * @param boolean $array return an array of files? * @return array a list of files when $array is TRUE * @return string single file path */ public function findFile($dir, $file, $ext = null, $array = false) { if ($ext === null) { // Use the default extension $ext = '.php'; } elseif ($ext) { // Prefix the extension with a period $ext = ".{$ext}"; } else { // Use no extension $ext = ''; } // Create a partial path of the filename $path = File::normalizePath($dir . DIRECTORY_SEPARATOR . $file . $ext); if (isset(static::$files[$path . ($array ? '_array' : '_path')])) { // This path has been cached return static::$files[$path . ($array ? '_array' : '_path')]; } if ($array) { // Array of files that have been found $found = []; foreach ($this->getRegisteredModules() as $module) { $dir = $module->getPath() . DIRECTORY_SEPARATOR; if (is_file($dir . $path)) { // This path has a file, add it to the list $found[] = $dir . $path; } } } else { // The file has not been found yet $found = false; foreach ($this->getRegisteredModules() as $module) { $dir = $module->getPath() . DIRECTORY_SEPARATOR; if (is_file($dir . $path)) { // A path has been found $found = $dir . $path; // Stop searching break; } } } // Add the path to the cache static::$files[$path . ($array ? '_array' : '_path')] = $found; // Files have been changed static::$filesChanged = true; return $found; }
/** * @return bool * @throws Exception */ public function save() { if ($this->isReadOnly() and !$this->isNew()) { return false; } $status = true; if ($this->isNew()) { $newFilename = FileSystem::normalizePath($this->basePath . DIRECTORY_SEPARATOR . $this->changed['name']); $status = touch($newFilename) !== false; if ($status) { chmod($newFilename, 0777); $this->file = new SplFileObject($newFilename); } } else { if ($this->isChanged('name')) { $newFilename = FileSystem::normalizePath($this->getPath() . '/' . $this->changed['name']); $status = @app('files')->move($this->getRealPath(), $newFilename); if ($status) { $this->file = new SplFileObject($newFilename); } } } if ($status and $this->isChanged('content')) { $status = app('files')->put($this->getRealPath(), $this->changed['content']) !== false; } $this->changed = []; return $status; }
/** * @return string */ public function getSettingsFilePath() { return FileSystem::normalizePath($this->directory . DIRECTORY_SEPARATOR . '.settings.php'); }