Example #1
0
 /**
  * Method to test stripExtension().
  *
  * @return void
  *
  * @covers Windwalker\Filesystem\File::stripExtension
  */
 public function testStripExtension()
 {
     $name = File::stripExtension('Wu-la.la');
     $this->assertEquals('Wu-la', $name);
     $name = File::stripExtension(__DIR__ . '/Wu-la.la');
     $this->assertEquals(__DIR__ . '/Wu-la', $name);
 }
Example #2
0
 /**
  * generateEntry
  *
  * @param   Asset $entry
  *
  * @return  Page
  */
 public function generateEntry(Asset $entry)
 {
     $view = new PageHtmlView();
     $layout = File::stripExtension($entry->getPath());
     $html = $view->setLayout($layout)->render();
     $file = $layout . '.html';
     return new Page($file, $html);
 }
Example #3
0
 /**
  * findPaths
  *
  * @param string $layout
  *
  * @return  \SplFileInfo
  */
 public function findPaths($layout = null)
 {
     $layout = $layout ?: $this->getLayout();
     if (is_file($this->getPath() . '/' . $layout)) {
         return new \SplFileInfo(realpath($this->getPath() . '/' . $layout));
     }
     $layout = explode('/', $layout);
     $name = array_pop($layout);
     $layout = implode('/', $layout);
     if (is_dir($this->getPath() . '/' . $layout)) {
         $files = Filesystem::find($this->path . '/' . $layout, $name);
         /** @var \SplFileInfo $file */
         foreach ($files as $file) {
             if (File::stripExtension($file->getFilename()) == $name) {
                 return $file;
             }
         }
     }
     return null;
 }
Example #4
0
 /**
  * doExecute
  *
  * @return  int
  */
 protected function doExecute()
 {
     $path = $this->getArgument(0);
     $package = $this->getOption('p');
     $folder = $this->console->get('asset.folder', 'asset');
     if ($package = PackageHelper::getPackage($package)) {
         $path = $package->getDir() . '/Resources/asset/' . $path;
     } else {
         $path = WINDWALKER_PUBLIC . '/' . trim($folder, '/') . '/' . $path;
     }
     if (is_file($path)) {
         $files = array(new \SplFileInfo($path));
     } elseif (is_dir($path)) {
         $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \FilesystemIterator::FOLLOW_SYMLINKS));
     } else {
         throw new \InvalidArgumentException('No path');
     }
     /** @var \SplFileInfo $file */
     foreach ($files as $file) {
         $ext = File::getExtension($file->getPathname());
         if (StringHelper::endsWith($file->getBasename(), '.min.' . $ext)) {
             continue;
         }
         if ($ext == 'css') {
             $this->out('[<comment>Compressing</comment>] ' . $file);
             $data = \Minify_CSS_Compressor::process(file_get_contents($file));
             $data = str_replace("\n", ' ', $data);
         } elseif ($ext == 'js') {
             $this->out('[<comment>Compressing</comment>] ' . $file);
             $data = \JSMinPlus::minify(file_get_contents($file));
             $data = str_replace("\n", ';', $data);
         } else {
             continue;
         }
         $newName = $file->getPath() . '/' . File::stripExtension($file->getBasename()) . '.min.' . $ext;
         file_put_contents($newName, $data);
         $this->out('[<info>Compressed</info>] ' . $newName);
     }
 }
Example #5
0
 /**
  * loadAllFromPath
  *
  * @param   string $path
  * @param   string $format
  * @param   string $package
  */
 public static function loadAllFromPath($path, $format, $package = null)
 {
     $config = Ioc::getConfig();
     $locale = $config['language.locale'] ?: 'en-GB';
     $default = $config['language.default'] ?: 'en-GB';
     $locale = LanguageNormalize::toLanguageTag($locale);
     $default = LanguageNormalize::toLanguageTag($default);
     $localePath = $path . '/' . $locale;
     $files = array();
     if (is_dir($localePath)) {
         $files = array_merge($files, (array) Folder::files($localePath, false, Folder::PATH_BASENAME));
     }
     $defaultPath = $path . '/' . $default;
     if (is_dir($defaultPath)) {
         $files = array_merge($files, (array) Folder::files($defaultPath, false, Folder::PATH_BASENAME));
     }
     foreach ($files as $file) {
         $ext = File::getExtension($file);
         if (strcasecmp($ext, $format) !== 0) {
             continue;
         }
         Translator::loadFile(File::stripExtension($file), strtolower($format), $package);
     }
 }
Example #6
0
 /**
  * Method to get property Target
  *
  * @return  string
  */
 public function getTarget()
 {
     if (!$this->target) {
         $this->target = ltrim($this->getLayout(), '\\/');
         $this->target = File::stripExtension($this->target) . '.html';
     }
     return $this->target;
 }
Example #7
0
 /**
  * getRoute
  *
  * @return  string
  */
 public function getRoute()
 {
     if ($this->name == 'index' || $this->name == 'default') {
         $route = dirname($this->path);
         return Path::clean($route == '.' ? null : $route, '/');
     }
     return Path::clean(File::stripExtension($this->path), '/');
 }
Example #8
0
 /**
  * delete
  *
  * @param   string $path
  *
  * @return  boolean
  */
 public function delete($path)
 {
     $path = File::stripExtension($path);
     $basic = $this->imgur->api('image')->deleteImage($path)->getData();
     return $basic['success'];
 }
Example #9
0
 /**
  * getItem
  *
  * @param array $paths
  *
  * @return  string
  */
 public function getItem($paths)
 {
     $path = array_pop($paths);
     return \Windwalker\Filesystem\File::stripExtension($path);
 }