class DirectoryResource

A resource is something formulae can be loaded from.

@author Kris Wallsmith <kris.wallsmith@gmail.com>

Hierarchy

Expanded class hierarchy of DirectoryResource

2 files declare their use of DirectoryResource
CoalescingDirectoryResourceTest.php in drupal/core/vendor/kriswallsmith/assetic/tests/Assetic/Test/Factory/Resource/CoalescingDirectoryResourceTest.php
DirectoryResourceTest.php in drupal/core/vendor/kriswallsmith/assetic/tests/Assetic/Test/Factory/Resource/DirectoryResourceTest.php

File

drupal/core/vendor/kriswallsmith/assetic/src/Assetic/Factory/Resource/DirectoryResource.php, line 19

Namespace

Assetic\Factory\Resource
View source
class DirectoryResource implements IteratorResourceInterface {
  private $path;
  private $pattern;

  /**
   * Constructor.
   *
   * @param string $path    A directory path
   * @param string $pattern A filename pattern
   */
  public function __construct($path, $pattern = null) {
    if (DIRECTORY_SEPARATOR != substr($path, -1)) {
      $path .= DIRECTORY_SEPARATOR;
    }
    $this->path = $path;
    $this->pattern = $pattern;
  }
  public function isFresh($timestamp) {
    if (!is_dir($this->path) || filemtime($this->path) > $timestamp) {
      return false;
    }
    foreach ($this as $resource) {
      if (!$resource
        ->isFresh($timestamp)) {
        return false;
      }
    }
    return true;
  }

  /**
   * Returns the combined content of all inner resources.
   */
  public function getContent() {
    $content = array();
    foreach ($this as $resource) {
      $content[] = $resource
        ->getContent();
    }
    return implode("\n", $content);
  }
  public function __toString() {
    return $this->path;
  }
  public function getIterator() {
    return is_dir($this->path) ? new DirectoryResourceIterator($this
      ->getInnerIterator()) : new \EmptyIterator();
  }
  protected function getInnerIterator() {
    return new DirectoryResourceFilterIterator(new \RecursiveDirectoryIterator($this->path, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS), $this->pattern);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DirectoryResource::$path private property
DirectoryResource::$pattern private property
DirectoryResource::getContent public function Returns the combined content of all inner resources. Overrides ResourceInterface::getContent
DirectoryResource::getInnerIterator protected function
DirectoryResource::getIterator public function
DirectoryResource::isFresh public function Checks if a timestamp represents the latest resource. Overrides ResourceInterface::isFresh
DirectoryResource::__construct public function Constructor.
DirectoryResource::__toString public function Returns a unique string for the current resource. Overrides ResourceInterface::__toString