diff --git a/app/code/Magento/Catalog/Model/Entity/Attribute.php b/app/code/Magento/Catalog/Model/Entity/Attribute.php old mode 100644 new mode 100755 index da907bde71f75ca5ef9f2147cfc89c3070ef8c41..ca1e3038e03909c756d7b793669393f78457656e --- a/app/code/Magento/Catalog/Model/Entity/Attribute.php +++ b/app/code/Magento/Catalog/Model/Entity/Attribute.php @@ -139,14 +139,14 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute * Processing object before save data * * @return \Magento\Framework\Model\AbstractModel - * @throws \Magento\Eav\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function beforeSave() { try { $this->attrLockValidator->validate($this); } catch (\Magento\Framework\Exception\LocalizedException $exception) { - throw new \Magento\Eav\Exception(__($exception->getMessage())); + throw new \Magento\Framework\Exception\LocalizedException(__($exception->getMessage())); } $this->setData('modulePrefix', self::MODULE_NAME); diff --git a/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Sku.php b/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Sku.php old mode 100644 new mode 100755 index 2272520c1a4fdfdadc63791d8fb4d8451f104481..5d21012f3964f7798aea8822c425192146d9481d --- a/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Sku.php +++ b/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Sku.php @@ -44,7 +44,7 @@ class Sku extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend * * @param Product $object * @return bool - * @throws \Magento\Eav\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @throws \Magento\Framework\Exception\LocalizedException */ public function validate($object) @@ -52,7 +52,7 @@ class Sku extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend $attrCode = $this->getAttribute()->getAttributeCode(); $value = $object->getData($attrCode); if ($this->getAttribute()->getIsRequired() && strlen($value) === 0) { - throw new \Magento\Eav\Exception(__('The value of attribute "%1" must be set', $attrCode)); + throw new \Magento\Framework\Exception\LocalizedException(__('The value of attribute "%1" must be set', $attrCode)); } if ($this->string->strlen($object->getSku()) > self::SKU_MAX_LENGTH) { diff --git a/app/code/Magento/Catalog/Model/Product/Option/Type/File.php b/app/code/Magento/Catalog/Model/Product/Option/Type/File.php index f1f80f7701c0cf8e260892361e90110616656a31..21a1ecedb1f403f2bbe222e6b2e5542348ab1368 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Type/File.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Type/File.php @@ -181,6 +181,7 @@ class File extends \Magento\Catalog\Model\Product\Option\Type\DefaultType * @param array $values All product option values, i.e. array (option_id => mixed, option_id => mixed...) * @return $this * @throws LocalizedException + * @throws \Exception * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function validateUserValue($values) @@ -222,9 +223,6 @@ class File extends \Magento\Catalog\Model\Product\Option\Type\DefaultType $value = $this->validatorFile->setProduct($this->getProduct()) ->validate($this->_getProcessingParams(), $option); $this->setUserValue($value); - } catch (\Magento\Framework\Exception\File\LargeSizeException $largeSizeException) { - $this->setIsValid(false); - throw new LocalizedException(__($largeSizeException->getMessage())); } catch (ProductException $e) { switch ($this->getProcessMode()) { case \Magento\Catalog\Model\Product\Type\AbstractType::PROCESS_MODE_FULL: @@ -236,7 +234,7 @@ class File extends \Magento\Catalog\Model\Product\Option\Type\DefaultType } } catch (\Magento\Framework\Validator\Exception $e) { $this->setUserValue(null); - } catch (\Magento\Framework\Exception\File\ValidatorException $e) { + } catch (LocalizedException $e) { $this->setIsValid(false); throw new LocalizedException(__($e->getMessage())); } catch (\Exception $e) { diff --git a/app/code/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFile.php b/app/code/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFile.php index beb1b3d2f8da1b5421b751aab1ee24d36de49c63..9f8c3c955c96e7e08e580c5de60f5fcb3c3c77f1 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFile.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFile.php @@ -9,6 +9,7 @@ namespace Magento\Catalog\Model\Product\Option\Type\File; use Magento\Catalog\Model\Product; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Catalog\Model\Product\Exception as ProductException; +use Magento\Framework\Exception\LocalizedException; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -89,10 +90,12 @@ class ValidatorFile extends Validator * @param \Magento\Framework\Object $processingParams * @param \Magento\Catalog\Model\Product\Option $option * @return array - * @throws \Magento\Framework\Exception\LocalizedException - * @throws \Zend_File_Transfer_Exception + * @throws LocalizedException + * @throws ProductException + * @throws \Exception + * @throws \Magento\Framework\Exception\InputException * @throws \Magento\Framework\Validator\Exception - * @throws \Magento\Catalog\Model\Product\Exception + * @throws \Zend_File_Transfer_Exception * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ @@ -116,7 +119,7 @@ class ValidatorFile extends Validator // when file exceeds the upload_max_filesize, $_FILES is empty if ($this->validateContentLength()) { $value = $this->fileSize->getMaxFileSizeInMb(); - throw new \Magento\Framework\Exception\File\LargeSizeException( + throw new LocalizedException( __('The file you uploaded is larger than %1 Megabytes allowed by server', $value) ); } else { @@ -188,12 +191,10 @@ class ValidatorFile extends Validator $errors = $this->getValidatorErrors($upload->getErrors(), $fileInfo, $option); if (count($errors) > 0) { - throw new \Magento\Framework\Exception\File\ValidatorException(__(implode("\n", $errors))); + throw new LocalizedException(__(implode("\n", $errors))); } } else { - throw new \Magento\Framework\Exception\File\ValidatorException( - __('Please specify the product\'s required option(s).') - ); + throw new LocalizedException(__('Please specify the product\'s required option(s).')); } return $userValue; } diff --git a/app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php b/app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php old mode 100644 new mode 100755 index a2cfaba45a1e0ccdf826cce274ad17864eb00ca7..af1dee02649e9bb3fdcf56a7d40404b79a7c65f7 --- a/app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php +++ b/app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php @@ -562,7 +562,7 @@ class IndexBuilder * @param int $websiteId * @param int|null $productId * @return \Zend_Db_Statement_Interface - * @throws \Magento\Eav\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function getRuleProductsStmt($websiteId, $productId = null) { diff --git a/app/code/Magento/Developer/Model/View/Layout/Plugin.php b/app/code/Magento/Developer/Model/View/Layout/Plugin.php new file mode 100644 index 0000000000000000000000000000000000000000..4f4f059813d58552730aea52894ce610ce327799 --- /dev/null +++ b/app/code/Magento/Developer/Model/View/Layout/Plugin.php @@ -0,0 +1,61 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Developer\Model\View\Layout; + +use Magento\Framework\App\State; +use Magento\Framework\Exception\LocalizedException; +use Psr\Log\LoggerInterface as Logger; + +/** + * Layout plugin that handle exceptions + */ +class Plugin +{ + /** + * @var State + */ + protected $appState; + + /** + * @var \Psr\Log\LoggerInterface + */ + protected $logger; + + /** + * @param State $appState + * @param Logger $logger + */ + public function __construct( + State $appState, + Logger $logger + ) { + $this->appState = $appState; + $this->logger = $logger; + } + + /** + * @param \Magento\Framework\View\Layout $subject + * @param callable $proceed + * @param string $name + * @return string + * @throws \Exception + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function aroundRenderNonCachedElement(\Magento\Framework\View\Layout $subject, \Closure $proceed, $name) + { + $result = ''; + try { + $result = $proceed($name); + } catch (\Exception $e) { + if ($this->appState->getMode() === State::MODE_DEVELOPER) { + throw $e; + } + $message = ($e instanceof LocalizedException) ? $e->getLogMessage() : $e->getMessage(); + $this->logger->critical($message); + } + return $result; + } +} diff --git a/app/code/Magento/Developer/etc/di.xml b/app/code/Magento/Developer/etc/di.xml index d923b3d55553d83da4bd4d54defdd00bf2baf8d6..1a21f191e09094fc0f9275ddabd632807fbdc1ff 100644 --- a/app/code/Magento/Developer/etc/di.xml +++ b/app/code/Magento/Developer/etc/di.xml @@ -10,6 +10,9 @@ <type name="Magento\Framework\View\TemplateEngineFactory"> <plugin name="debug_hints" type="Magento\Developer\Model\TemplateEngine\Plugin\DebugHints" sortOrder="10"/> </type> + <type name="Magento\Framework\View\Layout"> + <plugin name="exception_handler" type="Magento\Developer\Model\View\Layout\Plugin" sortOrder="10"/> + </type> <type name="Magento\Framework\View\Result\Page"> <arguments> <argument name="pageConfigRendererFactory" xsi:type="object">Magento\Developer\Model\View\Page\Config\RendererFactory</argument> diff --git a/app/code/Magento/Eav/Exception.php b/app/code/Magento/Eav/Exception.php deleted file mode 100644 index ed5a6dd53d7140f8088c4cbc8e32d4a8c8a18ad7..0000000000000000000000000000000000000000 --- a/app/code/Magento/Eav/Exception.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Eav; - -class Exception extends \Magento\Framework\Exception\LocalizedException -{ -} diff --git a/app/code/Magento/Eav/Model/Entity/AbstractEntity.php b/app/code/Magento/Eav/Model/Entity/AbstractEntity.php old mode 100644 new mode 100755 index cc3d3950d01b2d66fe48129d35506daa3a967a91..ac8c5805f4b72f8727d09a4a4cbc71a0f05c2258 --- a/app/code/Magento/Eav/Model/Entity/AbstractEntity.php +++ b/app/code/Magento/Eav/Model/Entity/AbstractEntity.php @@ -14,7 +14,7 @@ use Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend; use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource; use Magento\Framework\App\Config\Element; use Magento\Framework\Model\AbstractModel; -use Magento\Eav\Exception as EavException; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Model\Resource\Db\ObjectRelationProcessor; use Magento\Framework\Model\Resource\Db\TransactionManagerInterface; @@ -334,12 +334,12 @@ abstract class AbstractEntity extends \Magento\Framework\Model\Resource\Abstract * Retrieve current entity config * * @return Type - * @throws EavException + * @throws LocalizedException */ public function getEntityType() { if (empty($this->_type)) { - throw new EavException(__('Entity is not initialized')); + throw new LocalizedException(__('Entity is not initialized')); } return $this->_type; } @@ -372,7 +372,7 @@ abstract class AbstractEntity extends \Magento\Framework\Model\Resource\Abstract * * @param array|string|null $attributes * @return $this - * @throws EavException + * @throws LocalizedException */ public function unsetAttributes($attributes = null) { @@ -387,7 +387,7 @@ abstract class AbstractEntity extends \Magento\Framework\Model\Resource\Abstract } if (!is_array($attributes)) { - throw new EavException(__('Unknown parameter')); + throw new LocalizedException(__('Unknown parameter')); } foreach ($attributes as $attrCode) { diff --git a/app/code/Magento/Eav/Model/Entity/Attribute.php b/app/code/Magento/Eav/Model/Entity/Attribute.php old mode 100644 new mode 100755 index df877f97a92afdec4ea0cdb857e10d3a90f84ba9..5682724a47726b8504a4862eca31b2c8c75b2bfb --- a/app/code/Magento/Eav/Model/Entity/Attribute.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute.php @@ -5,7 +5,7 @@ */ namespace Magento\Eav\Model\Entity; -use Magento\Eav\Exception as EavException; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Api\AttributeValueFactory; /** @@ -213,7 +213,7 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im * Prepare data for save * * @return $this - * @throws EavException + * @throws LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ @@ -221,7 +221,7 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im { // prevent overriding product data if (isset($this->_data['attribute_code']) && $this->reservedAttributeList->isReservedAttribute($this)) { - throw new EavException( + throw new LocalizedException( __( 'The attribute code \'%1\' is reserved by system. Please try another attribute code', $this->_data['attribute_code'] @@ -240,7 +240,7 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im ['max' => self::ATTRIBUTE_CODE_MAX_LENGTH] ) ) { - throw new EavException( + throw new LocalizedException( __('Maximum length of attribute code must be less than %1 symbols', self::ATTRIBUTE_CODE_MAX_LENGTH) ); } @@ -252,7 +252,7 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im $numberFormatter = new \NumberFormatter($this->_localeResolver->getLocale(), \NumberFormatter::DECIMAL); $defaultValue = $numberFormatter->parse($defaultValue); if ($defaultValue === false) { - throw new EavException(__('Invalid default decimal value')); + throw new LocalizedException(__('Invalid default decimal value')); } $this->setDefaultValue($defaultValue); } @@ -275,7 +275,7 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im $defaultValue = \IntlDateFormatter::formatObject(new \DateTime($defaultValue), $format); $this->setDefaultValue($defaultValue); } catch (\Exception $e) { - throw new EavException(__('Invalid default date')); + throw new LocalizedException(__('Invalid default date')); } } } diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/AbstractAttribute.php b/app/code/Magento/Eav/Model/Entity/Attribute/AbstractAttribute.php old mode 100644 new mode 100755 index e52ab0860e2022a332732b550391e45fabb5e305..9dbc048d711ecb5ddbcb936e1cdad322200c61c7 --- a/app/code/Magento/Eav/Model/Entity/Attribute/AbstractAttribute.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/AbstractAttribute.php @@ -6,7 +6,7 @@ namespace Magento\Eav\Model\Entity\Attribute; -use Magento\Eav\Exception as EavException; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Api\AttributeValueFactory; /** @@ -181,7 +181,7 @@ abstract class AbstractAttribute extends \Magento\Framework\Model\AbstractExtens * @param string|int|\Magento\Eav\Model\Entity\Type $entityType * @param string $code * @return $this - * @throws EavException + * @throws LocalizedException */ public function loadByCode($entityType, $code) { @@ -195,7 +195,7 @@ abstract class AbstractAttribute extends \Magento\Framework\Model\AbstractExtens $entityTypeId = $entityType->getId(); } if (empty($entityTypeId)) { - throw new EavException(__('Invalid entity supplied')); + throw new LocalizedException(__('Invalid entity supplied')); } $this->_getResource()->loadByCode($this, $entityTypeId, $code); $this->_afterLoad(); @@ -461,7 +461,7 @@ abstract class AbstractAttribute extends \Magento\Framework\Model\AbstractExtens * Retrieve backend instance * * @return \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend - * @throws EavException + * @throws LocalizedException */ public function getBackend() { @@ -471,7 +471,7 @@ abstract class AbstractAttribute extends \Magento\Framework\Model\AbstractExtens } $backend = $this->_universalFactory->create($this->getBackendModel()); if (!$backend) { - throw new EavException(__('Invalid backend model specified: ' . $this->getBackendModel())); + throw new LocalizedException(__('Invalid backend model specified: ' . $this->getBackendModel())); } $this->_backend = $backend->setAttribute($this); } @@ -500,7 +500,7 @@ abstract class AbstractAttribute extends \Magento\Framework\Model\AbstractExtens * Retrieve source instance * * @return \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource - * @throws EavException + * @throws LocalizedException */ public function getSource() { @@ -510,7 +510,7 @@ abstract class AbstractAttribute extends \Magento\Framework\Model\AbstractExtens } $source = $this->_universalFactory->create($this->getSourceModel()); if (!$source) { - throw new EavException( + throw new LocalizedException( __( 'Source model "%1" not found for attribute "%2"', $this->getSourceModel(), diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/Backend/AbstractBackend.php b/app/code/Magento/Eav/Model/Entity/Attribute/Backend/AbstractBackend.php old mode 100644 new mode 100755 index 9950d293cba1937e72b4aa479aa579ef5ea1df16..aa010892c64957ff153888590e20f49987aa82e4 --- a/app/code/Magento/Eav/Model/Entity/Attribute/Backend/AbstractBackend.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/Backend/AbstractBackend.php @@ -5,7 +5,7 @@ */ namespace Magento\Eav\Model\Entity\Attribute\Backend; -use Magento\Eav\Exception as EavException; +use Magento\Framework\Exception\LocalizedException; /** * Entity/Attribute/Model - attribute backend abstract @@ -214,7 +214,7 @@ abstract class AbstractBackend implements \Magento\Eav\Model\Entity\Attribute\Ba * * @param \Magento\Framework\Object $object * @return bool - * @throws EavException + * @throws LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function validate($object) @@ -223,7 +223,7 @@ abstract class AbstractBackend implements \Magento\Eav\Model\Entity\Attribute\Ba $attrCode = $attribute->getAttributeCode(); $value = $object->getData($attrCode); if ($attribute->getIsVisible() && $attribute->getIsRequired() && $attribute->isValueEmpty($value)) { - throw new EavException(__('The value of attribute "%1" must be set', $attrCode)); + throw new LocalizedException(__('The value of attribute "%1" must be set', $attrCode)); } if ($attribute->getIsUnique() @@ -236,7 +236,7 @@ abstract class AbstractBackend implements \Magento\Eav\Model\Entity\Attribute\Ba if ($attribute->getIsUnique()) { if (!$attribute->getEntity()->checkAttributeUniqueValue($attribute, $object)) { $label = $attribute->getFrontend()->getLabel(); - throw new EavException(__('The value of attribute "%1" must be unique', $label)); + throw new LocalizedException(__('The value of attribute "%1" must be unique', $label)); } } diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/Backend/Datetime.php b/app/code/Magento/Eav/Model/Entity/Attribute/Backend/Datetime.php old mode 100644 new mode 100755 index 4145ac0a68cd95767a2ace6d48bda83048f00d73..147f1dcdd0bc845b871daaa2146b468438942d72 --- a/app/code/Magento/Eav/Model/Entity/Attribute/Backend/Datetime.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/Backend/Datetime.php @@ -30,7 +30,7 @@ class Datetime extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBacke * necessary for further process, else date string * * @param \Magento\Framework\Object $object - * @throws \Magento\Eav\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @return $this */ public function beforeSave($object) @@ -41,7 +41,7 @@ class Datetime extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBacke try { $value = $this->formatDate($object->getData($attributeName)); } catch (\Exception $e) { - throw new \Magento\Eav\Exception(__('Invalid date')); + throw new \Magento\Framework\Exception\LocalizedException(__('Invalid date')); } if (is_null($value)) { diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/Set.php b/app/code/Magento/Eav/Model/Entity/Attribute/Set.php old mode 100644 new mode 100755 index c8eb151622d4d235b8460fc548ac202d504b0e4a..446f4fd65a88ba119a7ad37caa67d681aa327ffd --- a/app/code/Magento/Eav/Model/Entity/Attribute/Set.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/Set.php @@ -19,7 +19,7 @@ */ namespace Magento\Eav\Model\Entity\Attribute; -use Magento\Eav\Exception as EavException; +use Magento\Framework\Exception\LocalizedException; use Magento\Eav\Model\Entity\Type; use Magento\Framework\Api\AttributeValueFactory; @@ -255,17 +255,17 @@ class Set extends \Magento\Framework\Model\AbstractExtensibleModel implements * Validate attribute set name * * @return bool - * @throws EavException + * @throws LocalizedException */ public function validate() { $attributeSetName = $this->getAttributeSetName(); if ($attributeSetName == '') { - throw new EavException(__('Attribute set name is empty.')); + throw new LocalizedException(__('Attribute set name is empty.')); } if (!$this->_getResource()->validate($this, $attributeSetName)) { - throw new EavException(__('An attribute set with the "%1" name already exists.', $attributeSetName)); + throw new LocalizedException(__('An attribute set with the "%1" name already exists.', $attributeSetName)); } return true; diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/Source/Config.php b/app/code/Magento/Eav/Model/Entity/Attribute/Source/Config.php old mode 100644 new mode 100755 index 427000b106f5e6b743213ab967e33c1095a56ce9..6417cd0b506d865fcc95f1595f4845439a8500c4 --- a/app/code/Magento/Eav/Model/Entity/Attribute/Source/Config.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/Source/Config.php @@ -30,7 +30,7 @@ class Config extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource /** * Retrieve all options for the source from configuration * - * @throws \Magento\Eav\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @return array */ public function getAllOptions() @@ -39,7 +39,7 @@ class Config extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource $this->_options = []; if (empty($this->_optionsData)) { - throw new \Magento\Eav\Exception(__('No options found.')); + throw new \Magento\Framework\Exception\LocalizedException(__('No options found.')); } foreach ($this->_optionsData as $option) { $this->_options[] = ['value' => $option['value'], 'label' => __($option['label'])]; diff --git a/app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php b/app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php old mode 100644 new mode 100755 index 6cd6cf0e6d018dc745d1d4f66a73581ae593a915..72712e67c4406c2c2485649571e70ee145701992 --- a/app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php +++ b/app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php @@ -6,7 +6,7 @@ namespace Magento\Eav\Model\Entity\Collection; use Magento\Framework\DB\Select; -use Magento\Eav\Exception as EavException; +use Magento\Framework\Exception\LocalizedException; /** * Entity/Attribute/Model - collection abstract @@ -225,7 +225,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db * * @param \Magento\Eav\Model\Entity\AbstractEntity $entity * @return $this - * @throws EavException + * @throws LocalizedException */ public function setEntity($entity) { @@ -234,7 +234,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db } elseif (is_string($entity) || $entity instanceof \Magento\Framework\App\Config\Element) { $this->_entity = $this->_eavEntityFactory->create()->setType($entity); } else { - throw new EavException(__('Invalid entity supplied: %1', print_r($entity, 1))); + throw new LocalizedException(__('Invalid entity supplied: %1', print_r($entity, 1))); } return $this; } @@ -243,12 +243,12 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db * Get collection's entity object * * @return \Magento\Eav\Model\Entity\AbstractEntity - * @throws EavException + * @throws LocalizedException */ public function getEntity() { if (empty($this->_entity)) { - throw new EavException(__('Entity is not initialized')); + throw new LocalizedException(__('Entity is not initialized')); } return $this->_entity; } @@ -284,12 +284,12 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db * * @param \Magento\Framework\Object $object * @return $this - * @throws EavException + * @throws LocalizedException */ public function addItem(\Magento\Framework\Object $object) { if (!$object instanceof $this->_itemObjectClass) { - throw new EavException(__('Attempt to add an invalid object')); + throw new LocalizedException(__('Attempt to add an invalid object')); } return parent::addItem($object); } @@ -449,7 +449,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db * @param array|string|integer|\Magento\Framework\App\Config\Element $attribute * @param bool|string $joinType flag for joining attribute * @return $this - * @throws EavException + * @throws LocalizedException */ public function addAttributeToSelect($attribute, $joinType = false) { @@ -474,7 +474,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db $attrInstance = $this->_eavConfig->getAttribute($this->getEntity()->getType(), $attribute); } if (empty($attrInstance)) { - throw new EavException(__('Invalid attribute requested: %1', (string)$attribute)); + throw new LocalizedException(__('Invalid attribute requested: %1', (string)$attribute)); } $this->_selectAttributes[$attrInstance->getAttributeCode()] = $attrInstance->getId(); } @@ -520,13 +520,13 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db * @param string $expression * @param string $attribute * @return $this - * @throws EavException + * @throws LocalizedException */ public function addExpressionAttributeToSelect($alias, $expression, $attribute) { // validate alias if (isset($this->_joinFields[$alias])) { - throw new EavException(__('Joint field or attribute expression with this alias is already declared')); + throw new LocalizedException(__('Joint field or attribute expression with this alias is already declared')); } if (!is_array($attribute)) { $attribute = [$attribute]; @@ -622,7 +622,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db * @param string $joinType inner|left * @param null $storeId * @return $this - * @throws EavException + * @throws LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ @@ -630,7 +630,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db { // validate alias if (isset($this->_joinAttributes[$alias])) { - throw new EavException(__('Invalid alias, already exists in joint attributes')); + throw new LocalizedException(__('Invalid alias, already exists in joint attributes')); } $bindAttribute = null; @@ -640,7 +640,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db } if (!$bindAttribute || !$bindAttribute->isStatic() && !$bindAttribute->getId()) { - throw new EavException(__('Invalid foreign key')); + throw new LocalizedException(__('Invalid foreign key')); } // try to explode combined entity/attribute if supplied @@ -664,7 +664,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db } } if (!$entity || !$entity->getTypeId()) { - throw new EavException(__('Invalid entity type')); + throw new LocalizedException(__('Invalid entity type')); } // cache entity @@ -677,7 +677,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db $attribute = $entity->getAttribute($attribute); } if (!$attribute) { - throw new EavException(__('Invalid attribute type')); + throw new LocalizedException(__('Invalid attribute type')); } if (empty($filter)) { @@ -712,13 +712,13 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db * @param string|array $cond "{{table}}.language_code='en'" OR array('language_code'=>'en') * @param string $joinType 'left' * @return $this - * @throws EavException + * @throws LocalizedException */ public function joinField($alias, $table, $field, $bind, $cond = null, $joinType = 'inner') { // validate alias if (isset($this->_joinFields[$alias])) { - throw new EavException(__('A joined field with this alias is already declared.')); + throw new LocalizedException(__('A joined field with this alias is already declared.')); } $table = $this->_resource->getTableName($table); @@ -774,7 +774,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db * @param null|array $cond * @param string $joinType * @return $this - * @throws EavException + * @throws LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function joinTable($table, $bind, $fields = null, $cond = null, $joinType = 'inner') @@ -793,11 +793,11 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db // validate fields and aliases if (!$fields) { - throw new EavException(__('Invalid joint fields')); + throw new LocalizedException(__('Invalid joint fields')); } foreach ($fields as $alias => $field) { if (isset($this->_joinFields[$alias])) { - throw new EavException(__('A joint field with this alias (%1) is already declared.', $alias)); + throw new LocalizedException(__('A joint field with this alias (%1) is already declared.', $alias)); } $this->_joinFields[$alias] = ['table' => $tableAlias, 'field' => $field]; } @@ -1100,7 +1100,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db * @param bool $printQuery * @param bool $logQuery * @return $this - * @throws EavException + * @throws LocalizedException * @throws \Exception * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) @@ -1214,14 +1214,14 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db * * @param array $valueInfo * @return $this - * @throws EavException + * @throws LocalizedException */ protected function _setItemAttributeValue($valueInfo) { $entityIdField = $this->getEntity()->getEntityIdField(); $entityId = $valueInfo[$entityIdField]; if (!isset($this->_itemsById[$entityId])) { - throw new EavException(__('Data integrity: No header row found for attribute')); + throw new LocalizedException(__('Data integrity: No header row found for attribute')); } $attributeCode = array_search($valueInfo['attribute_id'], $this->_selectAttributes); if (!$attributeCode) { @@ -1255,7 +1255,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db * * @param string $attributeCode * @return string - * @throws EavException + * @throws LocalizedException */ protected function _getAttributeFieldName($attributeCode) { @@ -1273,7 +1273,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db $attribute = $this->getAttribute($attributeCode); if (!$attribute) { - throw new EavException(__('Invalid attribute name: %1', $attributeCode)); + throw new LocalizedException(__('Invalid attribute name: %1', $attributeCode)); } if ($attribute->isStatic()) { @@ -1295,7 +1295,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db * @param string $attributeCode * @param string $joinType inner|left * @return $this - * @throws EavException + * @throws LocalizedException * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function _addAttributeJoin($attributeCode, $joinType = 'inner') @@ -1333,7 +1333,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db } if (!$attribute) { - throw new EavException(__('Invalid attribute name: %1', $attributeCode)); + throw new LocalizedException(__('Invalid attribute name: %1', $attributeCode)); } if ($attribute->getBackend()->isStatic()) { diff --git a/app/code/Magento/Eav/Model/Entity/Increment/Alphanum.php b/app/code/Magento/Eav/Model/Entity/Increment/Alphanum.php old mode 100644 new mode 100755 index f413b900610a9cf62cfed7c286c4ec11447514b7..06c71132bf982a5e9eb9a7b03c225f8129c6b6f3 --- a/app/code/Magento/Eav/Model/Entity/Increment/Alphanum.php +++ b/app/code/Magento/Eav/Model/Entity/Increment/Alphanum.php @@ -31,7 +31,7 @@ class Alphanum extends \Magento\Eav\Model\Entity\Increment\AbstractIncrement * Get next id * * @return string - * @throws \Magento\Eav\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function getNextId() { @@ -52,7 +52,9 @@ class Alphanum extends \Magento\Eav\Model\Entity\Increment\AbstractIncrement for ($i = $lid; $i >= 0; $i--) { $p = strpos($chars, $lastId[$i]); if (false === $p) { - throw new \Magento\Eav\Exception(__('Invalid character encountered in increment ID: %1', $lastId)); + throw new \Magento\Framework\Exception\LocalizedException( + __('Invalid character encountered in increment ID: %1', $lastId) + ); } if ($bumpNextChar) { $p++; diff --git a/app/code/Magento/Eav/Setup/EavSetup.php b/app/code/Magento/Eav/Setup/EavSetup.php old mode 100644 new mode 100755 index 4e2a177f364bcb103cb8dc312a4f944c01a34385..cccb9d3b0286efc053a86b5fa752cc2a6f189577 --- a/app/code/Magento/Eav/Setup/EavSetup.php +++ b/app/code/Magento/Eav/Setup/EavSetup.php @@ -10,7 +10,7 @@ use Magento\Eav\Model\Entity\Setup\PropertyMapperInterface; use Magento\Eav\Model\Resource\Entity\Attribute\Group\CollectionFactory; use Magento\Framework\App\CacheInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; -use Magento\Eav\Exception as EavException; +use Magento\Framework\Exception\LocalizedException; /** * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) @@ -247,7 +247,7 @@ class EavSetup * * @param int|string $entityTypeId * @return int - * @throws EavException + * @throws LocalizedException */ public function getEntityTypeId($entityTypeId) { @@ -255,7 +255,7 @@ class EavSetup $entityTypeId = $this->getEntityType($entityTypeId, 'entity_type_id'); } if (!is_numeric($entityTypeId)) { - throw new EavException(__('Wrong entity ID')); + throw new LocalizedException(__('Wrong entity ID')); } return $entityTypeId; @@ -381,7 +381,7 @@ class EavSetup * @param int|string $entityTypeId * @param int|string $setId * @return int - * @throws EavException + * @throws LocalizedException */ public function getAttributeSetId($entityTypeId, $setId) { @@ -389,7 +389,7 @@ class EavSetup $setId = $this->getAttributeSet($entityTypeId, $setId, 'attribute_set_id'); } if (!is_numeric($setId)) { - throw new EavException(__('Wrong attribute set ID')); + throw new LocalizedException(__('Wrong attribute set ID')); } return $setId; @@ -598,7 +598,7 @@ class EavSetup * @param int|string $setId * @param int|string $groupId * @return $this - * @throws EavException + * @throws LocalizedException */ public function getAttributeGroupId($entityTypeId, $setId, $groupId) { @@ -611,7 +611,7 @@ class EavSetup } if (!is_numeric($groupId)) { - throw new EavException(__('Wrong attribute group ID')); + throw new LocalizedException(__('Wrong attribute group ID')); } return $groupId; } @@ -713,7 +713,7 @@ class EavSetup * * @param array $data * @return true - * @throws EavException + * @throws LocalizedException */ private function _validateAttributeData($data) { @@ -727,7 +727,7 @@ class EavSetup ['max' => $attributeCodeMaxLength] ) ) { - throw new EavException( + throw new LocalizedException( __('Maximum length of attribute code must be less than %1 symbols', $attributeCodeMaxLength) ); } diff --git a/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/SetTest.php b/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/SetTest.php old mode 100644 new mode 100755 index 23d24c8edd47ffa94a603517f3303bf0e5c7581e..7a81bd55d364ff3423c2e2d4cb884827f4fa4c83 --- a/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/SetTest.php +++ b/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/SetTest.php @@ -51,7 +51,7 @@ class SetTest extends \PHPUnit_Framework_TestCase { $this->_model->getResource()->expects($this->any())->method('validate')->will($this->returnValue(false)); - $this->setExpectedException('Magento\Eav\Exception', $exceptionMessage); + $this->setExpectedException('Magento\Framework\Exception\LocalizedException', $exceptionMessage); $this->_model->setAttributeSetName($attributeSetName); $this->_model->validate(); } diff --git a/app/code/Magento/Eav/Test/Unit/Model/Entity/Increment/AlphanumTest.php b/app/code/Magento/Eav/Test/Unit/Model/Entity/Increment/AlphanumTest.php old mode 100644 new mode 100755 index bbf9f3b2535633f1ff7fd5a6756ef54ce5cfc5fc..23bd155a23f02b029c93edfcc26580d478f51ac1 --- a/app/code/Magento/Eav/Test/Unit/Model/Entity/Increment/AlphanumTest.php +++ b/app/code/Magento/Eav/Test/Unit/Model/Entity/Increment/AlphanumTest.php @@ -54,7 +54,7 @@ class AlphanumTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Eav\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Invalid character encountered in increment ID: ---wrong-id--- */ public function testGetNextIdThrowsExceptionIfIdContainsNotAllowedCharacters() diff --git a/app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php b/app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php index 21c1fc1cf75899ce1fdbb49c15e31c9865d57c32..b89948409ebd294999cae7f1d7224bf3a19972b7 100644 --- a/app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php +++ b/app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php @@ -5,6 +5,8 @@ */ namespace Magento\OfflineShipping\Model\Carrier; +use Magento\Framework\Exception\LocalizedException; + class Tablerate extends \Magento\Shipping\Model\Carrier\AbstractCarrier implements \Magento\Shipping\Model\Carrier\CarrierInterface { @@ -197,7 +199,7 @@ class Tablerate extends \Magento\Shipping\Model\Carrier\AbstractCarrier implemen * @param string $type * @param string $code * @return array - * @throws \Magento\Shipping\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function getCode($type, $code = '') { @@ -215,7 +217,7 @@ class Tablerate extends \Magento\Shipping\Model\Carrier\AbstractCarrier implemen ]; if (!isset($codes[$type])) { - throw new \Magento\Shipping\Exception(__('Please correct Table Rate code type: %1.', $type)); + throw new LocalizedException(__('Please correct Table Rate code type: %1.', $type)); } if ('' === $code) { @@ -223,7 +225,7 @@ class Tablerate extends \Magento\Shipping\Model\Carrier\AbstractCarrier implemen } if (!isset($codes[$type][$code])) { - throw new \Magento\Shipping\Exception(__('Please correct Table Rate code for type %1: %2.', $type, $code)); + throw new LocalizedException(__('Please correct Table Rate code for type %1: %2.', $type, $code)); } return $codes[$type][$code]; diff --git a/app/code/Magento/Reports/Model/Resource/Quote/Collection.php b/app/code/Magento/Reports/Model/Resource/Quote/Collection.php index cb2a9333fe01e3f67cc168067fc0fdc0a1bcc773..ea190558cac88646b628f4affaa5583f23f92d14 100644 --- a/app/code/Magento/Reports/Model/Resource/Quote/Collection.php +++ b/app/code/Magento/Reports/Model/Resource/Quote/Collection.php @@ -323,7 +323,7 @@ class Collection extends \Magento\Quote\Model\Resource\Quote\Collection * * @param array $productIds * @return array - * @throws \Magento\Eav\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function getProductData(array $productIds) { diff --git a/app/code/Magento/Shipping/Exception.php b/app/code/Magento/Shipping/Exception.php deleted file mode 100755 index b140b961cf6d2bdf50fbc78e600517b55b8d3211..0000000000000000000000000000000000000000 --- a/app/code/Magento/Shipping/Exception.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Shipping; - -class Exception extends \Magento\Framework\Exception\LocalizedException -{ -} diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFileTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFileTest.php index eb8ec06003ac4f24253b991563579c4818fe3335..96833ea6131be828d3511fcd39db17b0409c0d02 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFileTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFileTest.php @@ -66,10 +66,10 @@ class ValidatorFileTest extends \PHPUnit_Framework_TestCase /** * @return void */ - public function testLargeSizeException() + public function testLargeSizeFile() { $this->setExpectedException( - '\Magento\Framework\Exception\File\LargeSizeException', + '\Magento\Framework\Exception\LocalizedException', sprintf('The file you uploaded is larger than %s Megabytes allowed by server', $this->maxFileSizeInMb) ); $this->prepareEnv(); @@ -108,7 +108,7 @@ class ValidatorFileTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Exception\File\ValidatorException + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Please specify the product's required option(s). * @return void */ @@ -131,7 +131,7 @@ class ValidatorFileTest extends \PHPUnit_Framework_TestCase public function testInvalidateFile() { $this->setExpectedException( - '\Magento\Framework\Exception\File\ValidatorException', + '\Magento\Framework\Exception\LocalizedException', "The file 'test.jpg' for 'MediaOption' has an invalid extension.\n" . "The file 'test.jpg' for 'MediaOption' has an invalid extension.\n" . "Maximum allowed image size for 'MediaOption' is 2000x2000 px.\n" diff --git a/dev/tests/integration/testsuite/Magento/Framework/View/Fixture/Block/BrokenAction.php b/dev/tests/integration/testsuite/Magento/Framework/View/Fixture/Block/BrokenAction.php new file mode 100644 index 0000000000000000000000000000000000000000..0732a8e7916e7b6e9ca46a6a221a5dc56ea016b6 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Framework/View/Fixture/Block/BrokenAction.php @@ -0,0 +1,44 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View\Fixture\Block; + +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Phrase; +use Magento\Framework\View\LayoutInterface; + +class BrokenAction extends \Magento\Framework\View\Element\AbstractBlock +{ + /** + * @param LayoutInterface $layout + * @return $this + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function setLayout(LayoutInterface $layout) + { + return $this; + } + + /** + * @param string $action + * @throws LocalizedException + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function initAction($action) + { + throw new LocalizedException(new Phrase('Init action problem.')); + } + + /** + * Produce and return block's html output + * + * @return string + */ + public function toHtml() + { + return '<p>Rendered with action problem.</p>'; + } +} diff --git a/dev/tests/integration/testsuite/Magento/Framework/View/Fixture/Block/BrokenConstructor.php b/dev/tests/integration/testsuite/Magento/Framework/View/Fixture/Block/BrokenConstructor.php new file mode 100644 index 0000000000000000000000000000000000000000..b421b1f76d693fceff48282d953b097d552c233e --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Framework/View/Fixture/Block/BrokenConstructor.php @@ -0,0 +1,30 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View\Fixture\Block; + +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Phrase; + +class BrokenConstructor extends \Magento\Framework\View\Element\AbstractBlock +{ + /** + * @throws LocalizedException + */ + public function __construct() + { + throw new LocalizedException(new Phrase('Construction problem.')); + } + + /** + * Produce and return block's html output + * + * @return string + */ + public function toHtml() + { + return '<p>Rendered with construction problem.</p>'; + } +} diff --git a/dev/tests/integration/testsuite/Magento/Framework/View/Fixture/Block/BrokenLayout.php b/dev/tests/integration/testsuite/Magento/Framework/View/Fixture/Block/BrokenLayout.php new file mode 100644 index 0000000000000000000000000000000000000000..4673250a1cb08e29e0935e4f9dbf02c173a2e7c1 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Framework/View/Fixture/Block/BrokenLayout.php @@ -0,0 +1,34 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View\Fixture\Block; + +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Phrase; +use Magento\Framework\View\LayoutInterface; + +class BrokenLayout extends \Magento\Framework\View\Element\AbstractBlock +{ + /** + * @param LayoutInterface $layout + * @throws LocalizedException + * @return void + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function setLayout(LayoutInterface $layout) + { + throw new LocalizedException(new Phrase('Prepare layout problem.')); + } + + /** + * Produce and return block's html output + * + * @return string + */ + public function toHtml() + { + return '<p>Rendered with layout problem.</p>'; + } +} diff --git a/dev/tests/integration/testsuite/Magento/Framework/View/LayoutTestWithExceptions.php b/dev/tests/integration/testsuite/Magento/Framework/View/LayoutTestWithExceptions.php new file mode 100644 index 0000000000000000000000000000000000000000..64d383ed99a249cd738ff1be87433ea241458f3e --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Framework/View/LayoutTestWithExceptions.php @@ -0,0 +1,57 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View; + +use \Magento\Framework\App\State; + +class LayoutTestWithExceptions extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\Framework\View\Layout + */ + protected $layout; + + public function setUp() + { + $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + $layoutFactory = $objectManager->get('Magento\Framework\View\LayoutFactory'); + $this->layout = $layoutFactory->create(); + $layoutElement = new \Magento\Framework\View\Layout\Element( + __DIR__ . '/_files/layout_with_exceptions/layout.xml', + 0, + true + ); + + $this->layout->setXml($layoutElement); + $objectManager->get('Magento\Framework\App\Cache\Type\Layout')->clean(); + } + + /** + * @expectedException \Magento\Framework\Exception\LocalizedException + * @expectedExceptionMessage Construction problem. + */ + public function testProcessWithExceptionsDeveloperMode() + { + $this->layout->generateElements(); + } + + /** + * @magentoAppIsolation enabled + */ + public function testProcessWithExceptions() + { + \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\Framework\App\State') + ->setMode(State::MODE_DEFAULT); + + $this->layout->generateElements(); + + $this->layout->addOutputElement('block.with.broken.constructor'); + $this->layout->addOutputElement('block.with.broken.layout'); + $this->layout->addOutputElement('block.with.broken.action'); + + $this->assertEmpty($this->layout->getOutput()); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Framework/View/Utility/Layout.php b/dev/tests/integration/testsuite/Magento/Framework/View/Utility/Layout.php index 2f43263c6989c9428586006bdd7c2a6dfa43f2ce..df662db1bd7af9e9b39ccca6ca0b0a963012bc26 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/View/Utility/Layout.php +++ b/dev/tests/integration/testsuite/Magento/Framework/View/Utility/Layout.php @@ -104,6 +104,8 @@ class Layout 'cache' => $objectManager->get('Magento\Framework\App\Cache\Type\Layout'), 'readerContextFactory' => $objectManager->get('Magento\Framework\View\Layout\Reader\ContextFactory'), 'generatorContextFactory' => $objectManager->get('Magento\Framework\View\Layout\Generator\ContextFactory'), + 'appState' => $objectManager->get('Magento\Framework\App\State'), + 'logger' => $objectManager->get('Psr\Log\LoggerInterface'), ]; } } diff --git a/dev/tests/integration/testsuite/Magento/Framework/View/_files/layout_with_exceptions/layout.xml b/dev/tests/integration/testsuite/Magento/Framework/View/_files/layout_with_exceptions/layout.xml new file mode 100644 index 0000000000000000000000000000000000000000..a52c0a6645cf38171cec6ded52f867f5ce5e5d37 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Framework/View/_files/layout_with_exceptions/layout.xml @@ -0,0 +1,20 @@ +<?xml version="1.0"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd"> + <body> + <referenceContainer name="root"> + <block class="Magento\Framework\View\Fixture\Block\BrokenConstructor" name="block.with.broken.constructor"/> + <block class="Magento\Framework\View\Fixture\Block\BrokenLayout" name="block.with.broken.layout"/> + <block class="Magento\Framework\View\Fixture\Block\BrokenAction" name="block.with.broken.action"> + <action method="initAction"> + <argument name="action" xsi:type="string">action</argument> + </action> + </block> + </referenceContainer> + </body> +</page> diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/ExceptionHierarchyTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/ExceptionHierarchyTest.php new file mode 100644 index 0000000000000000000000000000000000000000..b7fb0b8ae7a94fac791f68ba00a147f6bf138776 --- /dev/null +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/ExceptionHierarchyTest.php @@ -0,0 +1,73 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Test\Integrity; + +use Magento\Framework\App\Utility\Files as UtilityFiles; + +/** + * Checks that all Exceptions inherit LocalizedException + */ +class ExceptionHierarchyTest extends \PHPUnit_Framework_TestCase +{ + /** + * @param \ReflectionClass $reflectionException + * @dataProvider isInheritedLocalizedExceptionDataProvider + */ + public function testIsInheritedLocalizedException(\ReflectionClass $reflectionException) + { + $this->assertTrue( + $reflectionException->isSubclassOf('Magento\Framework\Exception\LocalizedException'), + "{$reflectionException->name} is not inherited LocalizedException" + ); + } + + /** + * @return array + */ + public function isInheritedLocalizedExceptionDataProvider() + { + $files = UtilityFiles::init()->getClassFiles(true, false, false, true, false); + $blacklistExceptions = $this->getBlacklistExceptions(); + + $data = []; + foreach ($files as $file) { + $className = $this->convertPathToClassName($file); + try { + $reflectionClass = new \ReflectionClass($className); + if ($reflectionClass->isSubclassOf('Exception') && !in_array($className, $blacklistExceptions)) { + $data[$className] = [$reflectionClass]; + } + } catch (\Exception $e) { + $this->fail("File name and class name '{$className}' is not appropriate"); + } + } + return $data; + } + + /** + * @param string $filePath + * @return string + */ + protected function convertPathToClassName($filePath) + { + $className = str_replace('.php', "", substr($filePath, strpos($filePath, '/Magento'))); + $className = implode("\\", explode("/", $className)); + return $className; + } + + /** + * @return array + */ + protected function getBlacklistExceptions() + { + $blacklistFiles = str_replace('\\', '/', realpath(__DIR__)) . '/_files/blacklist/exception_hierarchy*.txt'; + $exceptions = []; + foreach (glob($blacklistFiles) as $fileName) { + $exceptions = array_merge($exceptions, file($fileName, FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES)); + } + return $exceptions; + } +} diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/_files/blacklist/exception_hierarchy.txt b/dev/tests/static/testsuite/Magento/Test/Integrity/_files/blacklist/exception_hierarchy.txt new file mode 100644 index 0000000000000000000000000000000000000000..068e1ea553cbddd2adc20851f582c3188be8fda6 --- /dev/null +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/_files/blacklist/exception_hierarchy.txt @@ -0,0 +1,4 @@ +\Magento\Framework\Exception\LocalizedException +\Magento\Framework\View\Asset\File\NotFoundException +\Magento\Framework\Config\Dom\ValidationException +\Magento\Framework\Gdata\Gshopping\HttpException diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php old mode 100644 new mode 100755 index ea38ddcc122e4c6ee620adfe14fc76ebb806a43c..57cd1b6a4c81734430ee2dca24c68aa4ff61b623 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php @@ -3118,6 +3118,19 @@ return [ ['Magento\LocaleFactory'], ['Magento\Framework\LocaleFactory'], ['Magento\Core\Helper\Data', 'Magento\Framework\Json\Helper\Data'], + ['Magento\Framework\App\DeploymentConfig\BackendConfig'], + ['Magento\Framework\App\DeploymentConfig\DbConfig'], + ['Magento\Framework\App\DeploymentConfig\InstallConfig'], + ['Magento\Framework\App\DeploymentConfig\ResourceConfig'], + ['Magento\Framework\App\DeploymentConfig\SessionConfig'], + ['Magento\Framework\App\DeploymentConfig\CacheConfig'], + ['Magento\Setup\Model\DeploymentConfigMapper'], + ['Magento\Framework\App\DeploymentConfig\EncryptConfig'], + ['Magento\Framework\Filesystem\Io\IoException'], + ['Magento\Framework\DB\DBException'], + ['Magento\Framework\DB\Tree\TreeException'], + ['Magento\Framework\DB\Tree\Node\NodeException'], + ['Magento\Framework\DB\Tree\NodeSet\NodeSetException'], ['Magento\Backup\Exception'], ['Magento\Catalog\Exception'], ['Magento\Reports\Exception'], @@ -3138,18 +3151,14 @@ return [ ['Magento\CatalogRule\CatalogRuleException'], ['Magento\Payment\Exception'], ['Magento\UrlRewrite\Model\Storage\DuplicateEntryException'], - ['Magento\Framework\App\DeploymentConfig\BackendConfig'], - ['Magento\Framework\App\DeploymentConfig\DbConfig'], - ['Magento\Framework\App\DeploymentConfig\InstallConfig'], - ['Magento\Framework\App\DeploymentConfig\ResourceConfig'], - ['Magento\Framework\App\DeploymentConfig\SessionConfig'], - ['Magento\Framework\App\DeploymentConfig\CacheConfig'], - ['Magento\Setup\Model\DeploymentConfigMapper'], - ['Magento\Framework\App\DeploymentConfig\EncryptConfig'], ['Magento\Setup\Mvc\Console\RouteListener'], ['Magento\Setup\Mvc\Console\RouteMatcher'], ['Magento\Setup\Mvc\Console\VerboseValidator'], ['Magento\Setup\Controller\ConsoleController'], ['Magento\Setup\Model\UserConfigurationDataMapper', 'Magento\Setup\Model\StoreConfigurationDataMapper'], ['Magento\Framework\App\State\Cleanup', 'Magento\Framework\App\State\CleanupFiles'], + ['Magento\Eav\Exception'], + ['Magento\Framework\Exception\File\ValidatorException'], + ['Magento\Framework\Filesystem\FilesystemException', 'Magento\Framework\Exception\FileSystemException'], + ['Magento\Shipping\Exception'], ]; diff --git a/lib/internal/Magento/Framework/Archive/Helper/File.php b/lib/internal/Magento/Framework/Archive/Helper/File.php old mode 100644 new mode 100755 index 549c3b8849fe73ba906f1fe643e8f45d2fae37bd..eab51af7b2c87cbb6f8decc1e814af08645af7f6 --- a/lib/internal/Magento/Framework/Archive/Helper/File.php +++ b/lib/internal/Magento/Framework/Archive/Helper/File.php @@ -11,7 +11,7 @@ */ namespace Magento\Framework\Archive\Helper; -use Magento\Framework\Exception\LocalizedException as MagentoException; +use Magento\Framework\Exception\LocalizedException; class File { @@ -87,7 +87,7 @@ class File * @param string $mode * @param int $chmod * @return void - * @throws MagentoException + * @throws LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function open($mode = 'w+', $chmod = 0666) @@ -96,13 +96,13 @@ class File if ($this->_isInWriteMode) { if (!is_writable($this->_fileLocation)) { - throw new MagentoException( + throw new LocalizedException( new \Magento\Framework\Phrase('Permission denied to write to %1', [$this->_fileLocation]) ); } if (is_file($this->_filePath) && !is_writable($this->_filePath)) { - throw new MagentoException( + throw new LocalizedException( new \Magento\Framework\Phrase( "Can't open file %1 for writing. Permission denied.", [$this->_fileName] @@ -113,13 +113,13 @@ class File if ($this->_isReadableMode($mode) && (!is_file($this->_filePath) || !is_readable($this->_filePath))) { if (!is_file($this->_filePath)) { - throw new MagentoException( + throw new LocalizedException( new \Magento\Framework\Phrase('File %1 does not exist', [$this->_filePath]) ); } if (!is_readable($this->_filePath)) { - throw new MagentoException( + throw new LocalizedException( new \Magento\Framework\Phrase('Permission denied to read file %1', [$this->_filePath]) ); } @@ -191,14 +191,14 @@ class File * * @param string $mode * @return void - * @throws MagentoException + * @throws LocalizedException */ protected function _open($mode) { $this->_fileHandler = @fopen($this->_filePath, $mode); if (false === $this->_fileHandler) { - throw new MagentoException(new \Magento\Framework\Phrase('Failed to open file %1', [$this->_filePath])); + throw new LocalizedException(new \Magento\Framework\Phrase('Failed to open file %1', [$this->_filePath])); } } @@ -207,14 +207,14 @@ class File * * @param string $data * @return void - * @throws MagentoException + * @throws LocalizedException */ protected function _write($data) { $result = @fwrite($this->_fileHandler, $data); if (false === $result) { - throw new MagentoException(new \Magento\Framework\Phrase('Failed to write data to %1', [$this->_filePath])); + throw new LocalizedException(new \Magento\Framework\Phrase('Failed to write data to %1', [$this->_filePath])); } } @@ -223,14 +223,14 @@ class File * * @param int $length * @return string - * @throws MagentoException + * @throws LocalizedException */ protected function _read($length) { $result = fread($this->_fileHandler, $length); if (false === $result) { - throw new MagentoException( + throw new LocalizedException( new \Magento\Framework\Phrase('Failed to read data from %1', [$this->_filePath]) ); } @@ -284,12 +284,12 @@ class File * Check whether file is opened * * @return void - * @throws MagentoException + * @throws LocalizedException */ protected function _checkFileOpened() { if (!$this->_fileHandler) { - throw new MagentoException(new \Magento\Framework\Phrase('File not opened')); + throw new LocalizedException(new \Magento\Framework\Phrase('File not opened')); } } } diff --git a/lib/internal/Magento/Framework/DB/Adapter/AdapterInterface.php b/lib/internal/Magento/Framework/DB/Adapter/AdapterInterface.php index ac5f33263ec03c3ac9452229a31c8d0d71690272..938cfe6a31ec26f0193059607e1a20ea68bba299 100644 --- a/lib/internal/Magento/Framework/DB/Adapter/AdapterInterface.php +++ b/lib/internal/Magento/Framework/DB/Adapter/AdapterInterface.php @@ -985,7 +985,7 @@ interface AdapterInterface * @param \Magento\Framework\DB\Select $select * @param int $stepCount * @return \Magento\Framework\DB\Select[] - * @throws \Magento\Framework\DB\DBException + * @throws \Magento\Framework\Exception\LocalizedException */ public function selectsByRange($rangeField, \Magento\Framework\DB\Select $select, $stepCount = 100); diff --git a/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php b/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php index f3bf8e12d893c11bd321989e4786d1d65893976d..b4b07cd12e81494298dd43dea4a4156c8a684670 100644 --- a/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php +++ b/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php @@ -18,6 +18,7 @@ use Magento\Framework\DB\LoggerInterface; use Magento\Framework\DB\Profiler; use Magento\Framework\DB\Select; use Magento\Framework\DB\Statement\Parameter; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Stdlib\DateTime; use Magento\Framework\Stdlib\String; @@ -3322,13 +3323,13 @@ class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface * @param \Magento\Framework\DB\Select $select * @param int $stepCount * @return \Magento\Framework\DB\Select[] - * @throws \Magento\Framework\DB\DBException + * @throws LocalizedException */ public function selectsByRange($rangeField, \Magento\Framework\DB\Select $select, $stepCount = 100) { $fromSelect = $select->getPart(\Magento\Framework\DB\Select::FROM); if (empty($fromSelect)) { - throw new \Magento\Framework\DB\DBException( + throw new LocalizedException( new \Magento\Framework\Phrase('Select object must have correct "FROM" part') ); } @@ -3380,7 +3381,7 @@ class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface * @param Select $select * @param string|array $table * @return string - * @throws \Magento\Framework\DB\DBException + * @throws LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ @@ -3438,7 +3439,7 @@ class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface } if (!$columns) { - throw new \Magento\Framework\DB\DBException( + throw new LocalizedException( new \Magento\Framework\Phrase('The columns for UPDATE statement are not defined') ); } diff --git a/lib/internal/Magento/Framework/DB/DBException.php b/lib/internal/Magento/Framework/DB/DBException.php deleted file mode 100644 index 6af4e98427bbf852c39c0b4494e4a5bba23339b1..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/DB/DBException.php +++ /dev/null @@ -1,15 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\DB; - -/** - * TODO - * - * @author Magento Core Team <core@magentocommerce.com> - */ -class DBException extends \Magento\Framework\Exception\LocalizedException -{ -} diff --git a/lib/internal/Magento/Framework/DB/Test/Unit/Tree/NodeTest.php b/lib/internal/Magento/Framework/DB/Test/Unit/Tree/NodeTest.php index 92e206b069b491c3717db2b9484b9e25c4cff263..b89a7d646d07823c7da54caaca77bfc7d4f300b3 100644 --- a/lib/internal/Magento/Framework/DB/Test/Unit/Tree/NodeTest.php +++ b/lib/internal/Magento/Framework/DB/Test/Unit/Tree/NodeTest.php @@ -93,7 +93,7 @@ class NodeTest extends \PHPUnit_Framework_TestCase 'node_data' => null, 'keys' => null, ], - '\Magento\Framework\DB\Tree\Node\NodeException', + '\Magento\Framework\Exception\LocalizedException', 'Empty array of node information', ], [ @@ -101,7 +101,7 @@ class NodeTest extends \PHPUnit_Framework_TestCase 'node_data' => null, 'keys' => true, ], - '\Magento\Framework\DB\Tree\Node\NodeException', + '\Magento\Framework\Exception\LocalizedException', 'Empty array of node information' ], [ @@ -109,7 +109,7 @@ class NodeTest extends \PHPUnit_Framework_TestCase 'node_data' => true, 'keys' => null, ], - '\Magento\Framework\DB\Tree\Node\NodeException', + '\Magento\Framework\Exception\LocalizedException', 'Empty keys array' ] ]; diff --git a/lib/internal/Magento/Framework/DB/Tree.php b/lib/internal/Magento/Framework/DB/Tree.php index e2449c2bc8498fcd4758cc194862d3f78ee9742f..f06e9d291a89490355f627251548d701b66e36d9 100644 --- a/lib/internal/Magento/Framework/DB/Tree.php +++ b/lib/internal/Magento/Framework/DB/Tree.php @@ -10,13 +10,11 @@ namespace Magento\Framework\DB; \Zend_Loader::loadClass('\Magento\Framework\DB\Tree\NodeSet'); use Magento\Framework\DB\Tree\Node; use Magento\Framework\DB\Tree\NodeSet; -use Magento\Framework\DB\Tree\TreeException; +use Magento\Framework\Exception\LocalizedException; /** * Magento Library - */ -require_once 'Tree/TreeException.php'; -/** + * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class Tree @@ -79,7 +77,7 @@ class Tree /** * @param array $config - * @throws TreeException + * @throws LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ @@ -97,7 +95,7 @@ class Tree // make sure it's a \Zend_Db_Adapter if (!$connection instanceof \Zend_Db_Adapter_Abstract) { - throw new TreeException( + throw new LocalizedException( new \Magento\Framework\Phrase('db object does not implement \Zend_Db_Adapter_Abstract') ); } @@ -109,7 +107,7 @@ class Tree $conn->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true); } } else { - throw new TreeException(new \Magento\Framework\Phrase('db object is not set in config')); + throw new LocalizedException(new \Magento\Framework\Phrase('db object is not set in config')); } if (!empty($config['table'])) { diff --git a/lib/internal/Magento/Framework/DB/Tree/Node.php b/lib/internal/Magento/Framework/DB/Tree/Node.php index e9ea215876818ab635f24972875564cc4dd82ef7..f3e353ba81a4dba8180416e1cd4f711d78edbc99 100644 --- a/lib/internal/Magento/Framework/DB/Tree/Node.php +++ b/lib/internal/Magento/Framework/DB/Tree/Node.php @@ -5,7 +5,7 @@ */ namespace Magento\Framework\DB\Tree; -use Magento\Framework\DB\Tree\Node\NodeException; +use Magento\Framework\Exception\LocalizedException; /** * @SuppressWarnings(PHPMD.UnusedPrivateField) @@ -60,15 +60,15 @@ class Node /** * @param array $nodeData * @param array $keys - * @throws NodeException + * @throws LocalizedException */ public function __construct($nodeData, $keys) { if (empty($nodeData)) { - throw new NodeException(new \Magento\Framework\Phrase('Empty array of node information')); + throw new LocalizedException(new \Magento\Framework\Phrase('Empty array of node information')); } if (empty($keys)) { - throw new NodeException(new \Magento\Framework\Phrase('Empty keys array')); + throw new LocalizedException(new \Magento\Framework\Phrase('Empty keys array')); } $this->id = $nodeData[$keys['id']]; diff --git a/lib/internal/Magento/Framework/DB/Tree/Node/NodeException.php b/lib/internal/Magento/Framework/DB/Tree/Node/NodeException.php deleted file mode 100644 index 6f3fa5edae5e2a478cf2c750c6a9950a169866fb..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/DB/Tree/Node/NodeException.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\DB\Tree\Node; - -class NodeException extends \Magento\Framework\DB\Tree\TreeException -{ -} diff --git a/lib/internal/Magento/Framework/DB/Tree/NodeSet/NodeSetException.php b/lib/internal/Magento/Framework/DB/Tree/NodeSet/NodeSetException.php deleted file mode 100644 index 62c7b9554b2665afc84dffc67bbcd1552e1acd56..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/DB/Tree/NodeSet/NodeSetException.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\DB\Tree\NodeSet; - -class NodeSetException extends \Magento\Framework\DB\Tree\TreeException -{ -} diff --git a/lib/internal/Magento/Framework/DB/Tree/TreeException.php b/lib/internal/Magento/Framework/DB/Tree/TreeException.php deleted file mode 100644 index e462b47654bc44077946460d55dc8c9b350a9e72..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/DB/Tree/TreeException.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\DB\Tree; - -class TreeException extends \Magento\Framework\DB\DBException -{ -} diff --git a/lib/internal/Magento/Framework/Exception/File/LargeSizeException.php b/lib/internal/Magento/Framework/Exception/File/LargeSizeException.php deleted file mode 100644 index 73a22a65116e664f73531b2f34ed1612e5e803e3..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Exception/File/LargeSizeException.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\Exception\File; - -use Magento\Framework\Exception\LocalizedException; - -class LargeSizeException extends LocalizedException -{ -} diff --git a/lib/internal/Magento/Framework/Exception/File/ValidatorException.php b/lib/internal/Magento/Framework/Exception/File/ValidatorException.php deleted file mode 100644 index a8f78f8aeb2668009a79ccdd4a0ced4ed55c5286..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Exception/File/ValidatorException.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\Exception\File; - -use Magento\Framework\Exception\LocalizedException; - -class ValidatorException extends LocalizedException -{ -} diff --git a/lib/internal/Magento/Framework/Filesystem/Io/Ftp.php b/lib/internal/Magento/Framework/Filesystem/Io/Ftp.php index ed850baec96a9bb36bea2aaaa294ec3073394519..1f897eee69f0194cdc69fe580f9ee81a402e94d4 100644 --- a/lib/internal/Magento/Framework/Filesystem/Io/Ftp.php +++ b/lib/internal/Magento/Framework/Filesystem/Io/Ftp.php @@ -5,6 +5,9 @@ */ namespace Magento\Framework\Filesystem\Io; +use Magento\Framework\Phrase; +use Magento\Framework\Exception\LocalizedException; + /** * FTP client */ @@ -66,7 +69,7 @@ class Ftp extends AbstractIo * * @param array $args * @return true - * @throws IoException + * @throws LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ @@ -74,7 +77,7 @@ class Ftp extends AbstractIo { if (empty($args['host'])) { $this->_error = self::ERROR_EMPTY_HOST; - throw new IoException(new \Magento\Framework\Phrase('Empty host specified')); + throw new LocalizedException(new Phrase('Empty host specified')); } if (empty($args['port'])) { @@ -107,22 +110,20 @@ class Ftp extends AbstractIo } if (!$this->_conn) { $this->_error = self::ERROR_INVALID_CONNECTION; - throw new IoException( - new \Magento\Framework\Phrase('Could not establish FTP connection, invalid host or port') - ); + throw new LocalizedException(new Phrase('Could not establish FTP connection, invalid host or port')); } if (!@ftp_login($this->_conn, $this->_config['user'], $this->_config['password'])) { $this->_error = self::ERROR_INVALID_LOGIN; $this->close(); - throw new IoException(new \Magento\Framework\Phrase('Invalid user name or password')); + throw new LocalizedException(new Phrase('Invalid user name or password')); } if (!empty($this->_config['path'])) { if (!@ftp_chdir($this->_conn, $this->_config['path'])) { $this->_error = self::ERROR_INVALID_PATH; $this->close(); - throw new IoException(new \Magento\Framework\Phrase('Invalid path')); + throw new LocalizedException(new Phrase('Invalid path')); } } @@ -130,7 +131,7 @@ class Ftp extends AbstractIo if (!@ftp_pasv($this->_conn, true)) { $this->_error = self::ERROR_INVALID_MODE; $this->close(); - throw new IoException(new \Magento\Framework\Phrase('Invalid file transfer mode')); + throw new LocalizedException(new Phrase('Invalid file transfer mode')); } } diff --git a/lib/internal/Magento/Framework/Filesystem/Io/IoException.php b/lib/internal/Magento/Framework/Filesystem/Io/IoException.php deleted file mode 100644 index 3d94334dcae56b811afb12cc45fbe2deec95296f..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Filesystem/Io/IoException.php +++ /dev/null @@ -1,14 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -namespace Magento\Framework\Filesystem\Io; - -/** - * Io exception - */ -class IoException extends \Magento\Framework\Exception\LocalizedException -{ -} diff --git a/lib/internal/Magento/Framework/View/Element/ExceptionHandlerBlock.php b/lib/internal/Magento/Framework/View/Element/ExceptionHandlerBlock.php new file mode 100644 index 0000000000000000000000000000000000000000..f848775a34b79ca17c1cc93d69071ab80a664a07 --- /dev/null +++ b/lib/internal/Magento/Framework/View/Element/ExceptionHandlerBlock.php @@ -0,0 +1,62 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View\Element; + +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Phrase; + +/** + * Class of a Exception Handler Block + * + * Block for default and maintenance mode. During layout loading process corrupted block (that throws exception) + * will be replaced with a "dummy" block. As result, page will be loaded without broken block. + * + * When calls from parent to child block occurred and the error appeared in the child block, + * all blocks chain would be removed. + */ +class ExceptionHandlerBlock implements BlockInterface +{ + /** + * @var string + */ + protected $blockName; + + /** + * @param string $blockName + */ + public function __construct($blockName = '') + { + $this->blockName = $blockName; + } + + /** + * Throws an exception when parent block calls corrupted child block method + * + * @param string $method + * @param array $args + * @return void + * @throws LocalizedException + */ + public function __call($method, $args) + { + throw new LocalizedException( + new Phrase('Block %1 throws exception and cannot be rendered.', [$this->blockName]) + ); + } + + /** + * Declared in BlockInterface and also throws an exception + * + * @throws LocalizedException + * @return void + */ + public function toHtml() + { + throw new LocalizedException( + new Phrase('Block %1 throws exception and cannot be rendered.', [$this->blockName]) + ); + } +} diff --git a/lib/internal/Magento/Framework/View/Element/ExceptionHandlerBlockFactory.php b/lib/internal/Magento/Framework/View/Element/ExceptionHandlerBlockFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..522324c0ea22df2f5ffacfb7496d07127819d4cb --- /dev/null +++ b/lib/internal/Magento/Framework/View/Element/ExceptionHandlerBlockFactory.php @@ -0,0 +1,48 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View\Element; + +/** + * Class ExceptionHandlerBlockFactory + * @package Magento\Framework\View\Element + */ +class ExceptionHandlerBlockFactory +{ + const DEFAULT_INSTANCE_NAME = 'Magento\Framework\View\Element\ExceptionHandlerBlock'; + + /** + * @var \Magento\Framework\ObjectManagerInterface + */ + protected $objectManager; + + /** + * @var string + */ + protected $instanceName; + + /** + * @param \Magento\Framework\ObjectManagerInterface $objectManager + * @param string $instanceName + */ + public function __construct( + \Magento\Framework\ObjectManagerInterface $objectManager, + $instanceName = self::DEFAULT_INSTANCE_NAME + ) { + $this->objectManager = $objectManager; + $this->instanceName = $instanceName; + } + + /** + * Create exception handling block + * + * @param array $data + * @return \Magento\Framework\View\Element\BlockInterface + */ + public function create(array $data = []) + { + return $this->objectManager->create($this->instanceName, $data); + } +} diff --git a/lib/internal/Magento/Framework/View/Layout.php b/lib/internal/Magento/Framework/View/Layout.php index c2184cfff688e3f04e0863954a831e68b82b9ce2..6c857548d18ed329d6767bbc6f35684f8205e059 100644 --- a/lib/internal/Magento/Framework/View/Layout.php +++ b/lib/internal/Magento/Framework/View/Layout.php @@ -148,9 +148,9 @@ class Layout extends \Magento\Framework\Simplexml\Config implements \Magento\Fra /** * @param Layout\ProcessorFactory $processorFactory - * @param \Magento\Framework\Event\ManagerInterface $eventManager + * @param ManagerInterface $eventManager * @param Layout\Data\Structure $structure - * @param \Magento\Framework\Message\ManagerInterface $messageManager + * @param MessageManagerInterface $messageManager * @param Design\Theme\ResolverInterface $themeResolver * @param Layout\ReaderPool $readerPool * @param Layout\GeneratorPool $generatorPool @@ -458,14 +458,7 @@ class Layout extends \Magento\Framework\Simplexml\Config implements \Magento\Fra { $this->build(); if (!isset($this->_renderElementCache[$name]) || !$useCache) { - if ($this->isUiComponent($name)) { - $result = $this->_renderUiComponent($name); - } elseif ($this->isBlock($name)) { - $result = $this->_renderBlock($name); - } else { - $result = $this->_renderContainer($name); - } - $this->_renderElementCache[$name] = $result; + $this->_renderElementCache[$name] = $this->renderNonCachedElement($name); } $this->_renderingOutput->setData('output', $this->_renderElementCache[$name]); $this->_eventManager->dispatch( @@ -475,6 +468,24 @@ class Layout extends \Magento\Framework\Simplexml\Config implements \Magento\Fra return $this->_renderingOutput->getData('output'); } + /** + * Render non cached element + * + * @param string $name + * @return string + */ + public function renderNonCachedElement($name) + { + if ($this->isUiComponent($name)) { + $result = $this->_renderUiComponent($name); + } elseif ($this->isBlock($name)) { + $result = $this->_renderBlock($name); + } else { + $result = $this->_renderContainer($name); + } + return $result; + } + /** * Gets HTML of block element * diff --git a/lib/internal/Magento/Framework/View/Layout/Generator/Block.php b/lib/internal/Magento/Framework/View/Layout/Generator/Block.php index 1bd30ebe9ca8c29dfedb2a98423306a3174266d4..d6b0a5b5a11f35c268155d40e59312ece89c7fae 100644 --- a/lib/internal/Magento/Framework/View/Layout/Generator/Block.php +++ b/lib/internal/Magento/Framework/View/Layout/Generator/Block.php @@ -5,6 +5,7 @@ */ namespace Magento\Framework\View\Layout\Generator; +use Magento\Framework\App\State; use Magento\Framework\ObjectManager\Config\Reader\Dom; use Magento\Framework\View\Layout; @@ -49,6 +50,16 @@ class Block implements Layout\GeneratorInterface */ protected $scopeResolver; + /** + * @var State + */ + protected $appState; + + /** + * @var \Magento\Framework\View\Element\ExceptionHandlerBlock + */ + protected $exceptionHandlerBlockFactory; + /** * @param \Magento\Framework\View\Element\BlockFactory $blockFactory * @param \Magento\Framework\Data\Argument\InterpreterInterface $argumentInterpreter @@ -56,6 +67,8 @@ class Block implements Layout\GeneratorInterface * @param \Psr\Log\LoggerInterface $logger * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Framework\App\ScopeResolverInterface $scopeResolver + * @param \Magento\Framework\View\Element\ExceptionHandlerBlockFactory $exceptionHandlerBlockFactory + * @param State $appState */ public function __construct( \Magento\Framework\View\Element\BlockFactory $blockFactory, @@ -63,7 +76,9 @@ class Block implements Layout\GeneratorInterface \Magento\Framework\Event\ManagerInterface $eventManager, \Psr\Log\LoggerInterface $logger, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, - \Magento\Framework\App\ScopeResolverInterface $scopeResolver + \Magento\Framework\App\ScopeResolverInterface $scopeResolver, + \Magento\Framework\View\Element\ExceptionHandlerBlockFactory $exceptionHandlerBlockFactory, + State $appState ) { $this->blockFactory = $blockFactory; $this->argumentInterpreter = $argumentInterpreter; @@ -71,6 +86,8 @@ class Block implements Layout\GeneratorInterface $this->logger = $logger; $this->scopeConfig = $scopeConfig; $this->scopeResolver = $scopeResolver; + $this->exceptionHandlerBlockFactory = $exceptionHandlerBlockFactory; + $this->appState = $appState; } /** @@ -89,6 +106,7 @@ class Block implements Layout\GeneratorInterface * @param Layout\Reader\Context $readerContext * @param Context $generatorContext * @return $this + * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function process(Layout\Reader\Context $readerContext, Layout\Generator\Context $generatorContext) { @@ -102,34 +120,72 @@ class Block implements Layout\GeneratorInterface foreach ($scheduledStructure->getElements() as $elementName => $element) { list($type, $data) = $element; if ($type === self::TYPE) { - $block = $this->generateBlock($scheduledStructure, $structure, $elementName); - $blocks[$elementName] = $block; - $layout->setBlock($elementName, $block); - if (!empty($data['actions'])) { - $blockActions[$elementName] = $data['actions']; + try { + $block = $this->generateBlock($scheduledStructure, $structure, $elementName); + $blocks[$elementName] = $block; + $layout->setBlock($elementName, $block); + if (!empty($data['actions'])) { + $blockActions[$elementName] = $data['actions']; + } + } catch (\Exception $e) { + $this->handleRenderException($e); + unset($blocks[$elementName]); } } } // Set layout instance to all generated block (trigger _prepareLayout method) foreach ($blocks as $elementName => $block) { - $block->setLayout($layout); - $this->eventManager->dispatch('core_layout_block_create_after', ['block' => $block]); + try { + $block->setLayout($layout); + $this->eventManager->dispatch('core_layout_block_create_after', ['block' => $block]); + } catch (\Exception $e) { + $this->handleRenderException($e); + $layout->setBlock( + $elementName, + $this->exceptionHandlerBlockFactory->create(['blockName' => $elementName]) + ); + unset($blockActions[$elementName]); + } $scheduledStructure->unsetElement($elementName); } // Run all actions after layout initialization foreach ($blockActions as $elementName => $actions) { - foreach ($actions as $action) { - list($methodName, $actionArguments, $configPath, $scopeType) = $action; - if (empty($configPath) - || $this->scopeConfig->isSetFlag($configPath, $scopeType, $this->scopeResolver->getScope()) - ) { - $this->generateAction($blocks[$elementName], $methodName, $actionArguments); + try { + foreach ($actions as $action) { + list($methodName, $actionArguments, $configPath, $scopeType) = $action; + if (empty($configPath) + || $this->scopeConfig->isSetFlag($configPath, $scopeType, $this->scopeResolver->getScope()) + ) { + $this->generateAction($blocks[$elementName], $methodName, $actionArguments); + } } + } catch (\Exception $e) { + $this->handleRenderException($e); + $layout->setBlock( + $elementName, + $this->exceptionHandlerBlockFactory->create(['blockName' => $elementName]) + ); } } return $this; } + /** + * Handle exceptions during rendering process + * + * @param \Exception $cause + * @throws \Exception + * @return void + */ + protected function handleRenderException(\Exception $cause) + { + if ($this->appState->getMode() === State::MODE_DEVELOPER) { + throw $cause; + } + $message = ($cause instanceof LocalizedException) ? $cause->getLogMessage() : $cause->getMessage(); + $this->logger->critical($message); + } + /** * Create block and set related data * diff --git a/lib/internal/Magento/Framework/View/Test/Unit/LayoutTest.php b/lib/internal/Magento/Framework/View/Test/Unit/LayoutTest.php index 7679ac3d2846e2f1a06c3dada1b988e275ea5de4..45effcf449e43c4e7a05dcc77d37003195069eea 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/LayoutTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/LayoutTest.php @@ -26,11 +26,6 @@ class LayoutTest extends \PHPUnit_Framework_TestCase */ protected $processorFactoryMock; - /** - * @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject - */ - protected $appStateMock; - /** * @var \Magento\Framework\View\Design\Theme\ResolverInterface|\PHPUnit_Framework_MockObject_MockObject */