示例#1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $result = CssKeys::removeAll();
     if ($result) {
         $this->info('Cache is now empty');
     } else {
         $this->error('Cache is not cleared!');
     }
 }
示例#2
0
 public function getHtmlCss($cssfiles)
 {
     $files = is_array($cssfiles) ? $cssfiles : func_get_args();
     $cacheKey = CssKeys::getSingleKey(Request::path());
     if (Cache::has($cacheKey)) {
         $cssoutput = Cache::get($cacheKey);
         return $this->getAsyncStylesheet($cssoutput, $files);
     } else {
         return $this->getStylesheetLink($files);
     }
 }
示例#3
0
 public function testGenerateAsyncCSS()
 {
     $html = file_get_contents(__DIR__ . '/resources/index.html');
     $urlPath = '/example';
     // create
     $job = new BuildAsyncCSS($html, $urlPath);
     $job->handle();
     // check
     $cssOutput = Cache::get(CssKeys::getSingleKey($urlPath));
     $this->assertFalse(empty($cssOutput), 'Css output is empty');
     $start = '@charset "UTF-8"';
     $this->assertStringStartsWith($start, $cssOutput, 'Css output maybe wrong');
 }
示例#4
0
文件: Show.php 项目: alcodo/async-css
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $keys = CssKeys::show();
     if ($keys === null) {
         $this->info('Cache is empty');
         return true;
     }
     if (is_array($keys)) {
         foreach ($keys as $key) {
             $path = CssKeys::getSinglePath($key);
             $this->info('Path: ' . $path);
         }
     }
     return true;
 }
示例#5
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     $result = $this->setCssfile();
     if ($result === false) {
         return false;
     }
     $tmpHtmlFile = $this->setHtml();
     if (empty($tmpHtmlFile)) {
         Log::warning('AsyncCss: No html file is loaded');
     }
     $cssOutput = $this->getCssOutput($tmpHtmlFile);
     if (empty($cssOutput)) {
         Log::warning('AsyncCss: Css output is empty');
     } else {
         Cache::forever($this->cacheKey, $cssOutput);
         CssKeys::add($this->cacheKey);
     }
     unlink($tmpHtmlFile);
 }
示例#6
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($request->getMethod() !== 'GET') {
         return $next($request);
     }
     $response = $next($request);
     if ($this->isHtmlResponse($response)) {
         $urlPath = $request->getRequestUri();
         //            var_dump('arsch'.$urlPath);
         $cacheKey = CssKeys::getSingleKey($urlPath);
         ////            var_dump($cacheKey);
         ////            dd(Cache::has($cacheKey));
         if (Cache::has($cacheKey) === false) {
             // start a asynccss job in queues mode
             $html = $response->getContent();
             $this->dispatch(new BuildAsyncCSS($html, $urlPath));
         }
     }
     return $response;
 }