Пример #1
0
 protected function createTestRepository()
 {
     if (false == file_exists(sys_get_temp_dir() . '/octopus-repo/foo')) {
         $fileObject = new File(sys_get_temp_dir() . '/octopus-repo/foo');
         $fileObject->mkdirs();
     }
     // foo/bar1
     file_put_contents(sys_get_temp_dir() . '/octopus-repo/foo/bar1.json', json_encode(array('name' => 'foo/bar1', 'version' => array('*' => array('require' => array('foo/bar2' => '*'), "file" => "https://foo/bar1.ttl", "prefix-uri" => "http://foo/bar1/")))));
     // foo/bar2
     file_put_contents(sys_get_temp_dir() . '/octopus-repo/foo/bar2.json', json_encode(array('name' => 'foo/bar2', 'version' => array('*' => array("require" => array('foo/bar1' => '*', 'foo/bar3' => '*'), "file" => "https://foo/bar2.ttl", "prefix-uri" => "http://foo/bar2/")))));
     // foo/bar2
     file_put_contents(sys_get_temp_dir() . '/octopus-repo/foo/bar3.json', json_encode(array('name' => 'foo/bar3', 'version' => array('*' => array("require" => array('foo/bar2' => '*'), "file" => "https://foo/bar3.ttl", "prefix-uri" => "http://foo/bar3/")))));
 }
Пример #2
0
echo '<br/>';
echo 'File permission: ' . $fileObject->getPermission();
echo '<br/>';
echo '<br/>';
echo 'Remove file';
echo '<br/>';
$deletePath = __DIR__ . '/tmp/example.txt';
$fileObject = new File($deletePath);
$fileObject->delete();
echo 'Remove directories';
echo '<br/>';
$deletePath = __DIR__ . '/tmp/target/';
$fileObject = new File($deletePath);
$fileObject->deleteAll();
$examplePath = __DIR__ . '/ExampleDir';
$fileObject = new File($examplePath);
echo '<br/>';
$iteratorObject = $fileObject->listAll();
echo 'Iterate * <strong>' . $fileObject->getBasename() . '</strong>';
echo '<br/>';
echo '<ul>';
echo '<li>' . $fileObject->getBasename();
echo '<ul>';
foreach ($iteratorObject as $subFileObject) {
    echo '<li>' . $subFileObject->getBasename() . '</li>';
    if ($subFileObject->isDir()) {
        echo '<ul>';
        foreach ($subFileObject->listAll() as $subChildFileObject) {
            echo '<li>' . $subChildFileObject->getBasename() . '</li>';
        }
        echo '</ul>';
Пример #3
0
 /**
  * @depends     testExist
  * @return      void
  */
 public function testListFiles()
 {
     $examplePath = __DIR__ . '/ExampleDir';
     $filesObject = new File($examplePath);
     $expectedFiles = array($examplePath . '/testFile1.txt', $examplePath . '/testFile2.txt');
     $i = 0;
     foreach ($filesObject->listFiles() as $fileObject) {
         $this->assertInstanceOf('Naucon\\File\\File', $fileObject);
         $this->assertContains($fileObject->getPathname(), $expectedFiles);
         $i++;
     }
     $this->assertEquals(2, $i);
 }
Пример #4
0
 /**
  * copy file to a given directory
  *
  * @param       FileInterface|string
  * @return      bool
  */
 public function copy($pathname)
 {
     if (!empty($pathname)) {
         if ($pathname instanceof FileInterface) {
             $targetFile = $pathname;
         } else {
             $targetFile = new File($pathname);
         }
         if ($targetFile->isDir()) {
             $targetPathname = $targetFile->getPathname() . self::PATH_SEPARATOR . $this->getBasename();
             if ($this->isFile()) {
                 if (copy($this->getPathname(), $targetPathname)) {
                     parent::__construct($targetPathname);
                     return true;
                 }
             } elseif ($this->isDir()) {
                 if ($this->copyAction($this->getPathname(), $targetPathname, true)) {
                     parent::__construct($targetPathname);
                     return true;
                 }
             } else {
                 throw new FileException('Copy failed, source file or directory do not exist.');
             }
         } else {
             throw new FileException('Copy failed, target directory do not exist.');
         }
     } else {
         throw new FileException('Copy failed, because given filepath is empty.');
     }
     return false;
 }
Пример #5
0
 /**
  * @param string $configurationFilepath
  * @param File $repositoryFileObject
  * @throws \Exception if configuration file does not exists
  * @throws \Exception if configuration file is not readable
  */
 public function setup($configurationFilepath, $repositoryFileObject)
 {
     if (false === file_exists($configurationFilepath)) {
         throw new \Exception('Given configuration file does not exists: ' . $configurationFilepath);
     }
     if (false === is_readable($configurationFilepath)) {
         throw new \Exception('Given configuration file is not readable: ' . $configurationFilepath);
     }
     $this->configurationFilepath = $configurationFilepath;
     // include known vocabulary and ontology meta data
     $iteratorObject = $repositoryFileObject->listAll();
     foreach ($iteratorObject as $vendorFolder) {
         $vendorFolder->getBasename() . '<br/>';
         if ($vendorFolder->isDir()) {
             foreach ($vendorFolder->listFiles() as $jsonFile) {
                 $infoArray = json_decode(file_get_contents($jsonFile->getPathname()), true);
                 $this->repository[$infoArray['name']] = $infoArray;
             }
         }
     }
 }