コード例 #1
0
ファイル: Path.php プロジェクト: yakamoz-fang/concrete
 /**
  * {@inheritdoc}
  */
 public function getRelativePath(PathInterface $reference)
 {
     if ($this->sameValueAs($reference)) {
         return '';
     }
     $ref_path = array_values($reference->toArray());
     $this_path = array_values($this->data);
     $filename = array_pop($this_path);
     //retrieve the final consecutive identical segment in the current path
     $index = 0;
     foreach ($ref_path as $offset => $value) {
         if (!isset($this_path[$offset]) || $value != $this_path[$offset]) {
             break;
         }
         $index++;
     }
     //deduce the number of similar segment according to the reference path
     $nb_common_segment = count($ref_path) - $index;
     $nb_segments = array();
     if ($nb_common_segment) {
         $nb_segments = array_fill(0, $nb_common_segment, '..');
     }
     //let's output the relative path using a new Path object
     $res = new Path(array_merge($nb_segments, array_slice($this_path, $index), array($filename)));
     return $res->__toString();
 }
コード例 #2
0
 /** Main entry point */
 public function main()
 {
     // Apparently casting to (string) no longer invokes __toString() automatically.
     if (is_object($this->classpath)) {
         $classpath = $this->classpath->__toString();
     }
     if (empty($classpath)) {
         throw new BuildException("Provided classpath was empty.");
     }
     $curr_parts = Phing::explodeIncludePath();
     $add_parts = Phing::explodeIncludePath($classpath);
     $new_parts = array_diff($add_parts, $curr_parts);
     if ($new_parts) {
         $this->updateIncludePath($new_parts, $curr_parts);
     }
 }
コード例 #3
0
 /** Main entry point */
 public function main()
 {
     // Apparently casting to (string) no longer invokes __toString() automatically.
     if (is_object($this->classpath)) {
         $classpath = $this->classpath->__toString();
     }
     if (empty($classpath)) {
         throw new BuildException("Provided classpath was empty.");
     }
     $curr_parts = Phing::explodeIncludePath();
     $add_parts = Phing::explodeIncludePath($classpath);
     $new_parts = array_diff($add_parts, $curr_parts);
     if ($new_parts) {
         $this->log("Prepending new include_path components: " . implode(PATH_SEPARATOR, $new_parts), Project::MSG_VERBOSE);
         set_include_path(implode(PATH_SEPARATOR, array_merge($new_parts, $curr_parts)));
     }
 }
コード例 #4
0
ファイル: PathTest.php プロジェクト: Jaymon/Montage
 /**
  *  tests the {@link Montage\Path::getChildren()} method
  */
 public function testGetChildren()
 {
     $base = $this->getFixturePath('Path');
     $instance = new Path($base);
     $test_list = array();
     $test_list[] = array('in' => array('', 1), 'out' => array('files' => array(join(DIRECTORY_SEPARATOR, array($instance->__toString(), 'che.txt'))), 'folders' => array(join(DIRECTORY_SEPARATOR, array($instance->__toString(), 'bar')), join(DIRECTORY_SEPARATOR, array($instance->__toString(), 'foo')))));
     $test_list[] = array('in' => array('#che#', 1), 'out' => array('files' => array(join(DIRECTORY_SEPARATOR, array($instance->__toString(), 'che.txt'))), 'folders' => array()));
     $test_list[] = array('in' => array('#something-not-matching#', 1), 'out' => array('files' => array(), 'folders' => array()));
     $test_list[] = array('in' => array('', -1), 'out' => array('files' => array(join(DIRECTORY_SEPARATOR, array($instance->__toString(), 'bar', '2', '1.txt')), join(DIRECTORY_SEPARATOR, array($instance->__toString(), 'bar', '2', 'monkey.txt')), join(DIRECTORY_SEPARATOR, array($instance->__toString(), 'che.txt')), join(DIRECTORY_SEPARATOR, array($instance->__toString(), 'foo', '1', 'monkey.txt'))), 'folders' => array(join(DIRECTORY_SEPARATOR, array($instance->__toString(), 'bar')), join(DIRECTORY_SEPARATOR, array($instance->__toString(), 'bar', '1')), join(DIRECTORY_SEPARATOR, array($instance->__toString(), 'bar', '2')), join(DIRECTORY_SEPARATOR, array($instance->__toString(), 'bar', '3')), join(DIRECTORY_SEPARATOR, array($instance->__toString(), 'foo')), join(DIRECTORY_SEPARATOR, array($instance->__toString(), 'foo', '1')))));
     $test_list[] = array('in' => array('#che#', -1), 'out' => array('files' => array(join(DIRECTORY_SEPARATOR, array($instance->__toString(), 'che.txt'))), 'folders' => array()));
     $test_list[] = array('in' => array('#1$#', -1), 'out' => array('files' => array(), 'folders' => array(join(DIRECTORY_SEPARATOR, array($instance->__toString(), 'bar', '1')), join(DIRECTORY_SEPARATOR, array($instance->__toString(), 'foo', '1')))));
     $test_list[] = array('in' => array('#nothing-matching#', -1), 'out' => array('files' => array(), 'folders' => array()));
     foreach ($test_list as $key => $test_map) {
         $actual = call_user_func_array(array($instance, 'getChildren'), $test_map['in']);
         $this->assertEquals($test_map['out'], $actual, $key);
     }
     //foreach
 }