-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[5.0] Decouple models from CMSObject #38949
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f8b8062
Decouple models from CMSObject
wilsonge 56a1306
Fix PHPCS
wilsonge c0510b2
Update libraries/src/MVC/Model/Exception/ModelExceptionInterface.php
wilsonge cdd73cf
Update libraries/src/Object/LegacyErrorHandlingTrait.php
wilsonge 2cf4bf3
Fix text
wilsonge 635730a
Merge branch '5.0-dev' into feature/model-object-remove
HLeithner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
libraries/src/MVC/Model/Exception/ModelExceptionInterface.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Joomla! Content Management System | ||
| * | ||
| * @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org> | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
|
|
||
| namespace Joomla\CMS\MVC\Model\Exception; | ||
|
|
||
| // phpcs:disable PSR1.Files.SideEffects | ||
| \defined('JPATH_PLATFORM') or die; | ||
| // phpcs:enable PSR1.Files.SideEffects | ||
|
|
||
| /** | ||
| * Interface that all exceptions stemming from the model should implement for processing by the controller | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| interface ModelExceptionInterface extends \Throwable | ||
| { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Joomla! Content Management System | ||
| * | ||
| * @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org> | ||
| * @license GNU General Public License version 2 or later; see LICENSE | ||
| */ | ||
|
|
||
| namespace Joomla\CMS\Object; | ||
|
|
||
| // phpcs:disable PSR1.Files.SideEffects | ||
| \defined('JPATH_PLATFORM') or die; | ||
| // phpcs:enable PSR1.Files.SideEffects | ||
|
|
||
| /** | ||
| * Trait which contains the legacy methods that formerly were inherited from \Joomla\CMS\Object\CMSObject to set and | ||
| * get errors in a class. Strategically deprecated in favour of exceptions which implement the interface | ||
| * \Joomla\CMS\MVC\Model\Exception\ModelExceptionInterface | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| * @deprecated 6.0 Will be removed in favour of throwing exceptions | ||
| */ | ||
| trait LegacyErrorHandlingTrait | ||
| { | ||
| /** | ||
| * An array of error messages or Exception objects. | ||
| * | ||
| * @var array | ||
| * @since 1.7.0 | ||
| * @deprecated 3.1.4 JError has been deprecated | ||
| */ | ||
| // phpcs:disable PSR2.Classes.PropertyDeclaration | ||
| protected $_errors = array(); | ||
| // phpcs:enable PSR2.Classes.PropertyDeclaration | ||
|
|
||
| /** | ||
| * Get the most recent error message. | ||
| * | ||
| * @param integer $i Option error index. | ||
| * @param boolean $toString Indicates if Exception objects should return their error message. | ||
| * | ||
| * @return string Error message | ||
| * | ||
| * @since 1.7.0 | ||
| * @deprecated 3.1.4 JError has been deprecated | ||
| */ | ||
| public function getError($i = null, $toString = true) | ||
| { | ||
| // Find the error | ||
| if ($i === null) { | ||
| // Default, return the last message | ||
| $error = end($this->_errors); | ||
| } elseif (!\array_key_exists($i, $this->_errors)) { | ||
| // If $i has been specified but does not exist, return false | ||
| return false; | ||
| } else { | ||
| $error = $this->_errors[$i]; | ||
| } | ||
|
|
||
| // Check if only the string is requested | ||
| if ($error instanceof \Exception && $toString) { | ||
| return $error->getMessage(); | ||
| } | ||
|
|
||
| return $error; | ||
| } | ||
|
|
||
| /** | ||
| * Return all errors, if any. | ||
| * | ||
| * @return array Array of error messages. | ||
| * | ||
| * @since 1.7.0 | ||
| * @deprecated 3.1.4 JError has been deprecated | ||
| */ | ||
| public function getErrors() | ||
| { | ||
| return $this->_errors; | ||
| } | ||
|
|
||
| /** | ||
| * Add an error message. | ||
| * | ||
| * @param string $error Error message. | ||
| * | ||
| * @return void | ||
| * | ||
| * @since 1.7.0 | ||
| * @deprecated 3.1.4 JError has been deprecated | ||
| */ | ||
| public function setError($error) | ||
| { | ||
| $this->_errors[] = $error; | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.