Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Pôle IS
Bundles Symfony 2
plantuml-bundle
Commits
8f94a20a
Commit
8f94a20a
authored
May 12, 2016
by
Guillaume Perréal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ajout d'un filtre sur les noms de classe.
parent
c80e08d3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
89 additions
and
20 deletions
+89
-20
DependencyInjection/Configuration.php
DependencyInjection/Configuration.php
+4
-0
Factory/FilterFactory.php
Factory/FilterFactory.php
+26
-20
Model/Filter/ClassFilter.php
Model/Filter/ClassFilter.php
+59
-0
No files found.
DependencyInjection/Configuration.php
View file @
8f94a20a
...
...
@@ -144,6 +144,10 @@ class Configuration implements ConfigurationInterface
->
info
(
"Namespaces
$description
"
)
->
prototype
(
'scalar'
)
->
end
()
->
end
()
->
arrayNode
(
'classes'
)
->
info
(
"Classes
$description
"
)
->
prototype
(
'scalar'
)
->
end
()
->
end
()
->
end
();
return
$node
;
...
...
Factory/FilterFactory.php
View file @
8f94a20a
...
...
@@ -10,6 +10,7 @@ namespace Irstea\PlantUmlBundle\Factory;
use
Irstea\PlantUmlBundle\Model\ClassFilterInterface
;
use
Irstea\PlantUmlBundle\Model\Filter\AcceptAllFilter
;
use
Irstea\PlantUmlBundle\Model\Filter\ClassFilter
;
use
Irstea\PlantUmlBundle\Model\Filter\Composite\AllFilter
;
use
Irstea\PlantUmlBundle\Model\Filter\DirectoryFilter
;
use
Irstea\PlantUmlBundle\Model\Filter\NamespaceFilter
;
...
...
@@ -42,45 +43,50 @@ class FilterFactory
$filters
=
[];
if
(
!
empty
(
$include
))
{
$
filters
[]
=
$this
->
createSubFilters
(
$include
,
false
);
$
this
->
appendFilters
(
$filters
,
$include
,
false
);
}
if
(
!
empty
(
$exclude
))
{
$
filters
[]
=
$this
->
createSubFilters
(
$exclude
,
true
);
$
this
->
appendFilters
(
$filters
,
$exclude
,
true
);
}
$filters
=
array_merge
(
$filters
);
switch
(
count
(
$filters
))
{
case
0
:
return
AcceptAllFilter
::
instance
();
$filter
=
AcceptAllFilter
::
instance
();
break
;
case
1
:
return
$filters
[
0
];
$filter
=
$filters
[
0
];
break
;
default
:
return
new
AllFilter
(
$filters
);
$filter
=
new
AllFilter
(
$filters
);
}
dump
([
'include'
=>
$include
,
'exclude'
=>
$exclude
,
'filter'
=>
$filter
->
describe
()]);
return
$filter
;
}
protected
function
createSubFilters
(
array
$config
,
$notFound
)
protected
function
appendFilters
(
array
&
$filters
,
array
$config
,
$notFound
)
{
$filters
=
[];
if
(
!
empty
(
$config
[
'directories'
]))
{
$paths
=
$this
->
parseDirectorie
s
(
$config
[
'directories'
]);
$paths
=
$this
->
expandBundlePath
s
(
$config
[
'directories'
]);
$filters
[]
=
new
DirectoryFilter
(
$paths
,
$notFound
);
}
if
(
!
empty
(
$config
[
'namespaces'
]))
{
$namespaces
=
$this
->
pars
eNamespaces
(
$config
[
'namespaces'
]);
$namespaces
=
$this
->
expandBundl
eNamespaces
(
$config
[
'namespaces'
]);
$filters
[]
=
new
NamespaceFilter
(
$namespaces
,
$notFound
);
}
return
$filters
;
if
(
!
empty
(
$config
[
'classes'
]))
{
$classes
=
$this
->
expandBundleNamespaces
(
$config
[
'classes'
]);
$filters
[]
=
new
ClassFilter
(
$classes
,
$notFound
);
}
}
/**
* @param array $paths
* @return array
*/
protected
function
parseDirectorie
s
(
array
$paths
)
protected
function
expandBundlePath
s
(
array
$paths
)
{
$actualPaths
=
[];
foreach
(
$paths
as
$path
)
{
...
...
@@ -97,16 +103,16 @@ class FilterFactory
* @param array $paths
* @return array
*/
protected
function
pars
eNamespaces
(
array
$names
paces
)
protected
function
expandBundl
eNamespaces
(
array
$names
)
{
$actualNames
paces
=
[];
foreach
(
$names
paces
as
$name
space
)
{
if
(
preg_match
(
'/^@(\w+)(.*)$/'
,
$name
space
,
$groups
))
{
$actualNames
=
[];
foreach
(
$names
as
$name
)
{
if
(
preg_match
(
'/^@(\w+)(.*)$/'
,
$name
,
$groups
))
{
$bundle
=
$this
->
kernel
->
getBundle
(
$groups
[
1
]);
$name
space
=
$bundle
->
getNamespace
()
.
$groups
[
2
];
$name
=
$bundle
->
getNamespace
()
.
$groups
[
2
];
}
$actualNames
paces
[]
=
$name
space
;
$actualNames
[]
=
$name
;
}
return
$actualNames
paces
;
return
$actualNames
;
}
}
Model/Filter/
Whitelist
.php
→
Model/Filter/
ClassFilter
.php
View file @
8f94a20a
...
...
@@ -12,24 +12,48 @@ use Irstea\PlantUmlBundle\Model\ClassFilterInterface;
use
ReflectionClass
;
/**
* Description of
Whiltelist
* Description of
DirectoryFilter
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
class
Whitelist
implements
ClassFilterInterface
class
ClassFilter
implements
ClassFilterInterface
{
/**
* @var string[]
*/
private
$
accepted
;
private
$
classes
=
[]
;
public
function
__construct
(
array
$classNames
)
/**
* @var boolena
*/
private
$notFound
;
public
function
__construct
(
array
$classes
,
$notFound
=
false
)
{
$this
->
accepted
=
array_fill_keys
(
$classNames
,
true
);
$this
->
classes
=
array_map
(
function
(
$class
)
{
return
trim
(
$class
,
'\\'
);
},
$classes
);
$this
->
notFound
=
$notFound
;
}
public
function
accept
(
ReflectionClass
$class
)
{
return
isset
(
$this
->
accepted
[
$class
->
getName
()]);
$className
=
$class
->
getName
();
if
(
in_array
(
$className
,
$this
->
classes
))
{
return
!
$this
->
notFound
;
}
return
$this
->
notFound
;
}
public
function
describe
()
{
return
sprintf
(
"Class is%s [%s]"
,
$this
->
notFound
?
''
:
' not'
,
implode
(
', '
,
$this
->
classes
)
);
}
}
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