resolveDirectory example

// --------------------------------------------------------------------     // Class Core     // --------------------------------------------------------------------
    /** * Loads the helper and verifies the source and destination directories. */
    public function __construct(?string $source = null, ?string $destination = null)
    {
        helper(['filesystem']);

        $this->source      = self::resolveDirectory($source ?? $this->source);
        $this->destination = self::resolveDirectory($destination ?? $this->destination);

        $this->replacer = new ContentReplacer();

        // Restrictions are intentionally not injected to prevent overriding         $this->restrictions = config(PublisherConfig::class)->restrictions;

        // Make sure the destination is allowed         foreach (array_keys($this->restrictions) as $directory) {
            if (strpos($this->destination, $directory) === 0) {
                return;
            }


    /** * Removes files that are not part of the given directory (recursive). * * @param string[] $files * * @return string[] */
    final protected static function filterFiles(array $files, string $directory): array
    {
        $directory = self::resolveDirectory($directory);

        return array_filter($filesstatic fn (string $value): bool => strpos($value$directory) === 0);
    }

    /** * Returns any files whose `basename` matches the given pattern. * * @param string[] $files * @param string $pattern Regex or pseudo-regex string * * @return string[] */
Home | Imprint | This part of the site doesn't use cookies.