first commit
This commit is contained in:
commit
1218dd1517
12716 files changed
+989233
No files matched your search
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Extbase\Error;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
/**
|
||||
* An object representation of a generic error. Subclass this to create
|
||||
* more specific errors if necessary.
|
||||
*/
|
||||
class Error extends Message
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $message = 'Unknown error';
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Extbase\Error;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
/**
|
||||
* An object representation of a generic message. Usually, you will use Error, Warning or Notice instead of this one.
|
||||
*/
|
||||
class Message
|
||||
{
|
||||
/**
|
||||
* The default (english) error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $message = 'Unknown message';
|
||||
|
||||
/**
|
||||
* The error code
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $code;
|
||||
|
||||
/**
|
||||
* The message arguments. Will be replaced in the message body.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [];
|
||||
|
||||
/**
|
||||
* An optional title for the message (used eg. in flashMessages).
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title = '';
|
||||
|
||||
/**
|
||||
* Constructs this error
|
||||
*
|
||||
* @param string $message An english error message which is used if no other error message can be resolved
|
||||
* @param int $code A unique error code
|
||||
* @param array $arguments Array of arguments to be replaced in message
|
||||
* @param string $title optional title for the message
|
||||
*/
|
||||
public function __construct($message, $code, array $arguments = [], $title = '')
|
||||
{
|
||||
$this->message = $message;
|
||||
$this->code = $code;
|
||||
$this->arguments = $arguments;
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the error message
|
||||
*
|
||||
* @return string The error message
|
||||
*/
|
||||
public function getMessage()
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the error code
|
||||
*
|
||||
* @return string The error code
|
||||
*/
|
||||
public function getCode()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get arguments
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getArguments()
|
||||
{
|
||||
return $this->arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the rendered message
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
if (!empty($this->arguments)) {
|
||||
return vsprintf($this->message, $this->arguments);
|
||||
}
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts this error into a string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->render();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Extbase\Error;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
/**
|
||||
* An object representation of a generic notice. Subclass this to create
|
||||
* more specific notices if necessary.
|
||||
*/
|
||||
class Notice extends Message
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $message = 'Unknown notice';
|
||||
}
|
||||
@@ -0,0 +1,456 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Extbase\Error;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
/**
|
||||
* Result object for operations dealing with objects, such as the Property Mapper or the Validators.
|
||||
*/
|
||||
class Result
|
||||
{
|
||||
/**
|
||||
* @var Error[]
|
||||
*/
|
||||
protected $errors = [];
|
||||
|
||||
/**
|
||||
* Caches the existence of errors
|
||||
* @var bool
|
||||
*/
|
||||
protected $errorsExist = false;
|
||||
|
||||
/**
|
||||
* @var Warning[]
|
||||
*/
|
||||
protected $warnings = [];
|
||||
|
||||
/**
|
||||
* Caches the existence of warning
|
||||
* @var bool
|
||||
*/
|
||||
protected $warningsExist = false;
|
||||
|
||||
/**
|
||||
* @var Notice[]
|
||||
*/
|
||||
protected $notices = [];
|
||||
|
||||
/**
|
||||
* Caches the existence of notices
|
||||
* @var bool
|
||||
*/
|
||||
protected $noticesExist = false;
|
||||
|
||||
/**
|
||||
* The result objects for the sub properties
|
||||
*
|
||||
* @var Result[]
|
||||
*/
|
||||
protected $propertyResults = [];
|
||||
|
||||
/**
|
||||
* @var Result
|
||||
*/
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
* Injects the parent result and propagates the
|
||||
* cached error states upwards
|
||||
*
|
||||
* @param Result $parent
|
||||
*/
|
||||
public function setParent(Result $parent)
|
||||
{
|
||||
if ($this->parent !== $parent) {
|
||||
$this->parent = $parent;
|
||||
if ($this->hasErrors()) {
|
||||
$parent->setErrorsExist();
|
||||
}
|
||||
if ($this->hasWarnings()) {
|
||||
$parent->setWarningsExist();
|
||||
}
|
||||
if ($this->hasNotices()) {
|
||||
$parent->setNoticesExist();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an error to the current Result object
|
||||
*
|
||||
* @param Error $error
|
||||
*/
|
||||
public function addError(Error $error)
|
||||
{
|
||||
$this->errors[] = $error;
|
||||
$this->setErrorsExist();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a warning to the current Result object
|
||||
*
|
||||
* @param Warning $warning
|
||||
*/
|
||||
public function addWarning(Warning $warning)
|
||||
{
|
||||
$this->warnings[] = $warning;
|
||||
$this->setWarningsExist();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a notice to the current Result object
|
||||
*
|
||||
* @param Notice $notice
|
||||
*/
|
||||
public function addNotice(Notice $notice)
|
||||
{
|
||||
$this->notices[] = $notice;
|
||||
$this->setNoticesExist();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all errors in the current Result object (non-recursive)
|
||||
*
|
||||
* @return Error[]
|
||||
*/
|
||||
public function getErrors()
|
||||
{
|
||||
return $this->errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all warnings in the current Result object (non-recursive)
|
||||
*
|
||||
* @return Warning[]
|
||||
*/
|
||||
public function getWarnings()
|
||||
{
|
||||
return $this->warnings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all notices in the current Result object (non-recursive)
|
||||
*
|
||||
* @return Notice[]
|
||||
*/
|
||||
public function getNotices()
|
||||
{
|
||||
return $this->notices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first error object of the current Result object (non-recursive)
|
||||
*
|
||||
* @return Error
|
||||
*/
|
||||
public function getFirstError()
|
||||
{
|
||||
reset($this->errors);
|
||||
return current($this->errors);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first warning object of the current Result object (non-recursive)
|
||||
*
|
||||
* @return Warning
|
||||
*/
|
||||
public function getFirstWarning()
|
||||
{
|
||||
reset($this->warnings);
|
||||
return current($this->warnings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first notice object of the curren Result object (non-recursive)
|
||||
*
|
||||
* @return Notice
|
||||
*/
|
||||
public function getFirstNotice()
|
||||
{
|
||||
reset($this->notices);
|
||||
return current($this->notices);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a Result object for the given property path. This is
|
||||
* a fluent interface, so you will proboably use it like:
|
||||
* $result->forProperty('foo.bar')->getErrors() -- to get all errors
|
||||
* for property "foo.bar"
|
||||
*
|
||||
* @param string $propertyPath
|
||||
* @return Result
|
||||
*/
|
||||
public function forProperty($propertyPath)
|
||||
{
|
||||
if ($propertyPath === '' || $propertyPath === null) {
|
||||
return $this;
|
||||
}
|
||||
if (strpos($propertyPath, '.') !== false) {
|
||||
return $this->recurseThroughResult(explode('.', $propertyPath));
|
||||
}
|
||||
if (!isset($this->propertyResults[$propertyPath])) {
|
||||
$this->propertyResults[$propertyPath] = new self();
|
||||
$this->propertyResults[$propertyPath]->setParent($this);
|
||||
}
|
||||
return $this->propertyResults[$propertyPath];
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal use only!
|
||||
*
|
||||
* @param array $pathSegments
|
||||
* @return Result
|
||||
*/
|
||||
public function recurseThroughResult(array $pathSegments)
|
||||
{
|
||||
if (empty($pathSegments)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$propertyName = array_shift($pathSegments);
|
||||
|
||||
if (!isset($this->propertyResults[$propertyName])) {
|
||||
$this->propertyResults[$propertyName] = new self();
|
||||
$this->propertyResults[$propertyName]->setParent($this);
|
||||
}
|
||||
|
||||
return $this->propertyResults[$propertyName]->recurseThroughResult($pathSegments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the error cache to TRUE and propagates the information
|
||||
* upwards the Result-Object Tree
|
||||
*/
|
||||
protected function setErrorsExist()
|
||||
{
|
||||
$this->errorsExist = true;
|
||||
if ($this->parent !== null) {
|
||||
$this->parent->setErrorsExist();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the warning cache to TRUE and propagates the information
|
||||
* upwards the Result-Object Tree
|
||||
*/
|
||||
protected function setWarningsExist()
|
||||
{
|
||||
$this->warningsExist = true;
|
||||
if ($this->parent !== null) {
|
||||
$this->parent->setWarningsExist();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the notices cache to TRUE and propagates the information
|
||||
* upwards the Result-Object Tree
|
||||
*/
|
||||
protected function setNoticesExist()
|
||||
{
|
||||
$this->noticesExist = true;
|
||||
if ($this->parent !== null) {
|
||||
$this->parent->setNoticesExist();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the current Result object have Notices, Errors or Warnings? (Recursively)
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasMessages()
|
||||
{
|
||||
return $this->errorsExist || $this->noticesExist || $this->warningsExist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the result
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$this->errors = [];
|
||||
$this->notices = [];
|
||||
$this->warnings = [];
|
||||
|
||||
$this->warningsExist = false;
|
||||
$this->noticesExist = false;
|
||||
$this->errorsExist = false;
|
||||
|
||||
$this->propertyResults = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal use only!
|
||||
*
|
||||
* @param string $propertyName
|
||||
* @param string $checkerMethodName
|
||||
* @return bool
|
||||
*/
|
||||
protected function hasProperty($propertyName, $checkerMethodName)
|
||||
{
|
||||
if (!empty($this->{$propertyName})) {
|
||||
return true;
|
||||
}
|
||||
foreach ($this->propertyResults as $subResult) {
|
||||
if ($subResult->{$checkerMethodName}()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the current Result object have Errors? (Recursively)
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasErrors()
|
||||
{
|
||||
return $this->hasProperty('errors', 'hasErrors');
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the current Result object have Warnings? (Recursively)
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasWarnings()
|
||||
{
|
||||
return $this->hasProperty('warnings', 'hasWarnings');
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the current Result object have Notices? (Recursively)
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasNotices()
|
||||
{
|
||||
return $this->hasProperty('notices', 'hasNotices');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all Error objects recursively. The result is an array,
|
||||
* where the key is the property path where the error occurred, and the
|
||||
* value is a list of all errors (stored as array)
|
||||
*
|
||||
* @return Error[]
|
||||
*/
|
||||
public function getFlattenedErrors()
|
||||
{
|
||||
$result = [];
|
||||
$this->flattenTree('errors', $result, []);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all Warning objects recursively. The result is an array,
|
||||
* where the key is the property path where the warning occurred, and the
|
||||
* value is a list of all warnings (stored as array)
|
||||
*
|
||||
* @return Warning[]
|
||||
*/
|
||||
public function getFlattenedWarnings()
|
||||
{
|
||||
$result = [];
|
||||
$this->flattenTree('warnings', $result, []);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all Notice objects recursively. The result is an array,
|
||||
* where the key is the property path where the notice occurred, and the
|
||||
* value is a list of all notices (stored as array)
|
||||
*
|
||||
* @return Notice[]
|
||||
*/
|
||||
public function getFlattenedNotices()
|
||||
{
|
||||
$result = [];
|
||||
$this->flattenTree('notices', $result, []);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only use internally!
|
||||
*
|
||||
* Flatten a tree of Result objects, based on a certain property.
|
||||
*
|
||||
* @param string $propertyName
|
||||
* @param array $result
|
||||
* @param array $level
|
||||
*/
|
||||
public function flattenTree($propertyName, &$result, $level)
|
||||
{
|
||||
if (!empty($this->$propertyName)) {
|
||||
$result[implode('.', $level)] = $this->$propertyName;
|
||||
}
|
||||
foreach ($this->propertyResults as $subPropertyName => $subResult) {
|
||||
$level[] = $subPropertyName;
|
||||
$subResult->flattenTree($propertyName, $result, $level);
|
||||
array_pop($level);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge the given Result object into this one.
|
||||
*
|
||||
* @param Result $otherResult
|
||||
*/
|
||||
public function merge(Result $otherResult)
|
||||
{
|
||||
if ($otherResult->errorsExist) {
|
||||
$this->mergeProperty($otherResult, 'getErrors', 'addError');
|
||||
}
|
||||
if ($otherResult->warningsExist) {
|
||||
$this->mergeProperty($otherResult, 'getWarnings', 'addWarning');
|
||||
}
|
||||
if ($otherResult->noticesExist) {
|
||||
$this->mergeProperty($otherResult, 'getNotices', 'addNotice');
|
||||
}
|
||||
|
||||
foreach ($otherResult->getSubResults() as $subPropertyName => $subResult) {
|
||||
/** @var Result $subResult */
|
||||
if (array_key_exists($subPropertyName, $this->propertyResults) && $this->propertyResults[$subPropertyName]->hasMessages()) {
|
||||
$this->forProperty($subPropertyName)->merge($subResult);
|
||||
} else {
|
||||
$this->propertyResults[$subPropertyName] = $subResult;
|
||||
$subResult->setParent($this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge a single property from the other result object.
|
||||
*
|
||||
* @param Result $otherResult
|
||||
* @param string $getterName
|
||||
* @param string $adderName
|
||||
*/
|
||||
protected function mergeProperty(Result $otherResult, $getterName, $adderName)
|
||||
{
|
||||
foreach ($otherResult->$getterName() as $messageInOtherResult) {
|
||||
$this->$adderName($messageInOtherResult);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all sub Result objects available.
|
||||
*
|
||||
* @return Result[]
|
||||
*/
|
||||
public function getSubResults()
|
||||
{
|
||||
return $this->propertyResults;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Extbase\Error;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
/**
|
||||
* An object representation of a generic warning. Subclass this to create
|
||||
* more specific warnings if necessary.
|
||||
*/
|
||||
class Warning extends Message
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $message = 'Unknown warning';
|
||||
}
|
||||
Reference in new issue
Block a user