Skip to content

Commit

Permalink
Remove path resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
msmakouz committed Feb 2, 2024
1 parent 67f1cf2 commit 545495e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 51 deletions.
19 changes: 13 additions & 6 deletions src/FromFilesSchemaProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

use Cycle\Schema\Provider\Exception\ConfigurationException;
use Cycle\Schema\Provider\Exception\SchemaFileNotFoundException;
use Cycle\Schema\Provider\Path\ResolverInterface;
use Cycle\Schema\Provider\Path\SimpleResolver;
use Webmozart\Glob\Glob;
use Webmozart\Glob\Iterator\GlobIterator;
use Cycle\Schema\Provider\Support\SchemaMerger;
Expand All @@ -27,11 +25,20 @@ final class FromFilesSchemaProvider implements SchemaProviderInterface
*/
private bool $strict = false;

private ResolverInterface $pathResolver;
/**
* @var \Closure(non-empty-string): non-empty-string
*/
private \Closure $pathResolver;

public function __construct(?ResolverInterface $resolver = null)
/**
* @param null|callable(non-empty-string): non-empty-string $pathResolver A function that resolves
* framework-specific file paths.
*/
public function __construct(?callable $pathResolver = null)
{
$this->pathResolver = $resolver ?? new SimpleResolver();
$this->pathResolver = $pathResolver === null
? static fn (string $path): string => $path
: \Closure::fromCallable($pathResolver);
}

public function withConfig(array $config): self
Expand All @@ -54,7 +61,7 @@ function ($file) {
if (!\is_string($file)) {
throw new ConfigurationException('The `files` parameter must contain string values.');
}
return $this->pathResolver->resolve($file);
return ($this->pathResolver)($file);
},
$files
);
Expand Down
10 changes: 0 additions & 10 deletions src/Path/ResolverInterface.php

This file was deleted.

13 changes: 0 additions & 13 deletions src/Path/SimpleResolver.php

This file was deleted.

9 changes: 5 additions & 4 deletions src/PhpFileSchemaProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Cycle\Schema\Provider;

use Closure;
use Cycle\Schema\Provider\Exception\ConfigurationException;
use Cycle\Schema\Provider\Exception\SchemaProviderException;
use Cycle\Schema\Renderer\PhpSchemaRenderer;
Expand All @@ -19,8 +18,10 @@ final class PhpFileSchemaProvider implements SchemaProviderInterface
private string $file = '';
private int $mode = self::MODE_READ_AND_WRITE;

/** @var Closure(non-empty-string): non-empty-string */
private Closure $pathResolver;
/**
* @var \Closure(non-empty-string): non-empty-string
*/
private \Closure $pathResolver;
private FilesInterface $files;

/**
Expand All @@ -32,7 +33,7 @@ public function __construct(?callable $pathResolver = null, ?FilesInterface $fil
$this->files = $files ?? new Files();
$this->pathResolver = $pathResolver === null
? static fn (string $path): string => $path
: Closure::fromCallable($pathResolver);
: \Closure::fromCallable($pathResolver);
}

/**
Expand Down
18 changes: 0 additions & 18 deletions tests/Unit/Path/SimpleResolverTest.php

This file was deleted.

0 comments on commit 545495e

Please sign in to comment.