示例#1
0
 /**
  * Locates a library.
  *
  * @param \Drupal\libraries\ExternalLibrary\Local\LocalLibraryInterface $library
  *   The library to locate.
  *
  * @see \Drupal\libraries\ExternalLibrary\Local\LocatorInterface::locate()
  */
 public function locate(LocalLibraryInterface $library)
 {
     $path = $this->fileSystemHelper->realpath($this->getUri($library));
     if ($path && is_dir($path) && is_readable($path)) {
         // Set a path relative to the app root.
         assert('strpos($path, $this->appRoot . "/") === 0', "Path: {$path}");
         $path = str_replace($this->appRoot . '/', '', $path);
         assert('$path[0] !== "/"');
         $library->setLocalPath($path);
     } else {
         $library->setUninstalled();
     }
 }
示例#2
0
 /**
  * Determines if the source and destination URIs represent identical paths.
  *
  * If either URI is a remote stream, will return FALSE.
  *
  * @param string $source
  *   The source URI.
  * @param string $destination
  *   The destination URI.
  *
  * @return bool
  *   TRUE if the source and destination URIs refer to the same physical path,
  *   otherwise FALSE.
  */
 protected function isLocationUnchanged($source, $destination)
 {
     if ($this->isLocalUri($source) && $this->isLocalUri($destination)) {
         return $this->fileSystem->realpath($source) === $this->fileSystem->realpath($destination);
     }
     return FALSE;
 }
 /**
  * {@inheritdoc}
  */
 public function transformDimensions(array &$dimensions, $uri)
 {
     // Test to see if EXIF is supported by the image format.
     $mime_type = $this->mimeTypeGuesser->guess($uri);
     if (!in_array($mime_type, ['image/jpeg', 'image/tiff'])) {
         // Not an EXIF enabled image, return.
         return;
     }
     if ($dimensions['width'] && $dimensions['height'] && $this->configuration['scan_exif']) {
         // Both dimensions in input, and effect is configured to check the
         // the input file. Read EXIF data, and determine image orientation.
         if (($file_path = $this->fileSystem->realpath($uri)) && function_exists('exif_read_data')) {
             if ($exif_data = @exif_read_data($file_path)) {
                 $orientation = isset($exif_data['Orientation']) ? $exif_data['Orientation'] : NULL;
                 if (in_array($orientation, [5, 6, 7, 8])) {
                     $tmp = $dimensions['width'];
                     $dimensions['width'] = $dimensions['height'];
                     $dimensions['height'] = $tmp;
                 }
                 return;
             }
         }
     }
     // Either no full dimensions in input, or effect is configured to skip
     // checking the input file, or EXIF extension is missing. Set both
     // dimensions to NULL.
     $dimensions['width'] = $dimensions['height'] = NULL;
 }
示例#4
0
 /**
  * Test successful moves.
  */
 public function testSuccessfulMoves()
 {
     $file_1 = $this->createUri(NULL, NULL, 'temporary');
     $file_1_absolute = $this->fileSystem->realpath($file_1);
     $file_2 = $this->createUri(NULL, NULL, 'temporary');
     $file_2_absolute = $this->fileSystem->realpath($file_2);
     $local_file = $this->createUri(NULL, NULL, 'public');
     $data_sets = [[$local_file, 'public://file1.jpg'], [$file_1_absolute, 'temporary://test.jpg'], [$file_2_absolute, 'temporary://core/modules/simpletest/files/test.jpg']];
     foreach ($data_sets as $data) {
         list($source_path, $destination_path) = $data;
         $actual_destination = $this->doImport($source_path, $destination_path, ['move' => TRUE]);
         $message = sprintf('File %s exists', $destination_path);
         $this->assertFileExists($destination_path, $message);
         $message = sprintf('File %s does not exist', $source_path);
         $this->assertFileNotExists($source_path, $message);
         $this->assertSame($actual_destination, $destination_path, 'The importer returned the moved filename.');
     }
 }
示例#5
0
 /**
  * Determines if the source and destination URIs represent identical paths.
  *
  * @param string $source
  *   The source URI.
  * @param string $destination
  *   The destination URI.
  *
  * @return bool
  *   TRUE if the source and destination URIs refer to the same physical path,
  *   otherwise FALSE.
  */
 protected function isLocationUnchanged($source, $destination)
 {
     return $this->fileSystem->realpath($source) === $this->fileSystem->realpath($destination);
 }
 /**
  * Gets the path to the library.
  *
  * @return string
  *   The path to the library.
  *
  * @throws \Drupal\libraries\ExternalLibrary\Exception\LibraryNotInstalledException
  */
 public function getLibraryPath()
 {
     // @todo Validate that the library is installed without causing infinite
     //   recursion.
     return $this->fileSystemHelper->realpath($this->getUri());
 }