Skip to content

Commit 90d8f13

Browse files
authored
Merge pull request #111 from magento-engcom/74-eliminate-zend-uri-usage
74: Eliminate usage of Zend_Uri from Magento 2 Open Source
2 parents fa92ca4 + 26cccd4 commit 90d8f13

File tree

9 files changed

+43
-16
lines changed

9 files changed

+43
-16
lines changed

app/code/Magento/Integration/Test/Unit/Model/Oauth/ConsumerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Integration\Test\Unit\Model\Oauth;
77

88
use Magento\Framework\Url\Validator as UrlValidator;
9+
use Zend\Validator\Uri as ZendUriValidator;
910
use Magento\Integration\Model\Oauth\Consumer\Validator\KeyLength;
1011

1112
/**
@@ -84,7 +85,7 @@ protected function setUp()
8485

8586
$this->keyLengthValidator = new KeyLength();
8687

87-
$this->urlValidator = new UrlValidator();
88+
$this->urlValidator = new UrlValidator(new ZendUriValidator());
8889

8990
$this->oauthDataMock = $this->createPartialMock(
9091
\Magento\Integration\Helper\Oauth\Data::class,

app/code/Magento/Store/Model/Store.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Magento\Framework\Url\ScopeInterface as UrlScopeInterface;
1919
use Magento\Framework\UrlInterface;
2020
use Magento\Store\Api\Data\StoreInterface;
21+
use Zend\Uri\UriFactory;
2122

2223
/**
2324
* Store model
@@ -801,7 +802,7 @@ public function isCurrentlySecure()
801802
return false;
802803
}
803804

804-
$uri = \Zend_Uri::factory($secureBaseUrl);
805+
$uri = UriFactory::factory($secureBaseUrl);
805806
$port = $uri->getPort();
806807
$serverPort = $this->_request->getServer('SERVER_PORT');
807808
$isSecure = $uri->getScheme() == 'https' && isset($serverPort) && $port == $serverPort;

dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4235,5 +4235,6 @@
42354235
'Magento\Elasticsearch\Test\Unit\SearchAdapter\ConnectionManagerTest'
42364236
],
42374237
['Zend_Feed', 'Zend\Feed'],
4238+
['Zend_Uri', 'Zend\Uri\Uri'],
42384239
['Zend_Mime', 'Magento\Framework\HTTP\Mime'],
42394240
];

lib/internal/Magento/Framework/HTTP/Adapter/Curl.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public function connect($host, $port = 80, $secure = false)
154154
* Send request to the remote server
155155
*
156156
* @param string $method
157-
* @param \Zend_Uri_Http|string $url
157+
* @param string $url
158158
* @param string $http_ver
159159
* @param array $headers
160160
* @param string $body
@@ -163,9 +163,6 @@ public function connect($host, $port = 80, $secure = false)
163163
*/
164164
public function write($method, $url, $http_ver = '1.1', $headers = [], $body = '')
165165
{
166-
if ($url instanceof \Zend_Uri_Http) {
167-
$url = $url->getUri();
168-
}
169166
$this->_applyConfig();
170167

171168
// set url to post to

lib/internal/Magento/Framework/HTTP/ZendClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ZendClient extends \Zend_Http_Client
2121
protected $_urlEncodeBody = true;
2222

2323
/**
24-
* @param null|\Zend_Uri_Http|string $uri
24+
* @param null|string $uri
2525
* @param null|array $config
2626
*/
2727
public function __construct($uri = null, $config = null)

lib/internal/Magento/Framework/Oauth/Helper/Request.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Framework\Oauth\Helper;
77

88
use Magento\Framework\App\RequestInterface;
9+
use Zend\Uri\UriFactory;
910

1011
class Request
1112
{
@@ -95,7 +96,7 @@ protected function _processRequest($authHeaderValue, $contentTypeHeader, $reques
9596
}
9697
$protocolParamsNotSet = !$protocolParams;
9798

98-
$queryString = \Zend_Uri_Http::fromString($requestUrl)->getQuery();
99+
$queryString = UriFactory::factory($requestUrl)->getQuery();
99100
$this->_extractQueryStringParams($protocolParams, $queryString);
100101

101102
if ($protocolParamsNotSet) {

lib/internal/Magento/Framework/Url/Test/Unit/ValidatorTest.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,21 @@ class ValidatorTest extends \PHPUnit\Framework\TestCase
1212
/** @var \Magento\Framework\Url\Validator */
1313
protected $object;
1414

15+
/** @var \Zend\Validator\Uri */
16+
protected $zendValidator;
17+
1518
/** @var string[] */
1619
protected $expectedValidationMessages = ['invalidUrl' => "Invalid URL '%value%'."];
1720

1821
protected function setUp()
1922
{
2023
$objectManager = new ObjectManager($this);
21-
$this->object = $objectManager->getObject(\Magento\Framework\Url\Validator::class);
24+
25+
$this->zendValidator = $this->createMock(\Zend\Validator\Uri::class);
26+
$this->object = $objectManager->getObject(
27+
\Magento\Framework\Url\Validator::class,
28+
['validator' => $this->zendValidator]
29+
);
2230
}
2331

2432
public function testConstruct()
@@ -28,13 +36,23 @@ public function testConstruct()
2836

2937
public function testIsValidWhenValid()
3038
{
31-
$this->assertEquals(true, $this->object->isValid('http://example.com'));
39+
$this->zendValidator
40+
->method('isValid')
41+
->with('http://example.com')
42+
->willReturn(true);
43+
44+
$this->assertTrue($this->object->isValid('http://example.com'));
3245
$this->assertEquals([], $this->object->getMessages());
3346
}
3447

3548
public function testIsValidWhenInvalid()
3649
{
37-
$this->assertEquals(false, $this->object->isValid('%value%'));
50+
$this->zendValidator
51+
->method('isValid')
52+
->with('%value%')
53+
->willReturn(false);
54+
55+
$this->assertFalse($this->object->isValid('%value%'));
3856
$this->assertEquals($this->expectedValidationMessages, $this->object->getMessages());
3957
}
4058
}

lib/internal/Magento/Framework/Url/Validator.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,20 @@ class Validator extends \Zend_Validate_Abstract
1919
const INVALID_URL = 'invalidUrl';
2020
/**#@-*/
2121

22+
/**
23+
* @var \Zend\Validator\Uri
24+
*/
25+
private $validator;
26+
2227
/**
2328
* Object constructor
2429
*/
25-
public function __construct()
30+
public function __construct(\Zend\Validator\Uri $validator)
2631
{
2732
// set translated message template
2833
$this->setMessage((string)new \Magento\Framework\Phrase("Invalid URL '%value%'."), self::INVALID_URL);
34+
$this->validator = $validator;
35+
$this->validator->setAllowRelative(false);
2936
}
3037

3138
/**
@@ -45,11 +52,12 @@ public function isValid($value)
4552
{
4653
$this->_setValue($value);
4754

48-
if (!\Zend_Uri::check($value)) {
55+
$valid = $this->validator->isValid($value);
56+
57+
if (!$valid) {
4958
$this->_error(self::INVALID_URL);
50-
return false;
5159
}
5260

53-
return true;
61+
return $valid;
5462
}
5563
}

lib/internal/Magento/Framework/Webapi/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Request extends HttpRequest implements RequestInterface
3434
* @param StringUtils $converter
3535
* @param AreaList $areaList
3636
* @param ScopeInterface $configScope
37-
* @param null|string|\Zend_Uri $uri
37+
* @param null|string $uri
3838
*/
3939
public function __construct(
4040
CookieReaderInterface $cookieReader,

0 commit comments

Comments
 (0)