Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pôle IS
Bundles Symfony 2
plantuml-bundle
Commits
1f48e47d
Commit
1f48e47d
authored
May 12, 2016
by
Guillaume Perréal
Browse files
Factorisation de code dans les filtres.
parent
bf0b3729
Changes
4
Hide whitespace changes
Inline
Side-by-side
Model/Filter/AbstractListFilter.php
0 → 100644
View file @
1f48e47d
<?php
/*
* © 2016 IRSTEA
* Guillaume Perréal <guillaume.perreal@irstea.fr>
* Tous droits réservés.
*/
namespace
Irstea\PlantUmlBundle\Model\Filter
;
use
Irstea\PlantUmlBundle\Model\ClassFilterInterface
;
use
ReflectionClass
;
/**
* Description of AbstractListFilter
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
abstract
class
AbstractListFilter
implements
ClassFilterInterface
{
/**
* @var string[]
*/
private
$allowed
=
[];
/**
* @var boolena
*/
private
$notFound
;
public
function
__construct
(
array
$allowed
,
$notFound
=
false
)
{
$this
->
allowed
=
array_map
([
$this
,
'normalize'
],
$allowed
);
$this
->
notFound
=
$notFound
;
}
public
function
accept
(
ReflectionClass
$class
)
{
$tested
=
$this
->
normalize
(
$this
->
extract
(
$class
));
foreach
(
$this
->
allowed
as
$reference
)
{
if
(
$this
->
matches
(
$tested
,
$reference
))
{
return
!
$this
->
notFound
;
}
}
return
$this
->
notFound
;
}
/**
* @param string $value
* @return string
*/
abstract
protected
function
normalize
(
$value
);
/**
* @param ReflectionClass $class
* @return string
*/
abstract
protected
function
extract
(
ReflectionClass
$class
);
/**
* @param string $value
* @return bool
*/
abstract
protected
function
matches
(
$tested
,
$reference
);
}
Model/Filter/ClassFilter.php
View file @
1f48e47d
...
...
@@ -8,7 +8,6 @@
namespace
Irstea\PlantUmlBundle\Model\Filter
;
use
Irstea\PlantUmlBundle\Model\ClassFilterInterface
;
use
ReflectionClass
;
/**
...
...
@@ -16,35 +15,20 @@ use ReflectionClass;
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
class
ClassFilter
implem
en
t
s
ClassFilterInterface
class
ClassFilter
ext
en
d
s
AbstractListFilter
{
/**
* @var string[]
*/
private
$classes
=
[];
/**
* @var boolena
*/
private
$notFound
;
protected
function
extract
(
ReflectionClass
$class
)
{
return
$class
->
getName
();
}
p
ublic
function
__construct
(
array
$classes
,
$notFound
=
fals
e
)
p
rotected
function
matches
(
$tested
,
$referenc
e
)
{
$this
->
classes
=
array_map
(
function
(
$class
)
{
return
trim
(
$class
,
'\\'
);
},
$classes
);
$this
->
notFound
=
$notFound
;
return
$tested
===
$reference
;
}
p
ublic
function
accept
(
ReflectionClass
$class
)
p
rotected
function
normalize
(
$className
)
{
$className
=
$class
->
getName
();
if
(
in_array
(
$className
,
$this
->
classes
))
{
return
!
$this
->
notFound
;
}
return
$this
->
notFound
;
return
trim
(
$className
,
'\\'
);
}
}
Model/Filter/DirectoryFilter.php
View file @
1f48e47d
...
...
@@ -8,7 +8,6 @@
namespace
Irstea\PlantUmlBundle\Model\Filter
;
use
Irstea\PlantUmlBundle\Model\ClassFilterInterface
;
use
ReflectionClass
;
/**
...
...
@@ -16,37 +15,20 @@ use ReflectionClass;
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
class
DirectoryFilter
implem
en
t
s
ClassFilterInterface
class
DirectoryFilter
ext
en
d
s
AbstractListFilter
{
/**
* @var string[]
*/
private
$paths
=
[];
/**
* @var boolean
*/
private
$notFound
;
protected
function
extract
(
ReflectionClass
$class
)
{
return
dirname
(
$class
->
getFileName
());
}
p
ublic
function
__construct
(
array
$paths
,
$notFound
=
fals
e
)
p
rotected
function
matches
(
$tested
,
$referenc
e
)
{
$this
->
paths
=
array_map
(
function
(
$path
)
{
return
rtrim
(
strtr
(
$path
,
'/\\'
,
DIRECTORY_SEPARATOR
),
DIRECTORY_SEPARATOR
)
.
DIRECTORY_SEPARATOR
;
},
$paths
);
$this
->
notFound
=
$notFound
;
return
strpos
(
$tested
,
$reference
)
===
0
;
}
p
ublic
function
accept
(
ReflectionClass
$class
)
p
rotected
function
normalize
(
$path
)
{
$filepath
=
dirname
(
$class
->
getFileName
());
foreach
(
$this
->
paths
as
$path
)
{
if
(
strpos
(
$filepath
,
$path
)
===
0
)
{
return
!
$this
->
notFound
;
}
}
return
$this
->
notFound
;
return
rtrim
(
strtr
(
$path
,
'/\\'
,
DIRECTORY_SEPARATOR
),
DIRECTORY_SEPARATOR
)
.
DIRECTORY_SEPARATOR
;
}
}
Model/Filter/NamespaceFilter.php
View file @
1f48e47d
...
...
@@ -8,7 +8,6 @@
namespace
Irstea\PlantUmlBundle\Model\Filter
;
use
Irstea\PlantUmlBundle\Model\ClassFilterInterface
;
use
ReflectionClass
;
/**
...
...
@@ -16,37 +15,20 @@ use ReflectionClass;
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
class
NamespaceFilter
implem
en
t
s
ClassFilterInterface
class
NamespaceFilter
ext
en
d
s
AbstractListFilter
{
/**
* @var string[]
*/
private
$namespaces
=
[];
/**
* @var boolena
*/
private
$notFound
;
protected
function
extract
(
ReflectionClass
$class
)
{
return
$class
->
getNamespaceName
();
}
p
ublic
function
__construct
(
array
$namespaces
,
$notFound
=
fals
e
)
p
rotected
function
matches
(
$tested
,
$referenc
e
)
{
$this
->
namespaces
=
array_map
(
function
(
$namespace
)
{
return
trim
(
$namespace
,
'\\'
)
.
'\\'
;
},
$namespaces
);
$this
->
notFound
=
$notFound
;
return
strpos
(
$tested
,
$reference
)
===
0
;
}
p
ublic
function
accept
(
ReflectionClass
$class
)
p
rotected
function
normalize
(
$namespace
)
{
$className
=
$class
->
getNamespaceName
()
.
'\\'
;
foreach
(
$this
->
namespaces
as
$namespace
)
{
if
(
strpos
(
$className
,
$namespace
)
===
0
)
{
return
!
$this
->
notFound
;
}
}
return
$this
->
notFound
;
return
trim
(
$namespace
,
'\\'
)
.
'\\'
;
}
}
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