Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
default_content
Commits
5d34cd54
Commit
5d34cd54
authored
Aug 03, 2015
by
larowlan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request
#46
from larowlan/graph-not-gliph
Use core Graph over Gliph
parents
c31f933f
7e70fa3f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
24 deletions
+20
-24
.travis.yml
.travis.yml
+1
-1
src/DefaultContentManager.php
src/DefaultContentManager.php
+19
-23
No files found.
.travis.yml
View file @
5d34cd54
...
...
@@ -7,7 +7,7 @@ cache:
apt
:
true
php
:
-
5.
4
-
5.
6
-
5.5
env
:
...
...
src/DefaultContentManager.php
View file @
5d34cd54
...
...
@@ -7,6 +7,7 @@
namespace
Drupal\default_content
;
use
Drupal\Component\Graph\Graph
;
use
Drupal\Component\Utility\SafeMarkup
;
use
Drupal\Core\Config\Entity\ConfigEntityInterface
;
use
Drupal\Core\Entity\ContentEntityInterface
;
...
...
@@ -14,8 +15,6 @@ use Drupal\Core\Entity\EntityManager;
use
Drupal\Core\Session\AccountInterface
;
use
Drupal\rest\LinkManager\LinkManagerInterface
;
use
Drupal\rest\Plugin\Type\ResourcePluginManager
;
use
Gliph\Graph\DirectedAdjacencyList
;
use
Gliph\Traversal\DepthFirst
;
use
Symfony\Component\Serializer\Serializer
;
/**
...
...
@@ -62,18 +61,18 @@ class DefaultContentManager implements DefaultContentManagerInterface {
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
*/
protected
$
vertexes
=
array
()
;
protected
$
graph
=
[]
;
/**
* The link manager service.
...
...
@@ -151,7 +150,7 @@ class DefaultContentManager implements DefaultContentManagerInterface {
$file_map
[
$self
]
=
$file
;
// Create a vertex for the graph.
$vertex
=
$this
->
getVertex
(
$self
);
$this
->
tree
()
->
addVertex
(
$vertex
)
;
$this
->
graph
[
$vertex
->
link
][
'edges'
]
=
[]
;
if
(
empty
(
$decoded
[
'_embedded'
]))
{
// No dependencies to resolve.
continue
;
...
...
@@ -159,17 +158,18 @@ class DefaultContentManager implements DefaultContentManagerInterface {
// Here we need to resolve our dependencies;
foreach
(
$decoded
[
'_embedded'
]
as
$embedded
)
{
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?
$sorted
=
$this
->
sortTree
();
foreach
(
$sorted
as
$
vertex
)
{
if
(
!
empty
(
$file_map
[
$
vertex
->
link
]))
{
$file
=
$file_map
[
$
vertex
->
link
];
$sorted
=
$this
->
sortTree
(
$this
->
graph
);
foreach
(
$sorted
as
$
link
=>
$details
)
{
if
(
!
empty
(
$file_map
[
$link
]))
{
$file
=
$file_map
[
$link
];
$entity_type_id
=
$file
->
entity_type_id
;
$resource
=
$this
->
resourcePluginManager
->
getInstance
(
array
(
'id'
=>
'entity:'
.
$entity_type_id
));
$definition
=
$resource
->
getPluginDefinition
();
...
...
@@ -292,20 +292,16 @@ class DefaultContentManager implements DefaultContentManagerInterface {
return
file_get_contents
(
$file
->
uri
);
}
protected
function
tree
()
{
if
(
empty
(
$this
->
tree
))
{
$this
->
tree
=
new
DirectedAdjacencyList
();
}
return
$this
->
tree
;
}
protected
function
resetTree
()
{
$this
->
tree
=
FALSE
;
$this
->
graph
=
[]
;
$this
->
vertexes
=
array
();
}
protected
function
sortTree
()
{
return
DepthFirst
::
toposort
(
$this
->
tree
());
protected
function
sortTree
(
array
$graph
)
{
$graph_object
=
new
Graph
(
$graph
);
$sorted
=
$graph_object
->
searchAndSort
();
uasort
(
$sorted
,
'Drupal\Component\Utility\SortArray::sortByWeightElement'
);
return
array_reverse
(
$sorted
);
}
/**
...
...
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