/**
  * Return the last modified timestamp of a view.
  *
  * @param string $name
  * @return integer
  * @throws FileNotFoundException
  */
 public function lastModified($name)
 {
     if (!$this->files->exists($name)) {
         throw new FileNotFoundException("{$name} does not exist");
     }
     return $this->files->lastModified($name);
 }
Example #2
0
 public function get($path, array $data = array())
 {
     $filename = $this->files->name($path) . '.' . $this->files->extension($path);
     $compile_path = \Config::get('view.compiled') . DIRECTORY_SEPARATOR . $filename;
     $template_last_modified = $this->files->lastModified($path);
     $cache_last_modified = $this->files->isFile($compile_path) ? $this->files->lastModified($compile_path) : $template_last_modified;
     $view = $this->files->get($path);
     $app = app();
     // $m = new Mustache_Engine($app['config']->get('handlelars'));
     // Configuration
     $cache_disabled = false;
     $helpers = \Config::get('handlelars.helpers');
     // Precompile templates to view cache when necessary
     $compile = $template_last_modified >= $cache_last_modified || $cache_disabled;
     if ($compile) {
         $tpl = LightnCandy::compile($view, compact('helpers'));
         $this->files->put($compile_path, $tpl);
     }
     if (isset($data['__context']) && is_object($data['__context'])) {
         $data = $data['__context'];
     } else {
         $data = array_map(function ($item) {
             return is_object($item) && method_exists($item, 'toArray') ? $item->toArray() : $item;
         }, $data);
     }
     $renderer = $this->files->getRequire($compile_path);
     return $renderer($data);
 }
Example #3
0
 /**
  * Determine if the view at the given path is expired.
  *
  * @param string $path        	
  * @return bool
  */
 public function isExpired($path)
 {
     $compiled = $this->getCompiledPath($path);
     // If the compiled file doesn't exist we will indicate that the view is expired
     // so that it can be re-compiled. Else, we will verify the last modification
     // of the views is less than the modification times of the compiled views.
     if (!$this->cachePath || !$this->files->exists($compiled)) {
         return true;
     }
     $lastModified = $this->files->lastModified($path);
     return $lastModified >= $this->files->lastModified($compiled);
 }
Example #4
0
 /**
  * Get the last modified time of the asset.
  * 
  * @return int
  */
 public function getLastModified()
 {
     if ($this->lastModified) {
         return $this->lastModified;
     }
     return $this->lastModified = $this->isRemote() ? null : $this->files->lastModified($this->absolutePath);
 }
