getPath() публичный Метод

For references created with {@link createReference()}, the path returned by this method is the reference path and not the actual repository path of the referenced resource. You should use {@link getRepositoryPath()} if you want to glob the repository for a resource.
public getPath ( ) : string | null
Результат string | null The path of the resource. If the resource has no path, `null` is returned.
Пример #1
0
 /**
  * Return the descriptors value for the given descriptor.
  *
  * @param string $descriptor
  *
  * @return mixed
  */
 public function get($descriptor)
 {
     if (!isset($this->descriptors[$descriptor])) {
         throw new \InvalidArgumentException(sprintf('Descriptor "%s" not supported for resource "%s" of class "%s". Supported descriptors: "%s"', $descriptor, $this->resource->getPath(), get_class($this->resource), implode('", "', array_keys($this->descriptors))));
     }
     return $this->descriptors[$descriptor];
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function append(PuliResource $resource)
 {
     if (!isset($this->versions[$resource->getPath()])) {
         $this->versions[$resource->getPath()] = array();
     }
     $this->versions[$resource->getPath()][] = $resource;
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function append(PuliResource $resource)
 {
     if (null === $this->json) {
         $this->load();
     }
     if (!isset($this->json[$resource->getPath()])) {
         $this->json[$resource->getPath()] = array();
     }
     $this->json[$resource->getPath()][] = serialize($resource);
     $this->flush();
 }
Пример #4
0
 /**
  * Returns an iterator for the children of a resource.
  *
  * @param PuliResource $resource The resource.
  *
  * @return RegexFilterIterator The iterator.
  */
 private function getChildIterator(PuliResource $resource)
 {
     $staticPrefix = rtrim($resource->getPath(), '/') . '/';
     $regExp = '~^' . preg_quote($staticPrefix, '~') . '[^/]+$~';
     return new RegexFilterIterator($regExp, $staticPrefix, new ArrayIterator($this->resources), RegexFilterIterator::FILTER_KEY);
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 public function append(PuliResource $resource)
 {
     $versions = $this->store->get($resource->getPath(), array());
     $versions[] = $resource;
     $this->store->set($resource->getPath(), $versions);
 }
Пример #6
0
 /**
  * {@inheritdoc}
  */
 protected function storeVersion(PuliResource $resource)
 {
     $path = $resource->getPath();
     // Newly inserted parent directories and the resource need to be
     // sorted before we can correctly search references below
     krsort($this->json);
     // If a mapping exists for a sub-path of this resource
     // (e.g. $path = /a, mapped sub-path = /a/b)
     // we need to record the order, since by default sub-paths are
     // preferred over super paths
     $references = $this->searchReferences($path, self::NO_SEARCH_FILESYSTEM | self::NO_CHECK_FILE_EXISTS | self::INCLUDE_ANCESTORS | self::INCLUDE_NESTED);
     // Filter virtual resources
     $references = array_filter($references, function ($currentReferences) {
         return array(null) !== $currentReferences;
     });
     // The $references contain:
     // - any sub references (e.g. /a/b/c, /a/b/d)
     // - the reference itself at $pos (e.g. /a/b)
     // - non-null parent references (e.g. /a)
     // (in that order, since long paths are sorted before short paths)
     $pos = array_search($path, array_keys($references), true);
     // We need to do three things:
     // 1. If any parent mapping has an order defined, inherit that order
     if ($pos + 1 < count($references)) {
         // Inherit the parent order if necessary
         if (!isset($this->json['_order'][$path])) {
             $parentReferences = array_slice($references, $pos + 1);
             $this->initWithParentOrder($path, $parentReferences);
         }
         // A parent order was inherited. Insert the path itself.
         if (isset($this->json['_order'][$path])) {
             $this->prependOrderEntry($path, $path);
         }
     }
     // 2. If there are child mappings, insert the current path into their order
     if ($pos > 0) {
         $subReferences = array_slice($references, 0, $pos);
         foreach ($subReferences as $subPath => $_) {
             if (isset($this->json['_order'][$subPath])) {
                 continue;
             }
             if (isset($this->json['_order'][$path])) {
                 $this->json['_order'][$subPath] = $this->json['_order'][$path];
             } else {
                 $this->initWithDefaultOrder($subPath, $path, $references);
             }
         }
         // After initializing all order entries, insert the new one
         foreach ($subReferences as $subPath => $_) {
             $this->prependOrderEntry($subPath, $path);
         }
     }
 }