Ejemplo n.º 1
0
 /**
  * @throws \WPluginCore003\Diagnostics\Exception
  * @author Panagiotis Vagenas <*****@*****.**>
  * @since  0.0.2
  */
 public function testTruePath()
 {
     $cases = array(array('original' => '/1/2/3/4/5/file', 'expected' => '/1/2/3/4/5/file'), array('original' => '/1/2/3/../4/5/file', 'expected' => '/1/2/4/5/file'), array('original' => '/1/2/3/../../4/5/file', 'expected' => '/1/4/5/file'), array('original' => '/1/2/3/../../../../4/5/file', 'expected' => realpath(getcwd() . '/../') . '/4/5/file'), array('original' => '/1/2/3/../../../../4/5/../file', 'expected' => realpath(getcwd() . '/../') . '/4/file'), array('original' => '/1/2/3/../../../../4/5/../../file', 'expected' => realpath(getcwd() . '/../') . '/file'), array('original' => '/1/2/3/../../../../../4/5/../../file', 'expected' => realpath(getcwd() . '/../../') . '/file'), array('original' => '/1/2/3/../../../../4/5/../../../file', 'expected' => realpath(getcwd() . '/../../') . '/file'), array('original' => '/1///2/./3/../../../../4/5/../../../file', 'expected' => realpath(getcwd() . '/../../') . '/file'), array('original' => '/1/2/3/..///./..///../../4/5/../../../file', 'expected' => realpath(getcwd() . '/../../') . '/file'), array('original' => '/1/2/3/../../../../4/./././5/../../..///./file', 'expected' => realpath(getcwd() . '/../../') . '/file'), array('original' => '/root/dir', 'expected' => '/root/dir'), array('original' => '/root/dir/', 'expected' => '/root/dir'), array('original' => '/root/dir/subDir/../', 'expected' => '/root/dir'), array('original' => '//root/dir///subDir/..///', 'expected' => '/root/dir'), array('original' => '/root/dir', 'expected' => '/root/dir'), array('original' => '/root/dir/', 'expected' => '/root/dir'), array('original' => '/root/dir/subDir/../', 'expected' => '/root/dir'), array('original' => '//root/dir///subDir/..///', 'expected' => '/root/dir'), array('original' => '://root/dir///subDir/..///', 'expected' => '://root/dir'), array('original' => 'vfs://root/dir///subDir/..///', 'expected' => 'vfs://root/dir'));
     $rootDir = new vfs\vfsStreamDirectory('root');
     $rdDir = new vfs\vfsStreamDirectory('dir');
     $rdSubDir = new vfs\vfsStreamDirectory('subDir');
     $rootDir->addChild($rdDir);
     $rdDir->addChild($rdSubDir);
     vfs\vfsStreamWrapper::setRoot($rootDir);
     foreach ($cases as $i => $case) {
         $this->assertSame($case['expected'], \WPluginCore003\Plugin\Paths::truePath($case['original']), 'Failure on case ' . ($i + 1) . ' ---> "' . implode('" => "', $case) . '"');
     }
 }
Ejemplo n.º 2
0
 /**
  * @param        $name
  * @param        $searchIn
  * @param        $ext
  * @param Plugin $plugin
  *
  * @return string
  * @throws \WPluginCore003\Diagnostics\Exception
  * @author Panagiotis Vagenas <*****@*****.**>
  * @since  0.0.2
  */
 public function locate($name, $searchIn, $ext, Plugin $plugin)
 {
     if (!preg_match('/.*\\.' . $ext . '$/', $name)) {
         $name .= ".{$ext}";
     }
     foreach ((array) $searchIn as $path) {
         $filePath = Paths::truePath("{$path}/{$name}", true);
         if (!$filePath) {
             continue;
         }
         if ($plugin->getFactory()->fcrPlugin()->paths()->verifyPathIsUnder($filePath, $path) && file_exists($filePath) && is_readable($filePath)) {
             return $filePath;
         }
     }
     return '';
 }
Ejemplo n.º 3
0
 /**
  * @return Paths
  * @author Panagiotis Vagenas <*****@*****.**>
  * @since  TODO ${VERSION}
  */
 public function paths()
 {
     return Paths::getInstance($this->plugin);
 }