Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
default_content
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
default_content
Commits
5d34cd54
Commit
5d34cd54
authored
Aug 3, 2015
by
Lee Rowlands
Browse files
Options
Downloads
Plain Diff
Merge pull request
#46
from larowlan/graph-not-gliph
Use core Graph over Gliph
parents
c31f933f
7e70fa3f
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
.travis.yml
+1
-1
1 addition, 1 deletion
.travis.yml
src/DefaultContentManager.php
+19
-23
19 additions, 23 deletions
src/DefaultContentManager.php
with
20 additions
and
24 deletions
.travis.yml
+
1
−
1
View file @
5d34cd54
...
@@ -7,7 +7,7 @@ cache:
...
@@ -7,7 +7,7 @@ cache:
apt
:
true
apt
:
true
php
:
php
:
-
5.
4
-
5.
6
-
5.5
-
5.5
env
:
env
:
...
...
This diff is collapsed.
Click to expand it.
src/DefaultContentManager.php
+
19
−
23
View file @
5d34cd54
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
namespace
Drupal\default_content
;
namespace
Drupal\default_content
;
use
Drupal\Component\Graph\Graph
;
use
Drupal\Component\Utility\SafeMarkup
;
use
Drupal\Component\Utility\SafeMarkup
;
use
Drupal\Core\Config\Entity\ConfigEntityInterface
;
use
Drupal\Core\Config\Entity\ConfigEntityInterface
;
use
Drupal\Core\Entity\ContentEntityInterface
;
use
Drupal\Core\Entity\ContentEntityInterface
;
...
@@ -14,8 +15,6 @@ use Drupal\Core\Entity\EntityManager;
...
@@ -14,8 +15,6 @@ use Drupal\Core\Entity\EntityManager;
use
Drupal\Core\Session\AccountInterface
;
use
Drupal\Core\Session\AccountInterface
;
use
Drupal\rest\LinkManager\LinkManagerInterface
;
use
Drupal\rest\LinkManager\LinkManagerInterface
;
use
Drupal\rest\Plugin\Type\ResourcePluginManager
;
use
Drupal\rest\Plugin\Type\ResourcePluginManager
;
use
Gliph\Graph\DirectedAdjacencyList
;
use
Gliph\Traversal\DepthFirst
;
use
Symfony\Component\Serializer\Serializer
;
use
Symfony\Component\Serializer\Serializer
;
/**
/**
...
@@ -62,18 +61,18 @@ class DefaultContentManager implements DefaultContentManagerInterface {
...
@@ -62,18 +61,18 @@ class DefaultContentManager implements DefaultContentManagerInterface {
protected
$scanner
;
protected
$scanner
;
/**
/**
*
The tree resolver
.
*
A list of vertex objects keyed by their link
.
*
*
* @var
\Gliph\Graph\DirectedAdjacencyList
* @var
array
*/
*/
protected
$
tree
=
FALSE
;
protected
$
vertexes
=
array
()
;
/**
/**
*
A list of vertex objects keyed by their link
.
*
The graph entries
.
*
*
* @var array
* @var array
*/
*/
protected
$
vertexes
=
array
()
;
protected
$
graph
=
[]
;
/**
/**
* The link manager service.
* The link manager service.
...
@@ -151,7 +150,7 @@ class DefaultContentManager implements DefaultContentManagerInterface {
...
@@ -151,7 +150,7 @@ class DefaultContentManager implements DefaultContentManagerInterface {
$file_map
[
$self
]
=
$file
;
$file_map
[
$self
]
=
$file
;
// Create a vertex for the graph.
// Create a vertex for the graph.
$vertex
=
$this
->
getVertex
(
$self
);
$vertex
=
$this
->
getVertex
(
$self
);
$this
->
tree
()
->
addVertex
(
$vertex
)
;
$this
->
graph
[
$vertex
->
link
][
'edges'
]
=
[]
;
if
(
empty
(
$decoded
[
'_embedded'
]))
{
if
(
empty
(
$decoded
[
'_embedded'
]))
{
// No dependencies to resolve.
// No dependencies to resolve.
continue
;
continue
;
...
@@ -159,17 +158,18 @@ class DefaultContentManager implements DefaultContentManagerInterface {
...
@@ -159,17 +158,18 @@ class DefaultContentManager implements DefaultContentManagerInterface {
// Here we need to resolve our dependencies;
// Here we need to resolve our dependencies;
foreach
(
$decoded
[
'_embedded'
]
as
$embedded
)
{
foreach
(
$decoded
[
'_embedded'
]
as
$embedded
)
{
foreach
(
$embedded
as
$item
)
{
foreach
(
$embedded
as
$item
)
{
$this
->
tree
()
->
addDirectedEdge
(
$vertex
,
$this
->
getVertex
(
$item
[
'_links'
][
'self'
][
'href'
]));
$edge
=
$this
->
getVertex
(
$item
[
'_links'
][
'self'
][
'href'
]);
$this
->
graph
[
$vertex
->
link
][
'edges'
][
$edge
->
link
]
=
TRUE
;
}
}
}
}
}
}
}
}
// @todo what if no dependencies?
// @todo what if no dependencies?
$sorted
=
$this
->
sortTree
();
$sorted
=
$this
->
sortTree
(
$this
->
graph
);
foreach
(
$sorted
as
$
vertex
)
{
foreach
(
$sorted
as
$
link
=>
$details
)
{
if
(
!
empty
(
$file_map
[
$
vertex
->
link
]))
{
if
(
!
empty
(
$file_map
[
$link
]))
{
$file
=
$file_map
[
$
vertex
->
link
];
$file
=
$file_map
[
$link
];
$entity_type_id
=
$file
->
entity_type_id
;
$entity_type_id
=
$file
->
entity_type_id
;
$resource
=
$this
->
resourcePluginManager
->
getInstance
(
array
(
'id'
=>
'entity:'
.
$entity_type_id
));
$resource
=
$this
->
resourcePluginManager
->
getInstance
(
array
(
'id'
=>
'entity:'
.
$entity_type_id
));
$definition
=
$resource
->
getPluginDefinition
();
$definition
=
$resource
->
getPluginDefinition
();
...
@@ -292,20 +292,16 @@ class DefaultContentManager implements DefaultContentManagerInterface {
...
@@ -292,20 +292,16 @@ class DefaultContentManager implements DefaultContentManagerInterface {
return
file_get_contents
(
$file
->
uri
);
return
file_get_contents
(
$file
->
uri
);
}
}
protected
function
tree
()
{
if
(
empty
(
$this
->
tree
))
{
$this
->
tree
=
new
DirectedAdjacencyList
();
}
return
$this
->
tree
;
}
protected
function
resetTree
()
{
protected
function
resetTree
()
{
$this
->
tree
=
FALSE
;
$this
->
graph
=
[]
;
$this
->
vertexes
=
array
();
$this
->
vertexes
=
array
();
}
}
protected
function
sortTree
()
{
protected
function
sortTree
(
array
$graph
)
{
return
DepthFirst
::
toposort
(
$this
->
tree
());
$graph_object
=
new
Graph
(
$graph
);
$sorted
=
$graph_object
->
searchAndSort
();
uasort
(
$sorted
,
'Drupal\Component\Utility\SortArray::sortByWeightElement'
);
return
array_reverse
(
$sorted
);
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment