Search
Blade Parser

Blade Parser

Validating Workspaces

Validating workspaces works the same as validating individual documents. The difference is that all the configured nodes and document validators will be executed against all documents within the workspace.

1<?php
2use Stillat\BladeParser\Errors\BladeError;
3use Stillat\BladeParser\Workspaces\Workspace;
4 
5$workspace = new Workspace();
6$workspace->addDirectory(resource_path('views'))
7 ->withCoreValidators()
8 ->validate()->getValidationErrors()->each(function (BladeError $error) {
9 // Interact with the validation error.
10 });

#Available Methods

#validate

Validates all documents within the workspace using the internal BladeValidator instance.

1<?php
2 
3use Stillat\BladeParser\Workspaces\Workspace;
4 
5public function validate(): Workspace;

#getValidationErrors

Returns all validation errors present in the workspace.

1<?php
2 
3use Illuminate\Support\Collection;
4 
5public function getValidationErrors(): Collection;

#withCoreValidators

Includes the core validators on the internal BladeValidator instance.

If a BladeValidator instance does not already exist on the document, a new one will be created automatically via the ValidatorFactory::makeBladeValidator() factory method.
Under a typical installation environment, this will load the validators that are configured under the config path: blade.validation.core_validators

1<?php
2 
3use Stillat\BladeParser\Workspaces\Workspace;
4 
5public function withCoreValidators(): Workspace;

#validator

Returns access to an internal BladeValidator instance.

If a validator instance does not already exist, one will be automatically created by calling the ValidatorFactory::makeBladeValidator() method.

1<?php
2 
3use Stillat\BladeParser\Validation\BladeValidator;
4 
5public function validator(): BladeValidator;

#addValidator

Adds a single node validator instance to the internal BladeValidator instance.

Argument

Description

$validator

The node validator.

1<?php
2 
3use Stillat\BladeParser\Validation\AbstractNodeValidator;
4use Stillat\BladeParser\Workspaces\Workspace;
5 
6public function addValidator(
7 AbstractNodeValidator $validator
8): Workspace;

#addDocumentValidator

Adds a single document validator instance to the internal BladeValidator instance.

Argument

Description

$validator

The document validator.

1<?php
2 
3use Stillat\BladeParser\Validation\AbstractDocumentValidator;
4use Stillat\BladeParser\Workspaces\Workspace;
5 
6public function addDocumentValidator(
7 AbstractDocumentValidator $validator
8): Workspace;

#withValidator

Adds a validator instance to the internal BladeValidator instance.

Argument

Description

$validator

The validator instance.

1<?php
2 
3use Stillat\BladeParser\Validation\AbstractNodeValidator;
4use Stillat\BladeParser\Workspaces\Workspace;
5 
6public function withValidator(
7 AbstractNodeValidator $validator
8): Workspace;

#withValidators

Adds a list of validator instances to the internal BladeValidator instance.

Argument

Description

$validators

The validator instances.

1<?php
2 
3use Stillat\BladeParser\Workspaces\Workspace;
4 
5public function withValidators(
6 array $validators
7): Workspace;

#hasErrors

Tests if any errors are present.

1<?php
2 
3public function hasErrors(): bool;

#hasFatalErrors

Tests if any fatal errors are present.

1<?php
2 
3public function hasFatalErrors(): bool;

#getErrors

Retrieves a collection of BladeError instances for the workspace.

1<?php
2 
3use Illuminate\Support\Collection;
4 
5public function getErrors(): Collection;

#getFirstError

Retrieves the first error.

If the error source contains multiple types of errors, such as parser errors and validation errors, all errors will be considered.

1<?php
2 
3use Stillat\BladeParser\Errors\BladeError;
4 
5public function getFirstError(): BladeError;

#getFirstFatalError

Retrieves the first fatal error.

If the error source contains multiple types of errors, such as parser errors and validation errors, all errors will be considered. Fatal errors are considered those that would produce invalid compiled PHP code, regardless of which compiler implementation is used.

1<?php
2 
3use Stillat\BladeParser\Errors\BladeError;
4 
5public function getFirstFatalError(): BladeError;

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.