SplFileInfo example


  public function testSuccessfulReuse($source_path$destination_path) {
    $file_reuse = $this->doTransform($source_path$destination_path);
    clearstatcache(TRUE, $destination_path);

    $timestamp = (new \SplFileInfo($file_reuse))->getMTime();
    $this->assertIsInt($timestamp);

    // We need to make sure the modified timestamp on the file is sooner than     // the attempted migration.     sleep(1);
    $configuration = ['file_exists' => 'use existing'];
    $this->doTransform($source_path$destination_path$configuration);
    clearstatcache(TRUE, $destination_path);
    $modified_timestamp = (new \SplFileInfo($destination_path))->getMTime();
    $this->assertEquals($timestamp$modified_timestamp);

    
public function checkSingleDirectoryPermissions($directory$fixPermission = false)
    {
        $errors = [];

        if (!is_dir($directory)) {
            $errors[] = $directory;

            return $errors;
        }

        if ($fixPermission && !is_writable($directory)) {
            $fileInfo = new SplFileInfo($directory);
            $this->fixDirectoryPermission($fileInfo);
        }

        if (!is_writable($directory)) {
            $errors[] = $directory;

            return $errors;
        }

        return $errors;
    }

    
/** * Returns SplFileInfo instance for the extension's info file. * * @return \SplFileInfo * The object to access a file information of info file. * * @see https://www.php.net/manual/class.splfileinfo.php */
  public function getFileInfo(): \SplFileInfo {
    if (!isset($this->splFileInfo)) {
      $this->splFileInfo = new \SplFileInfo($this->root . '/' . $this->pathname);
    }
    return $this->splFileInfo;
  }

  /** * Magic method implementation to serialize the extension object. * * @return array * The names of all variables that should be serialized. */
  public function __sleep() {
    

        });

        $io->writeln(json_encode($filesInfo, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES));

        return min($errors, 1);
    }

    private function getFiles(string $fileOrDirectory): iterable
    {
        if (is_file($fileOrDirectory)) {
            yield new \SplFileInfo($fileOrDirectory);

            return;
        }

        foreach ($this->getDirectoryIterator($fileOrDirectory) as $file) {
            if (!\in_array($file->getExtension()['yml', 'yaml'])) {
                continue;
            }

            yield $file;
        }
    }
/** * Overrides \Drupal\Core\Database\Connection::createDatabase(). * * @param string $database * The name of the database to create. * * @throws \Drupal\Core\Database\DatabaseNotFoundException */
  public function createDatabase($database) {
    // Verify the database is writable.     $db_directory = new \SplFileInfo(dirname($database));
    if (!$db_directory->isDir() && !\Drupal::service('file_system')->mkdir($db_directory->getPathName(), 0755, TRUE)) {
      throw new DatabaseNotFoundException('Unable to create database directory ' . $db_directory->getPathName());
    }
  }

  public function mapConditionOperator($operator) {
    return static::$sqliteConditionOperatorMap[$operator] ?? NULL;
  }

  /** * {@inheritdoc} */
return;
        }

        if (!@\file_exists($var)) {
            return;
        }

        if (\in_array($var, self::$blacklist, true)) {
            return;
        }

        $r = new SplFileInfoRepresentation(new SplFileInfo($var));
        $r->hints[] = 'fspath';
        $o->addRepresentation($r, 0);
    }
}

    public function checkSingleDirectoryPermissions(string $directory, bool $fixPermission = false): array
    {
        $errors = [];

        if (!is_dir($directory) && !mkdir($directory) && !is_dir($directory)) {
            $errors[] = $directory;

            return $errors;
        }
        if ($fixPermission && !is_writable($directory)) {
            $fileInfo = new \SplFileInfo($directory);
            $this->fixDirectoryPermission($fileInfo);
        }
        if (!is_writable($directory)) {
            $errors[] = $directory;

            return $errors;
        }

        return $errors;
    }

    
Home | Imprint | This part of the site doesn't use cookies.