Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved structure for error message generation in configuration pages #29494

Open
wants to merge 29 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
393b7c8
Adding tests
JevgenijVisockij Aug 31, 2022
4507b03
Fixed test
JevgenijVisockij Aug 31, 2022
5d7a486
Added missing comment for function
JevgenijVisockij Sep 1, 2022
eaea148
CS fixer fix
JevgenijVisockij Sep 6, 2022
b659ae4
Fixing label provider test
JevgenijVisockij Sep 6, 2022
4dbeec1
Fixing configuration error factory test
JevgenijVisockij Sep 7, 2022
ea18922
Removed accidentally added exception
JevgenijVisockij Oct 17, 2022
0e07dc8
Removed accidentally added exception
JevgenijVisockij Oct 17, 2022
f509c54
Adding back const to avoid BC break, change test to use interface
JevgenijVisockij Nov 23, 2022
f83d050
Adding back old collection and error and depricating them
JevgenijVisockij Apr 18, 2023
2257542
Added deprication trigger error
JevgenijVisockij Nov 23, 2022
bd51aef
Removed not needed language repository from AdministrationConfigurati…
JevgenijVisockij Nov 29, 2022
059386b
Fixing unit tests
JevgenijVisockij Nov 29, 2022
fd1ec28
Removed unneeded comment
JevgenijVisockij Nov 29, 2022
2303177
Removed unneeded public, changing classes naming to FQCN
JevgenijVisockij Dec 5, 2022
13be1cd
Removing uneeded class
JevgenijVisockij Dec 5, 2022
e03ab92
Replacing with symfony contracts
JevgenijVisockij Dec 6, 2022
53cc57a
CS fixer fix
JevgenijVisockij Dec 6, 2022
e79d002
Adding autowiring to new services
JevgenijVisockij Jan 11, 2023
8bbd639
Using the class in AdministrationController.php
JevgenijVisockij Jan 11, 2023
00ef072
Update src/PrestaShopBundle/Form/ErrorMessage/Factory/AdministrationC…
JevgenijVisockij Mar 27, 2023
ce7d80f
Made ConfigurationErrorFactory public because it was causing fatal
JevgenijVisockij Mar 30, 2023
ae400cc
Refactored yml file to use autowire properly
JevgenijVisockij Mar 30, 2023
667c29d
Adding back label provider and ConfigurationErrorCollection.php
JevgenijVisockij Apr 18, 2023
311f56d
Cs Fixer fix
JevgenijVisockij Apr 19, 2023
f9a84a1
Fixing to use MAX_COOKIE_VALUE from cookie options
JevgenijVisockij Apr 26, 2023
c046cbc
Cs Fixer fix
JevgenijVisockij Apr 26, 2023
f32ea6d
syntax fix
JevgenijVisockij Apr 26, 2023
ed8990a
Fixed bug with wrong error
JevgenijVisockij May 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
73 changes: 73 additions & 0 deletions src/Core/Form/ErrorMessage/AbstractConfigurationError.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

declare(strict_types=1);

namespace PrestaShop\PrestaShop\Core\Form\ErrorMessage;

/**
* Abstract configuration error that contains main fields for the error.
* The errors extending it are mostly needed to store constants for specific errors or
* to be recognized in ConfigurationErrorMessage providers
*/
class AbstractConfigurationError implements ConfigurationErrorInterface
{
/**
* @var int
*/
private $errorCode;

/**
* @var string
*/
private $fieldName;

/**
* @param int $errorCode
* @param string $fieldName
*/
public function __construct(int $errorCode, string $fieldName)
{
$this->errorCode = $errorCode;
$this->fieldName = $fieldName;
}

/**
* @return int
*/
public function getErrorCode(): int
{
return $this->errorCode;
}

/**
* @return string
*/
public function getFieldName(): string
{
return $this->fieldName;
}
}
36 changes: 36 additions & 0 deletions src/Core/Form/ErrorMessage/AdministrationConfigurationError.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

declare(strict_types=1);

namespace PrestaShop\PrestaShop\Core\Form\ErrorMessage;

/** Configuration error specific to administration page */
class AdministrationConfigurationError extends AbstractConfigurationError
{
public const ERROR_COOKIE_LIFETIME_MAX_VALUE_EXCEEDED = 1;
public const ERROR_COOKIE_SAMESITE_NONE = 2;
}
35 changes: 35 additions & 0 deletions src/Core/Form/ErrorMessage/CommonConfigurationError.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

declare(strict_types=1);

namespace PrestaShop\PrestaShop\Core\Form\ErrorMessage;

/** Common configuration error that can appear in any configuration page */
class CommonConfigurationError extends AbstractConfigurationError
{
public const ERROR_NOT_NUMERIC_OR_LOWER_THAN_ZERO = 1;
}
40 changes: 40 additions & 0 deletions src/Core/Form/ErrorMessage/ConfigurationErrorCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

declare(strict_types=1);

namespace PrestaShop\PrestaShop\Core\Form\ErrorMessage;

use PrestaShop\PrestaShop\Core\Data\AbstractTypedCollection;

/** Collection of configuration form errors */
class ConfigurationErrorCollection extends AbstractTypedCollection
{
protected function getType(): string
{
return ConfigurationErrorInterface::class;
}
}
41 changes: 41 additions & 0 deletions src/Core/Form/ErrorMessage/ConfigurationErrorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

namespace PrestaShop\PrestaShop\Core\Form\ErrorMessage;

/** Interface for configuration errors which can happen when saving configuration forms */
interface ConfigurationErrorInterface
{
/**
* @return int
*/
public function getErrorCode(): int;

/**
* @return string
*/
public function getFieldName(): string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

namespace PrestaShop\PrestaShop\Core\Form\ErrorMessage\Factory;

use PrestaShop\PrestaShop\Core\Form\ErrorMessage\ConfigurationErrorInterface;

/** Interface for configuration error factories which are responsible for returning error messages for configuration errors */
interface ConfigurationErrorMessageProviderInterface
{
/**
* @param ConfigurationErrorInterface $error
* @param string $label
*
* @return string|null
*/
public function getErrorMessageForConfigurationError(ConfigurationErrorInterface $error, string $label): ?string;
}