-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #259 from magento-extensibility/MAGETWO-46445-corr…
…ect-erroneous-negative-recommendation [Extensibility] Bug fixes
- Loading branch information
Showing
25 changed files
with
256 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
lib/internal/Magento/Framework/ObjectManager/InterceptableValidator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Framework\ObjectManager; | ||
|
||
class InterceptableValidator | ||
{ | ||
/** | ||
* @param string $className | ||
* @return bool | ||
*/ | ||
public function validate($className) | ||
{ | ||
return !$this->isInterceptor($className) && $this->isInterceptable($className); | ||
} | ||
|
||
/** | ||
* | ||
* Check if instance type is interceptor | ||
* | ||
* @param string $instanceName | ||
* @return bool | ||
*/ | ||
private function isInterceptor($instanceName) | ||
{ | ||
return $this->endsWith($instanceName, '\Interceptor'); | ||
} | ||
|
||
/** | ||
* | ||
* Check if instance type is interceptable | ||
* | ||
* @param string $instanceName | ||
* @return bool | ||
*/ | ||
private function isInterceptable($instanceName) | ||
{ | ||
return !is_subclass_of( | ||
$instanceName, | ||
\Magento\Framework\ObjectManager\Code\Generator\Proxy::NON_INTERCEPTABLE_INTERFACE | ||
); | ||
} | ||
|
||
/** | ||
* Check if a string ends with a substring | ||
* | ||
* @param string $haystack | ||
* @param string $needle | ||
* @return bool | ||
*/ | ||
private function endsWith($haystack, $needle) | ||
{ | ||
// Search forward starting from end minus needle length characters | ||
$temp = strlen($haystack) - strlen($needle); | ||
return $needle === '' || ($temp >= 0 && strpos($haystack, $needle, $temp) !== false); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
lib/internal/Magento/Framework/ObjectManager/NoninterceptableInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Framework\ObjectManager; | ||
|
||
/** | ||
* Marker interface, used to identify proxies for which we don't need to generate interceptors | ||
*/ | ||
interface NoninterceptableInterface | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
lib/internal/Magento/Framework/ObjectManager/Test/Unit/InterceptableValidatorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Framework\ObjectManager\Test\Unit; | ||
|
||
require __DIR__ . '/_files/Proxy.php'; | ||
|
||
class InterceptableValidatorTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testValidate() | ||
{ | ||
$interceptableValidator = new \Magento\Framework\ObjectManager\InterceptableValidator(); | ||
$this->assertFalse( | ||
$interceptableValidator->validate( | ||
'Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper\Interceptor' | ||
) | ||
); | ||
$this->assertFalse( | ||
$interceptableValidator->validate( | ||
'Magento\Test\Di\Proxy' | ||
) | ||
); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
lib/internal/Magento/Framework/ObjectManager/Test/Unit/_files/Proxy.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Test\Di; | ||
|
||
class Proxy implements \Magento\Framework\ObjectManager\NoninterceptableInterface | ||
{ | ||
} |
Oops, something went wrong.