Skip to content

Commit d485c1b

Browse files
committed
chore: le systeme de vue doit toujours avoir le locator
1 parent 4525024 commit d485c1b

9 files changed

Lines changed: 24 additions & 30 deletions

File tree

src/Debug/ExceptionManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static function registerHttpErrors(Run $debugger, array $config): Run
5252

5353
if (in_array((string) $exception->getCode(), $files, true)) {
5454
$view = new View();
55-
$view->setAdapter(config('view.active_adapter', 'native'), ['view_path_locator' => $config['error_view_path']])
55+
$view->setAdapter(config('view.active_adapter', 'native'), ['view_path' => $config['error_view_path']])
5656
->display((string) $exception->getCode())
5757
->setData(['message' => $exception->getMessage()])
5858
->render();

src/View/Adapters/AbstractAdapter.php

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ abstract class AbstractAdapter implements RendererInterface
5050
/**
5151
* Instance de Locator lorsque nous devons tenter de trouver une vue qui n'est pas à l'emplacement standard.
5252
*/
53-
protected ?LocatorInterface $locator = null;
53+
protected LocatorInterface $locator;
5454

5555
/**
5656
* Le nom de la mise en page utilisée, le cas échéant.
@@ -70,25 +70,19 @@ abstract class AbstractAdapter implements RendererInterface
7070
/**
7171
* {@inheritDoc}
7272
*
73-
* @param array $config Configuration actuelle de l'adapter
74-
* @param bool $debug Devrions-nous stocker des informations sur les performances ?
73+
* @param array $config Configuration actuelle de l'adapter
74+
* @param string|null $viewPath Dossier principal dans lequel les vues doivent être cherchées
75+
* @param bool $debug Devrions-nous stocker des informations sur les performances ?
7576
*/
76-
public function __construct(protected array $config, $viewPathLocator = null, protected bool $debug = BLITZ_DEBUG)
77+
public function __construct(protected array $config, $viewPath = null, protected bool $debug = BLITZ_DEBUG)
7778
{
7879
helper('assets');
7980

80-
if (! empty($viewPathLocator)) {
81-
if (is_string($viewPathLocator)) {
82-
$this->viewPath = rtrim($viewPathLocator, '\\/ ') . DS;
83-
} elseif ($viewPathLocator instanceof LocatorInterface) {
84-
$this->locator = $viewPathLocator;
85-
}
81+
if (is_string($viewPath) && is_dir($viewPath = rtrim($viewPath, '\\/ ') . DS)) {
82+
$this->viewPath = $viewPath;
8683
}
8784

88-
if (! $this->locator instanceof LocatorInterface && ! is_dir($this->viewPath)) {
89-
$this->viewPath = '';
90-
$this->locator = service('locator');
91-
}
85+
$this->locator = service('locator');
9286

9387
$this->ext = preg_replace('#^\.#', '', $config['extension'] ?? $this->ext);
9488
}
@@ -264,7 +258,7 @@ protected function getRenderedFile(?array $options, string $view, ?string $ext =
264258

265259
$file = Helpers::ensureExt($file, $ext);
266260

267-
if (! is_file($file) && $this->locator instanceof LocatorInterface) {
261+
if (! is_file($file)) {
268262
$file = $this->locator->locateFile($view, 'Views', $ext);
269263
}
270264

src/View/Adapters/BladeAdapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ class BladeAdapter extends AbstractAdapter
3030
/**
3131
* {@inheritDoc}
3232
*/
33-
public function __construct(protected array $config, $viewPathLocator = null, protected bool $debug = BLITZ_DEBUG)
33+
public function __construct(protected array $config, $viewPath = null, protected bool $debug = BLITZ_DEBUG)
3434
{
35-
parent::__construct($config, $viewPathLocator, $debug);
35+
parent::__construct($config, $viewPath, $debug);
3636

3737
$this->engine = new Blade(
3838
$this->viewPath ?: VIEW_PATH,

src/View/Adapters/LatteAdapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class LatteAdapter extends AbstractAdapter
3131
/**
3232
* {@inheritDoc}
3333
*/
34-
public function __construct(protected array $config, $viewPathLocator = null, protected bool $debug = BLITZ_DEBUG)
34+
public function __construct(protected array $config, $viewPath = null, protected bool $debug = BLITZ_DEBUG)
3535
{
36-
parent::__construct($config, $viewPathLocator, $debug);
36+
parent::__construct($config, $viewPath, $debug);
3737

3838
$this->latte = new Engine();
3939

src/View/Adapters/NativeAdapter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ class NativeAdapter extends AbstractAdapter
7878
/**
7979
* {@inheritDoc}
8080
*/
81-
public function __construct(protected array $config, $viewPathLocator = null, protected bool $debug = BLITZ_DEBUG)
81+
public function __construct(protected array $config, $viewPath = null, protected bool $debug = BLITZ_DEBUG)
8282
{
83-
parent::__construct($config, $viewPathLocator, $debug);
83+
parent::__construct($config, $viewPath, $debug);
8484

8585
$this->saveData = (bool) ($config['save_data'] ?? true);
8686
}
@@ -591,7 +591,7 @@ public function required(bool|string $condition): string
591591
/**
592592
* Génère un champ input caché à utiliser dans les formulaires générés manuellement.
593593
*/
594-
public function csrf(?string $id): string
594+
public function csrf(?string $id = null): string
595595
{
596596
return csrf_field($id);
597597
}

src/View/Adapters/PlatesAdapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class PlatesAdapter extends AbstractAdapter
3131
/**
3232
* {@inheritDoc}
3333
*/
34-
public function __construct(protected array $config, $viewPathLocator = null, protected bool $debug = BLITZ_DEBUG)
34+
public function __construct(protected array $config, $viewPath = null, protected bool $debug = BLITZ_DEBUG)
3535
{
36-
parent::__construct($config, $viewPathLocator, $debug);
36+
parent::__construct($config, $viewPath, $debug);
3737

3838
$this->engine = new Engine(rtrim($this->viewPath, '/\\'), $this->ext);
3939

src/View/Adapters/SmartyAdapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ class SmartyAdapter extends AbstractAdapter
3030
/**
3131
* {@inheritDoc}
3232
*/
33-
public function __construct(protected array $config, $viewPathLocator = null, protected bool $debug = BLITZ_DEBUG)
33+
public function __construct(protected array $config, $viewPath = null, protected bool $debug = BLITZ_DEBUG)
3434
{
35-
parent::__construct($config, $viewPathLocator, $debug);
35+
parent::__construct($config, $viewPath, $debug);
3636

3737
$this->engine = new Smarty();
3838

src/View/Adapters/TwigAdapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ class TwigAdapter extends AbstractAdapter
3333
/**
3434
* {@inheritDoc}
3535
*/
36-
public function __construct(protected array $config, $viewPathLocator = null, protected bool $debug = BLITZ_DEBUG)
36+
public function __construct(protected array $config, $viewPath = null, protected bool $debug = BLITZ_DEBUG)
3737
{
38-
parent::__construct($config, $viewPathLocator, $debug);
38+
parent::__construct($config, $viewPath, $debug);
3939

4040
$loader = new FilesystemLoader([
4141
$this->viewPath,

src/View/View.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ public function setAdapter(string $adapter, array $config = []): static
369369

370370
$this->adapter = new self::$validAdapters[$adapter](
371371
$config,
372-
$config['view_path_locator'] ?? service('locator'),
372+
$config['view_path'] ?? null,
373373
$debug
374374
);
375375

0 commit comments

Comments
 (0)