Example #5
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // 从数据库中获取的ArticleTag集合
     $tags = \App\Model\Tag::all();
     // 初始化博客的路径
     $dir = "/root/blog";
     $file_system = new Filesystem();
     $files = $file_system->allFiles($dir);
     foreach ($files as $file) {
         $file_extension = $file_system->extension($file);
         if ($file_extension != 'md') {
             continue;
         }
         $create_time_stamp = $file_system->lastModified($file);
         $create_time = gmdate("Y-m-d", $create_time_stamp);
         $file_content = $file_system->get($file);
         $file_name = preg_replace('/^.+[\\\\\\/]/', '', $file);
         $file_name = explode(".md", $file_name);
         $blog_name = $file_name[0];
         $last_dir = dirname($file);
         $current_tag_name = preg_replace('/^.+[\\\\\\/]/', '', $last_dir);
         $article_type_id = 0;
         foreach ($tags as $tag) {
             $tag_name = $tag->name;
             if (strcmp($current_tag_name, $tag_name) == 0) {
                 $article_type_id = $tag->id;
                 break;
             }
         }
         $article_id = \App\Model\Article::create(['cate_id' => $article_type_id, 'user_id' => 1, 'title' => $blog_name, 'content' => $file_content, 'tags' => $article_type_id, 'created_at' => $create_time, 'updated_at' => $create_time])->id;
         \App\Model\ArticleStatus::create(['art_id' => $article_id, 'view_number' => 0]);
     }
 }
 /**
  * Creates the undo file
  *
  * @return void
  */
 protected function createUndoFile()
 {
     // The generated files
     $generatedFiles = [];
     // Scan folders for generated files
     foreach (['app', 'database/migrations'] as $folder) {
         // For every file inside this folder
         foreach ($this->filesystem->files($folder) as $file) {
             // If lastModified time of this file is greater or equal to $this->startTime
             if ($this->filesystem->lastModified($file) >= $this->startTime) {
                 // Add this file to our generated files array
                 $generatedFiles[] = $file;
             }
         }
     }
     // If we do not have any generated files
     if (empty($generatedFiles)) {
         // Show error message and end method execution
         $this->error('No generated files created');
         return;
     }
     // Output generated files to console
     $this->info("The following files have been created:");
     foreach ($generatedFiles as $generatedFile) {
         $this->info("  {$generatedFile}");
     }
     // Save $generatedFiles to undo file if directory is writeable
     if ($this->filesystem->isWritable($this->filePathDirectory)) {
         // Write undo json file
         $this->filesystem->put($this->undoFilePath, json_encode($generatedFiles, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
     } else {
         // Show error that file could not be created
         $this->error('Could not create undo file, not enough permissions perhaps?: ' . $this->undoFilePath);
     }
 }
Example #7
0
 /**
  * Run a delete statement against the datasource.
  *
  * @param  string  $dirName
  * @param  string  $fileName
  * @return int
  */
 public function lastModified($dirName, $fileName, $extension)
 {
     try {
         $path = $this->makeFilePath($dirName, $fileName, $extension);
         return $this->files->lastModified($path);
     } catch (Exception $ex) {
         return null;
     }
 }
Example #8
0
 /**
  * Determine if the view at the given path is expired.
  *
  * @param string $path
  * @param array  $attributes
  *
  * @return bool
  */
 public function isExpired($path, array $attributes = [])
 {
     $compiled = $this->getCompiledPath($path, $attributes);
     if (!$this->files->exists($compiled)) {
         return true;
     }
     $lastModified = $this->files->lastModified($path);
     return $lastModified >= $this->files->lastModified($compiled);
 }
 /**
  * Delete previews older than the given life time configuration.
  *
  * @return void
  */
 private function cleanOldPreviews()
 {
     $oldPreviews = array_filter($this->files->files($this->previewPath), function ($file) {
         return time() - $this->files->lastModified($file) > $this->lifeTime;
     });
     if ($oldPreviews) {
         $this->files->delete($oldPreviews);
     }
 }
 /**
  * get view.
  *
  * @param string $slug
  *
  * @return string
  */
 public function getView($slug)
 {
     $attributes = $this->getAttributes($slug);
     $file = $this->storagePath() . md5($slug) . '.blade.php';
     if ($this->filesystem->exists($file) === false || $attributes->updated_at->getTimestamp() > $this->filesystem->lastModified($file)) {
         $this->filesystem->put($file, $attributes->content);
     }
     return $this->viewNamespace . '::' . md5($slug);
 }
 /**
  * Delete previews older than the given life time configuration.
  */
 private function cleanOldPreviews()
 {
     $oldPreviews = array_filter($this->files->files($this->storage()), function ($file) {
         return time() - $this->files->lastModified($file) > Config::get('mail-debug.lifetime') * 60;
     });
     if ($oldPreviews) {
         $this->files->delete($oldPreviews);
     }
 }
 /**
  * 取得遺骸檔案列表.
  *
  * @param string $directory
  * @return array
  */
 protected function getOldFiles($directory)
 {
     $semester = intval(substr($this->semester, -1));
     $now = Carbon::createFromDate(intval(substr($this->semester, 0, -1)) + (1 === $semester ? 1911 : 1912), 1 === $semester ? 10 : 3)->timestamp;
     $files = [];
     foreach ($this->filesystem->files($directory) as $file) {
         if ($now - $this->filesystem->lastModified($file) > 12960000) {
             $files[] = $file;
         }
     }
     return $files;
 }
Example #13
0
 /**
  * Clear out all the old releases in a repository.
  *
  * @param string $repository
  *
  * @return void
  */
 protected function clearRepository($repository)
 {
     foreach ($this->files->directories($repository) as $release) {
         if ($this->files->lastModified($release) > $this->deletable) {
             continue;
         }
         $this->files->deleteDirectory($release);
     }
     foreach ($this->files->files($repository) as $release) {
         if ($this->files->lastModified($release) > $this->deletable) {
             continue;
         }
         $this->files->delete($release);
     }
 }
Example #14
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $tag_array = array();
     $first_add = true;
     $dir = "/root/blog";
     $file_system = new Filesystem();
     $files = $file_system->allFiles($dir);
     foreach ($files as $file) {
         $file_extension = $file_system->extension($file);
         if ($file_extension != 'md') {
             continue;
         }
         $last_dir = dirname($file);
         $tag_name = preg_replace('/^.+[\\\\\\/]/', '', $last_dir);
         $create_time_stamp = $file_system->lastModified($file);
         $create_time = gmdate("Y-m-d", $create_time_stamp);
         if ($first_add) {
             $tag_info = array();
             $tag_info[0] = $tag_name;
             $tag_info[1] = $create_time;
             $tag_array[0] = $tag_info;
             $first_add = false;
         }
         $is_new = true;
         foreach ($tag_array as $tag) {
             if (strcmp($tag[0], $tag_name) == 0) {
                 $is_new = false;
             }
         }
         if ($is_new) {
             $tag_count = count($tag_array);
             $tag_info = array();
             $tag_info[0] = $tag_name;
             $tag_info[1] = $create_time;
             $tag_array[$tag_count] = $tag_info;
         }
     }
     foreach ($tag_array as $tag_io) {
         \App\Model\Tag::create(['name' => $tag_io[0]]);
         \App\Model\Category::create(['cate_name' => $tag_io[0], 'as_name' => $tag_io[0], 'parent_id' => 0, 'seo_key' => $tag_io[0], 'seo_desc' => $tag_io[0], 'created_at' => $tag_io[1], 'updated_at' => $tag_io[1]]);
     }
 }
Example #15
0
 /**
  * media.
  *
  * @param \Illuminate\Http\Request                      $request
  * @param \Illuminate\Filesystem\Filesystem             $filesystem
  * @param \Illuminate\Contracts\Routing\ResponseFactory $request
  * @param string                                        $file
  *
  * @return \Illuminate\Http\Response
  */
 public function media(Request $request, Filesystem $filesystem, ResponseFactory $responseFactory, $file)
 {
     $filename = __DIR__ . '/../../../public/' . $file;
     $mimeType = strpos($filename, '.css') !== false ? 'text/css' : 'application/javascript';
     $lastModified = $filesystem->lastModified($filename);
     $eTag = sha1_file($filename);
     $headers = ['content-type' => $mimeType, 'last-modified' => date('D, d M Y H:i:s ', $lastModified) . 'GMT'];
     if (@strtotime($request->server('HTTP_IF_MODIFIED_SINCE')) === $lastModified || trim($request->server('HTTP_IF_NONE_MATCH'), '"') === $eTag) {
         $response = $responseFactory->make(null, 304, $headers);
     } else {
         $response = $responseFactory->stream(function () use($filename) {
             $out = fopen('php://output', 'wb');
             $file = fopen($filename, 'rb');
             stream_copy_to_stream($file, $out, filesize($filename));
             fclose($out);
             fclose($file);
         }, 200, $headers);
     }
     return $response->setEtag($eTag);
 }
 /**
  * sound.
  *
  * @param \Illuminate\Filesystem\Filesystem             $filesystem
  * @param \Illuminate\Http\Request                      $request
  * @param string                                        $file
  *
  * @return \Illuminate\Http\Response
  */
 public function sound(Filesystem $filesystem, Request $request, $file)
 {
     $filename = __DIR__ . '/../../../resources/elfinder/sounds/' . $file;
     $mimeType = $filesystem->mimeType($filename);
     $lastModified = $filesystem->lastModified($filename);
     $eTag = sha1_file($filename);
     $headers = ['content-type' => $mimeType, 'last-modified' => date('D, d M Y H:i:s ', $lastModified) . 'GMT'];
     if (@strtotime($request->server('HTTP_IF_MODIFIED_SINCE')) === $lastModified || trim($request->server('HTTP_IF_NONE_MATCH'), '"') === $eTag) {
         $response = $this->responseFactory->make(null, 304, $headers);
     } else {
         $response = $this->responseFactory->stream(function () use($filename) {
             $out = fopen('php://output', 'wb');
             $file = fopen($filename, 'rb');
             stream_copy_to_stream($file, $out, filesize($filename));
             fclose($out);
             fclose($file);
         }, 200, $headers);
     }
     return $response->setEtag($eTag);
 }
Example #17
0
 /**
  * Get the file's last modification time.
  *
  * @param string $path
  * @return int 
  * @static 
  */
 public static function lastModified($path)
 {
     return \Illuminate\Filesystem\Filesystem::lastModified($path);
 }
Example #18
0
 /**
  * Determine if the resource has been modified.
  *
  * @return bool
  */
 public function isModified()
 {
     return $this->lastModified < $this->files->lastModified($this->path);
 }
Example #19
0
 /**
  * Generate an interface for the given class and output.
  *
  * @param $class
  * @param null $output
  * @param $outputFile
  * @param $input_file
  * @param $namespace
  * @param $interfaceName
  *
  * @return null
  */
 public function generate($class, $output, $outputFile, $input_file, $namespace, $interfaceName)
 {
     // StubFile Arguments
     $arguments = [];
     // Compose the Interface Class Name
     $arguments['className'] = $interfaceName;
     $arguments['namespace'] = $namespace;
     // Store current datetime
     $arguments['datetime'] = date('Y-m-d H:i:s');
     // Initialise methods and properties
     $arguments['methods'] = '';
     $arguments['properties'] = '';
     // Fill stubFile in memory
     $stubFile = file_get_contents(config('larinterface.stubFile'));
     /**
      * At this point the class should perfectly implements the interface to avoid a fatal error.
      *
      * Possible workaround:
      * - Empty the interface to avoid any possible missmatch (dirtiest)(actual)
      * - Find a way to get the class tokenized definition and analyse it to empty just the right interface method
      * - Find a way to use ReflectionClass on a class with a not compatible Interface
      */
     // if the interface already exist we empty it
     if (file_exists($outputFile)) {
         $interfaceContent = file_get_contents($outputFile);
         $tokenized = token_get_all($interfaceContent);
         $interfaceContentEmpty = '';
         foreach ($tokenized as $token) {
             if (is_string($token) && $token === '{') {
                 break;
             }
             if (is_array($token)) {
                 $interfaceContentEmpty .= $token[1];
             } else {
                 $interfaceContentEmpty .= $token;
             }
         }
         $interfaceContentEmpty .= '{}';
         // Get last modification datetime of the class interface
         $updateInterface = $this->filesystem->lastModified($outputFile);
         // Get last modification datetime of the class
         $updateClass = $this->filesystem->lastModified($input_file);
         // Save old content
         $outputOldContent = $this->filesystem->get($outputFile);
         // Empty Interface
         $this->filesystem->put($outputFile, $interfaceContentEmpty);
         // Check if update is needed
         if ($updateClass < $updateInterface) {
             // if not Refill the interface
             if (isset($outputOldContent)) {
                 $this->filesystem->put($outputFile, $outputOldContent);
             }
             return self::NO_MODIFICATION;
         }
     } else {
         // Create output directory if needed
         if (!file_exists($output)) {
             $this->filesystem->makeDirectory($output, 0755, true);
         }
         $scratchStub = $stubFile;
         // Add arguments to the scratch stubFile
         foreach ($arguments as $key => $argument) {
             $scratchStub = str_replace('%' . $key . '%', $argument, $scratchStub);
         }
         // Write the Interface on disk
         if ($this->filesystem->put($outputFile, $scratchStub) === false) {
             return ['code' => self::FAIL_WRITING, 'output' => $outputFile];
         }
     }
     /**
      * At this point we are sure that the class have a valid interface, an empty
      * one but it's just to use the reflection on the class without any error
      * concerning difference between the class and the interface that it implement.
      */
     $reflectedClass = new ReflectionClass($class);
     // Check if it's already an interface
     if ($reflectedClass->isInterface() || $reflectedClass->isTrait()) {
         return self::NOT_CLASS;
     }
     // Get methods and properties
     $methods = $reflectedClass->getMethods(ReflectionMethod::IS_PUBLIC);
     $properties = [];
     //$properties = $reflectedClass->getProperties(ReflectionProperty::IS_PUBLIC);
     $missingCommentBlock = 0;
     if (count($methods) == 0 && count($properties) == 0) {
         return self::EMPTY_CLASS;
     }
     $classFile = file($reflectedClass->getFileName());
     // Parse Class methods
     foreach ($methods as $key => $reflectionMethod) {
         // Remove inherited methods
         if ($reflectionMethod->class != $class) {
             continue;
         }
         $start = $reflectionMethod->getStartLine();
         $end = $reflectionMethod->getEndLine();
         $comment = $reflectionMethod->getDocComment();
         $method = implode('', array_slice($classFile, $start - 1, $end - $start + 1));
         $tokenized = token_get_all('<?php ' . $method);
         $methodDeclaration = '';
         foreach ($tokenized as $token) {
             if (is_string($token) && $token === '{') {
                 break;
             }
             if (is_array($token)) {
                 $methodDeclaration .= $token[1];
             } else {
                 $methodDeclaration .= $token;
             }
         }
         $methodDeclaration = str_replace('<?php ', '', $methodDeclaration);
         if (empty($comment)) {
             $missingCommentBlock++;
             $arguments['methods'] .= trim($methodDeclaration) . ";\n\n    ";
         } else {
             $arguments['methods'] .= $comment . "\n    " . trim($methodDeclaration) . ";\n\n    ";
         }
     }
     // Trim end of methods string
     $arguments['methods'] = rtrim($arguments['methods']);
     // @TODO: Parse properties
     // Create output directory if needed
     if (!file_exists($output)) {
         $this->filesystem->makeDirectory($output, 0755, true);
     }
     // Add arguments for stubFile
     foreach ($arguments as $key => $argument) {
         $stubFile = str_replace('%' . $key . '%', $argument, $stubFile);
     }
     // Write Interface on disk using stubFile
     if ($this->filesystem->put($outputFile, $stubFile) === false) {
         return ['code' => self::FAIL_WRITING, 'output' => $outputFile];
     }
     return ['code' => self::SUCCESS, 'comment' => $missingCommentBlock];
 }
Example #20
0
 /**
  * {@inheritdoc}
  */
 public function isFresh($name, $time)
 {
     return $this->files->lastModified($this->findTemplate($name)) <= $time;
 }
Example #21
0
 /**
  * Get the object's last modification time.
  *
  * @param  string  $path
  * @return int
  */
 public function lastModified()
 {
     $this->files->lastModified($this->path);
 }
 /**
  * @param $path
  * @return int
  */
 public function lastModified($path)
 {
     return $this->storage->lastModified($this->storagePath($path));
 }