Skip to content

Commit

Permalink
Merge pull request #259 from magento-extensibility/MAGETWO-46445-corr…
Browse files Browse the repository at this point in the history
…ect-erroneous-negative-recommendation

[Extensibility] Bug fixes
  • Loading branch information
Melnikov, Igor(imelnikov) committed Dec 23, 2015
2 parents 33b13b6 + b5dc13b commit 44f284d
Show file tree
Hide file tree
Showing 25 changed files with 256 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
*/
namespace Magento\Config\Model\Config\Structure\Element\Group;

class Proxy extends \Magento\Config\Model\Config\Structure\Element\Group
class Proxy extends \Magento\Config\Model\Config\Structure\Element\Group implements
\Magento\Framework\ObjectManager\NoninterceptableInterface
{
/**
* Object manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
*/
namespace Magento\Config\Model\Config\Structure\Search;

class Proxy implements \Magento\Config\Model\Config\Structure\SearchInterface
class Proxy implements
\Magento\Config\Model\Config\Structure\SearchInterface,
\Magento\Framework\ObjectManager\NoninterceptableInterface
{
/**
* Object manager
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Deploy/Model/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ protected function compile(
DirectoryList::DI,
]
);
$cmd = $this->functionCallPath . 'setup:di:compile-multi-tenant';
$cmd = $this->functionCallPath . 'setup:di:compile';

/**
* exec command is necessary for now to isolate the autoloaders in the compiler from the memory state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
*/
namespace Magento\PageCache\Model\System\Config\Source;

use Magento\Framework\Option\ArrayInterface;
use Magento\PageCache\Model\Config;

/**
* Class Application
*
*/
class Application implements \Magento\Framework\Option\ArrayInterface
class Application implements ArrayInterface
{
/**
* Options getter
Expand All @@ -24,12 +26,12 @@ public function toOptionArray()
{
return [
[
'value' => \Magento\PageCache\Model\Config::BUILT_IN,
'label' => __('Built-in Application (Not Recommended for Production Use)')
'value' => Config::BUILT_IN,
'label' => __('Built-in Cache')
],
[
'value' => \Magento\PageCache\Model\Config::VARNISH,
'label' => __('Varnish Caching')
'value' => Config::VARNISH,
'label' => __('Varnish Cache (Recommended)')
]
];
}
Expand All @@ -42,9 +44,8 @@ public function toOptionArray()
public function toArray()
{
return [
\Magento\PageCache\Model\Config::BUILT_IN =>
__('Built-in Application (Not Recommended for Production Use)'),
\Magento\PageCache\Model\Config::VARNISH => __('Varnish Caching')
Config::BUILT_IN => __('Built-in Cache'),
Config::VARNISH => __('Varnish Cache (Recommended)')
];
}
}
4 changes: 2 additions & 2 deletions app/code/Magento/PageCache/i18n/en_US.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"Export VCL","Export VCL"
"Ttl value ""%1"" is not valid. Please use only numbers equal or greater than zero.","Ttl value ""%1"" is not valid. Please use only numbers equal or greater than zero."
"Built-in Application (Not Recommended for Production Use)","Built-in Application (Not Recommended for Production Use)"
"Varnish Caching","Varnish Caching"
"Built-in Cache","Built-in Cache"
"Varnish Cache (Recommended)","Varnish Cache (Recommended)"
"Full Page Cache","Full Page Cache"
"Caching Application","Caching Application"
"Varnish Configuration","Varnish Configuration"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct(BrowserInterface $browser)
*/
public function open()
{
$this->browser->open($this->url);
$this->openSwaggerUrl();
$this->waitForPageToLoad();
}

Expand Down Expand Up @@ -209,4 +209,29 @@ function () use ($browser, $selector, $strategy) {
}
);
}

/**
* Wait to open swagger url
*
* This is to work around an issue with selenium web driver randomly returns browser url as "about:blank"
* when open swagger page
*
* @return bool|null
*/
private function openSwaggerUrl()
{
$browser = $this->browser;
$pattern = self::MCA;
return $browser->waitUntil(
function () use ($browser, $pattern) {
try {
$url = $_ENV['app_frontend_url'] . $pattern;
$browser->open($url);
return true;
} catch (\PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) {
return false;
}
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Magento\Framework\Code\GeneratorTest\SourceClassWithNamespace;
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
class Proxy extends \Magento\Framework\Code\GeneratorTest\SourceClassWithNamespace
class Proxy extends \Magento\Framework\Code\GeneratorTest\SourceClassWithNamespace implements \Magento\Framework\ObjectManager\NoninterceptableInterface
{
/**
* Object Manager instance
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/Magento/Framework/App/AreaList/Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
*/
namespace Magento\Framework\App\AreaList;

class Proxy extends \Magento\Framework\App\AreaList
class Proxy extends \Magento\Framework\App\AreaList implements
\Magento\Framework\ObjectManager\NoninterceptableInterface
{
/**
* Object Manager instance
Expand Down
12 changes: 7 additions & 5 deletions lib/internal/Magento/Framework/App/Cache/Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\App\Cache;

use \Magento\Framework\App\CacheInterface;
use \Magento\Framework\ObjectManager\NoninterceptableInterface;

/**
* System cache proxy model
*/
namespace Magento\Framework\App\Cache;

use Magento\Framework\App\CacheInterface;

class Proxy implements CacheInterface
class Proxy implements
CacheInterface,
NoninterceptableInterface
{
/**
* @var \Magento\Framework\ObjectManagerInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
/**
* Proxy class for \Magento\Framework\App\ResourceConnection
*/
class Proxy implements \Magento\Framework\App\Route\ConfigInterface
class Proxy implements
\Magento\Framework\App\Route\ConfigInterface,
\Magento\Framework\ObjectManager\NoninterceptableInterface
{
/**
* Object Manager instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
/**
* Proxy class for @see \Magento\Framework\DataObject\Copy\Config\Data
*/
class Proxy extends \Magento\Framework\DataObject\Copy\Config\Data
class Proxy extends \Magento\Framework\DataObject\Copy\Config\Data implements
\Magento\Framework\ObjectManager\NoninterceptableInterface
{
/**
* Object Manager instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,31 @@
namespace Magento\Framework\Interception\ObjectManager\Config;

use Magento\Framework\Interception\ObjectManager\ConfigInterface;
use Magento\Framework\ObjectManager\DefinitionInterface;
use Magento\Framework\ObjectManager\RelationsInterface;
use Magento\Framework\ObjectManager\InterceptableValidator;

class Developer extends \Magento\Framework\ObjectManager\Config\Config implements ConfigInterface
{
/**
* @var InterceptableValidator
*/
private $interceptableValidator;

/**
* @param RelationsInterface $relations
* @param DefinitionInterface $definitions
* @param InterceptableValidator $interceptableValidator
*/
public function __construct(
RelationsInterface $relations = null,
DefinitionInterface $definitions = null,
InterceptableValidator $interceptableValidator = null
) {
$this->interceptableValidator = $interceptableValidator ?: new InterceptableValidator();
parent::__construct($relations, $definitions);
}

/**
* @var \Magento\Framework\Interception\ConfigInterface
*/
Expand All @@ -36,7 +58,9 @@ public function setInterceptionConfig(\Magento\Framework\Interception\ConfigInte
public function getInstanceType($instanceName)
{
$type = parent::getInstanceType($instanceName);
if ($this->interceptionConfig && $this->interceptionConfig->hasPlugins($instanceName)) {
if ($this->interceptionConfig && $this->interceptionConfig->hasPlugins($instanceName)
&& $this->interceptableValidator->validate($instanceName)
) {
return $type . '\\Interceptor';
}
return $type;
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/Magento/Framework/Mview/Config/Data/Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
/**
* Proxy class for \Magento\Framework\Mview\Config\Data
*/
class Proxy extends \Magento\Framework\Mview\Config\Data
class Proxy extends \Magento\Framework\Mview\Config\Data implements
\Magento\Framework\ObjectManager\NoninterceptableInterface
{
/**
* Object Manager instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class Proxy extends \Magento\Framework\Code\Generator\EntityAbstract
*/
const ENTITY_TYPE = 'proxy';

/**
* Marker interface
*/
const NON_INTERCEPTABLE_INTERFACE = '\Magento\Framework\ObjectManager\NoninterceptableInterface';

/**
* @param string $modelClassName
* @return string
Expand Down Expand Up @@ -131,9 +136,10 @@ protected function _generateCode()
$reflection = new \ReflectionClass($typeName);

if ($reflection->isInterface()) {
$this->_classGenerator->setImplementedInterfaces([$typeName]);
$this->_classGenerator->setImplementedInterfaces([$typeName, self::NON_INTERCEPTABLE_INTERFACE]);
} else {
$this->_classGenerator->setExtendedClass($typeName);
$this->_classGenerator->setImplementedInterfaces([self::NON_INTERCEPTABLE_INTERFACE]);
}
return parent::_generateCode();
}
Expand Down
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);
}
}
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
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Magento\Framework\ObjectManager\Code\Generator;
/**
* Proxy class for @see \Magento\Framework\ObjectManager\Code\Generator\Sample
*/
class Sample_Proxy extends \Magento\Framework\ObjectManager\Code\Generator\Sample
class Sample_Proxy extends \Magento\Framework\ObjectManager\Code\Generator\Sample implements \Magento\Framework\ObjectManager\NoninterceptableInterface
{
/**
* Object Manager instance
Expand Down
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'
)
);
}
}
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
{
}
Loading

0 comments on commit 44f284d

Please sign in to comment.