Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
225
Merge Requests
225
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
e5b70636
Commit
e5b70636
authored
Dec 18, 2018
by
catch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#3020165
by alexpott: Dependency objects can be optimised for serialisation
parent
56ccba06
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
0 deletions
+26
-0
core/lib/Drupal/Core/Extension/Dependency.php
core/lib/Drupal/Core/Extension/Dependency.php
+10
-0
core/tests/Drupal/Tests/Core/Extension/DependencyTest.php
core/tests/Drupal/Tests/Core/Extension/DependencyTest.php
+16
-0
No files found.
core/lib/Drupal/Core/Extension/Dependency.php
View file @
e5b70636
...
...
@@ -190,4 +190,14 @@ public static function createFromString($dependency) {
return
new
static
(
$name
,
$project
,
$version_string
);
}
/**
* Prevents unnecessary serialization of constraint objects.
*
* @return array
* The properties to seriailize.
*/
public
function
__sleep
()
{
return
[
'name'
,
'project'
,
'constraintString'
];
}
}
core/tests/Drupal/Tests/Core/Extension/DependencyTest.php
View file @
e5b70636
...
...
@@ -2,6 +2,7 @@
namespace
Drupal\Tests\Core\Extension
;
use
Drupal\Component\Version\Constraint
;
use
Drupal\Core\Extension\Dependency
;
use
Drupal\Tests\UnitTestCase
;
...
...
@@ -100,4 +101,19 @@ public function testOffsetSet() {
$dependency
[
'name'
]
=
'foo'
;
}
/**
* Ensures that constraint objects are not serialized.
*
* @covers ::__sleep
*/
public
function
testSerialization
()
{
$dependency
=
new
Dependency
(
'paragraphs_demo'
,
'paragraphs'
,
'>8.x-1.1'
);
$this
->
assertTrue
(
$dependency
->
isCompatible
(
'1.2'
));
$this
->
assertInstanceOf
(
Constraint
::
class
,
$this
->
getObjectAttribute
(
$dependency
,
'constraint'
));
$dependency
=
unserialize
(
serialize
(
$dependency
));
$this
->
assertNull
(
$this
->
getObjectAttribute
(
$dependency
,
'constraint'
));
$this
->
assertTrue
(
$dependency
->
isCompatible
(
'1.2'
));
$this
->
assertInstanceOf
(
Constraint
::
class
,
$this
->
getObjectAttribute
(
$dependency
,
'constraint'
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment