Skip to content

Commit

Permalink
Update deprecated code
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharette committed Feb 9, 2024
1 parent 74b4a9b commit 878fb19
Show file tree
Hide file tree
Showing 17 changed files with 88 additions and 100 deletions.
2 changes: 1 addition & 1 deletion app/src/Controller/Dashboard/DashboardAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected function getLatestUsers(): array
*/
protected function getDatabaseInfo(): array
{
$database = $this->config->getString('db.default');
$database = $this->config->getString('db.default', '');
$pdo = $this->dbConnection->getPdo();
$results = [
'connection' => $database,
Expand Down
17 changes: 8 additions & 9 deletions app/src/Controller/Group/GroupCreateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use UserFrosting\Alert\AlertStream;
use UserFrosting\Fortress\RequestDataTransformer;
use UserFrosting\Fortress\RequestSchema;
use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface;
use UserFrosting\Fortress\ServerSideValidator;
use UserFrosting\I18n\Translator;
use UserFrosting\Fortress\Transformer\RequestDataTransformer;
use UserFrosting\Fortress\Validator\ServerSideValidator;
use UserFrosting\Sprinkle\Account\Authenticate\Authenticator;
use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\GroupInterface;
use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface;
Expand Down Expand Up @@ -56,8 +55,9 @@ public function __construct(
protected Authenticator $authenticator,
protected Connection $db,
protected GroupInterface $groupModel,
protected Translator $translator,
protected UserActivityLogger $userActivityLogger,
protected RequestDataTransformer $transformer,
protected ServerSideValidator $validator,
) {
}

Expand Down Expand Up @@ -92,8 +92,7 @@ protected function handle(Request $request): void
$schema = $this->getSchema();

// Whitelist and set parameter defaults
$transformer = new RequestDataTransformer($schema);
$data = $transformer->transform($params);
$data = $this->transformer->transform($schema, $params);

// Validate request data
$this->validateData($schema, $data);
Expand Down Expand Up @@ -153,10 +152,10 @@ protected function getSchema(): RequestSchemaInterface
*/
protected function validateData(RequestSchemaInterface $schema, array $data): void
{
$validator = new ServerSideValidator($schema, $this->translator);
if ($validator->validate($data) === false && is_array($validator->errors())) {
$errors = $this->validator->validate($schema, $data);
if (count($errors) !== 0) {
$e = new ValidationException();
$e->addErrors($validator->errors());
$e->addErrors($errors);

throw $e;
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/Controller/Group/GroupCreateModal.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Views\Twig;
use UserFrosting\Fortress\Adapter\JqueryValidationAdapter;
use UserFrosting\Fortress\Adapter\JqueryValidationArrayAdapter;
use UserFrosting\Fortress\RequestSchema;
use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface;
use UserFrosting\I18n\Translator;
Expand Down Expand Up @@ -50,6 +50,7 @@ public function __construct(
protected GroupInterface $groupModel,
protected Translator $translator,
protected Twig $view,
protected JqueryValidationArrayAdapter $adapter,
) {
}

Expand Down Expand Up @@ -82,7 +83,6 @@ protected function handle(): array

// Load the request schema & validator
$schema = $this->getSchema();
$validatorRegister = new JqueryValidationAdapter($schema, $this->translator);

// Determine form fields to hide/disable
$fields = [
Expand All @@ -99,7 +99,7 @@ protected function handle(): array
'submit_text' => $this->translator->translate('CREATE'),
],
'page' => [
'validators' => $validatorRegister->rules(),
'validators' => $this->adapter->rules($schema),
],
];
}
Expand Down
17 changes: 8 additions & 9 deletions app/src/Controller/Group/GroupEditAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
use Psr\Http\Message\ServerRequestInterface as Request;
use UserFrosting\Alert\AlertStream;
use UserFrosting\Config\Config;
use UserFrosting\Fortress\RequestDataTransformer;
use UserFrosting\Fortress\RequestSchema;
use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface;
use UserFrosting\Fortress\ServerSideValidator;
use UserFrosting\I18n\Translator;
use UserFrosting\Fortress\Transformer\RequestDataTransformer;
use UserFrosting\Fortress\Validator\ServerSideValidator;
use UserFrosting\Sprinkle\Account\Authenticate\Authenticator;
use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\GroupInterface;
use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface;
Expand Down Expand Up @@ -55,9 +54,10 @@ public function __construct(
protected Authenticator $authenticator,
protected Config $config,
protected Connection $db,
protected Translator $translator,
protected UserActivityLogger $userActivityLogger,
protected GroupInterface $groupModel,
protected RequestDataTransformer $transformer,
protected ServerSideValidator $validator,
) {
}

Expand Down Expand Up @@ -93,8 +93,7 @@ protected function handle(GroupInterface $group, Request $request): void
$schema = $this->getSchema();

// Whitelist and set parameter defaults
$transformer = new RequestDataTransformer($schema);
$data = $transformer->transform($params);
$data = $this->transformer->transform($schema, $params);

// Validate request data
$this->validateData($schema, $data);
Expand Down Expand Up @@ -164,10 +163,10 @@ protected function getSchema(): RequestSchemaInterface
*/
protected function validateData(RequestSchemaInterface $schema, array $data): void
{
$validator = new ServerSideValidator($schema, $this->translator);
if ($validator->validate($data) === false && is_array($validator->errors())) {
$errors = $this->validator->validate($schema, $data);
if (count($errors) !== 0) {
$e = new ValidationException();
$e->addErrors($validator->errors());
$e->addErrors($errors);

throw $e;
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/Controller/Group/GroupEditModal.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Views\Twig;
use UserFrosting\Fortress\Adapter\JqueryValidationAdapter;
use UserFrosting\Fortress\Adapter\JqueryValidationArrayAdapter;
use UserFrosting\Fortress\RequestSchema;
use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface;
use UserFrosting\I18n\Translator;
Expand Down Expand Up @@ -49,6 +49,7 @@ public function __construct(
protected SiteLocaleInterface $siteLocale,
protected Translator $translator,
protected Twig $view,
protected JqueryValidationArrayAdapter $adapter,
) {
}

Expand Down Expand Up @@ -93,7 +94,6 @@ protected function handle(GroupInterface $group): array

// Load validation rules
$schema = $this->getSchema();
$validator = new JqueryValidationAdapter($schema, $this->translator);

return [
'group' => $group,
Expand All @@ -104,7 +104,7 @@ protected function handle(GroupInterface $group): array
'submit_text' => $this->translator->translate('UPDATE'),
],
'page' => [
'validators' => $validator->rules(),
'validators' => $this->adapter->rules($schema),
],
];
}
Expand Down
17 changes: 8 additions & 9 deletions app/src/Controller/Role/RoleCreateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use UserFrosting\Alert\AlertStream;
use UserFrosting\Fortress\RequestDataTransformer;
use UserFrosting\Fortress\RequestSchema;
use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface;
use UserFrosting\Fortress\ServerSideValidator;
use UserFrosting\I18n\Translator;
use UserFrosting\Fortress\Transformer\RequestDataTransformer;
use UserFrosting\Fortress\Validator\ServerSideValidator;
use UserFrosting\Sprinkle\Account\Authenticate\Authenticator;
use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\RoleInterface;
use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface;
Expand Down Expand Up @@ -56,8 +55,9 @@ public function __construct(
protected Authenticator $authenticator,
protected Connection $db,
protected RoleInterface $roleModel,
protected Translator $translator,
protected UserActivityLogger $userActivityLogger,
protected RequestDataTransformer $transformer,
protected ServerSideValidator $validator,
) {
}

Expand Down Expand Up @@ -92,8 +92,7 @@ protected function handle(Request $request): void
$schema = $this->getSchema();

// Whitelist and set parameter defaults
$transformer = new RequestDataTransformer($schema);
$data = $transformer->transform($params);
$data = $this->transformer->transform($schema, $params);

// Validate request data
$this->validateData($schema, $data);
Expand Down Expand Up @@ -153,10 +152,10 @@ protected function getSchema(): RequestSchemaInterface
*/
protected function validateData(RequestSchemaInterface $schema, array $data): void
{
$validator = new ServerSideValidator($schema, $this->translator);
if ($validator->validate($data) === false && is_array($validator->errors())) {
$errors = $this->validator->validate($schema, $data);
if (count($errors) !== 0) {
$e = new ValidationException();
$e->addErrors($validator->errors());
$e->addErrors($errors);

throw $e;
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/Controller/Role/RoleCreateModal.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Views\Twig;
use UserFrosting\Fortress\Adapter\JqueryValidationAdapter;
use UserFrosting\Fortress\Adapter\JqueryValidationArrayAdapter;
use UserFrosting\Fortress\RequestSchema;
use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface;
use UserFrosting\I18n\Translator;
Expand Down Expand Up @@ -47,6 +47,7 @@ public function __construct(
protected RoleInterface $roleModel,
protected Translator $translator,
protected Twig $view,
protected JqueryValidationArrayAdapter $adapter,
) {
}

Expand Down Expand Up @@ -76,7 +77,6 @@ protected function handle(): array

// Load the request schema & validator
$schema = $this->getSchema();
$validatorRegister = new JqueryValidationAdapter($schema, $this->translator);

// Determine form fields to hide/disable
$fields = [
Expand All @@ -93,7 +93,7 @@ protected function handle(): array
'submit_text' => $this->translator->translate('CREATE'),
],
'page' => [
'validators' => $validatorRegister->rules(),
'validators' => $this->adapter->rules($schema),
],
];
}
Expand Down
17 changes: 8 additions & 9 deletions app/src/Controller/Role/RoleEditAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
use Psr\Http\Message\ServerRequestInterface as Request;
use UserFrosting\Alert\AlertStream;
use UserFrosting\Config\Config;
use UserFrosting\Fortress\RequestDataTransformer;
use UserFrosting\Fortress\RequestSchema;
use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface;
use UserFrosting\Fortress\ServerSideValidator;
use UserFrosting\I18n\Translator;
use UserFrosting\Fortress\Transformer\RequestDataTransformer;
use UserFrosting\Fortress\Validator\ServerSideValidator;
use UserFrosting\Sprinkle\Account\Authenticate\Authenticator;
use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\RoleInterface;
use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface;
Expand Down Expand Up @@ -55,9 +54,10 @@ public function __construct(
protected Authenticator $authenticator,
protected Config $config,
protected Connection $db,
protected Translator $translator,
protected UserActivityLogger $userActivityLogger,
protected RoleInterface $roleModel,
protected RequestDataTransformer $transformer,
protected ServerSideValidator $validator,
) {
}

Expand Down Expand Up @@ -93,8 +93,7 @@ protected function handle(RoleInterface $role, Request $request): void
$schema = $this->getSchema();

// Whitelist and set parameter defaults
$transformer = new RequestDataTransformer($schema);
$data = $transformer->transform($params);
$data = $this->transformer->transform($schema, $params);

// Validate request data
$this->validateData($schema, $data);
Expand Down Expand Up @@ -164,10 +163,10 @@ protected function getSchema(): RequestSchemaInterface
*/
protected function validateData(RequestSchemaInterface $schema, array $data): void
{
$validator = new ServerSideValidator($schema, $this->translator);
if ($validator->validate($data) === false && is_array($validator->errors())) {
$errors = $this->validator->validate($schema, $data);
if (count($errors) !== 0) {
$e = new ValidationException();
$e->addErrors($validator->errors());
$e->addErrors($errors);

throw $e;
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/Controller/Role/RoleEditModal.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Views\Twig;
use UserFrosting\Fortress\Adapter\JqueryValidationAdapter;
use UserFrosting\Fortress\Adapter\JqueryValidationArrayAdapter;
use UserFrosting\Fortress\RequestSchema;
use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface;
use UserFrosting\I18n\Translator;
Expand Down Expand Up @@ -50,6 +50,7 @@ public function __construct(
protected SiteLocaleInterface $siteLocale,
protected Translator $translator,
protected Twig $view,
protected JqueryValidationArrayAdapter $adapter,
) {
}

Expand Down Expand Up @@ -94,7 +95,6 @@ protected function handle(RoleInterface $role): array

// Load validation rules
$schema = $this->getSchema();
$validator = new JqueryValidationAdapter($schema, $this->translator);

return [
'role' => $role,
Expand All @@ -105,7 +105,7 @@ protected function handle(RoleInterface $role): array
'submit_text' => $this->translator->translate('UPDATE'),
],
'page' => [
'validators' => $validator->rules(),
'validators' => $this->adapter->rules($schema),
],
];
}
Expand Down
17 changes: 8 additions & 9 deletions app/src/Controller/Role/RoleUpdateFieldAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
use Psr\Http\Message\ServerRequestInterface as Request;
use UserFrosting\Alert\AlertStream;
use UserFrosting\Config\Config;
use UserFrosting\Fortress\RequestDataTransformer;
use UserFrosting\Fortress\RequestSchema;
use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface;
use UserFrosting\Fortress\ServerSideValidator;
use UserFrosting\I18n\Translator;
use UserFrosting\Fortress\Transformer\RequestDataTransformer;
use UserFrosting\Fortress\Validator\ServerSideValidator;
use UserFrosting\Sprinkle\Account\Authenticate\Authenticator;
use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\RoleInterface;
use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface;
Expand Down Expand Up @@ -54,8 +53,9 @@ public function __construct(
protected Authenticator $authenticator,
protected Config $config,
protected Connection $db,
protected Translator $translator,
protected UserActivityLogger $userActivityLogger,
protected RequestDataTransformer $transformer,
protected ServerSideValidator $validator,
) {
}

Expand Down Expand Up @@ -126,8 +126,7 @@ protected function handle(
$schema = $this->getSchema();

// Whitelist and set parameter defaults
$transformer = new RequestDataTransformer($schema);
$data = $transformer->transform($params);
$data = $this->transformer->transform($schema, $params);

// Validate request data
$this->validateData($schema, $data);
Expand Down Expand Up @@ -185,10 +184,10 @@ protected function getSchema(): RequestSchemaInterface
*/
protected function validateData(RequestSchemaInterface $schema, array $data): void
{
$validator = new ServerSideValidator($schema, $this->translator);
if ($validator->validate($data) === false && is_array($validator->errors())) {
$errors = $this->validator->validate($schema, $data);
if (count($errors) !== 0) {
$e = new ValidationException();
$e->addErrors($validator->errors());
$e->addErrors($errors);

throw $e;
}
Expand Down
Loading

0 comments on commit 878fb19

Please sign in to comment.