コード例 #1
0
 /**
  * @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;
     }
 }
コード例 #2
0
 public function find()
 {
     $route = $this->getRouter()->getCurrentRoute();
     // Get the file path from the request
     $file = $route->getParameter('file');
     $ext = $route->getParameter('ext');
     // Remove the extension from the filename
     if ($file = app('module.loader')->findFile('resources', $file, $ext)) {
         // Check if the browser sent an "if-none-match: <etag>" header, and tell if the file hasn't changed
         // Set the proper headers to allow caching
         $this->response;
         return (new Response(file_get_contents($file)))->header('Content-Type', File::mimeByExt($ext))->header('last-modified', date('r', filemtime($file)));
     } else {
         abort(404);
     }
 }
コード例 #3
0
 /**
  * @return string
  */
 public function getMime()
 {
     $mime = File::mimeByExt(pathinfo($this->getUri(), PATHINFO_EXTENSION));
     return $mime === false ? 'text/html' : $mime;
 }
コード例 #4
0
function snippets_path()
{
    return File::normalizePath(base_path('resources/snippets'));
}
コード例 #5
0
ファイル: File.php プロジェクト: BlueCatTAT/kodicms-laravel
 /**
  * @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;
 }
コード例 #6
0
 /**
  * @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;
 }
コード例 #7
0
 /**
  * @return string
  */
 public function getSettingsFilePath()
 {
     return FileSystem::normalizePath($this->directory . DIRECTORY_SEPARATOR . '.settings.php');
 }