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
5e787728
Commit
5e787728
authored
Mar 09, 2016
by
Guillaume Perréal
Browse files
Refactoring des namespaces.
parent
61295671
Changes
15
Show whitespace changes
Inline
Side-by-side
Command/EntitySchemaCommand.php
View file @
5e787728
...
@@ -9,12 +9,14 @@ namespace Irstea\PlantUmlBundle\Command;
...
@@ -9,12 +9,14 @@ namespace Irstea\PlantUmlBundle\Command;
use
Doctrine\ORM\EntityManagerInterface
;
use
Doctrine\ORM\EntityManagerInterface
;
use
Doctrine\ORM\Mapping\ClassMetadata
;
use
Doctrine\ORM\Mapping\ClassMetadata
;
use
Irstea\PlantUmlBundle\Doctrine\AssociationDecorator
;
use
Irstea\PlantUmlBundle\Doctrine\AssociationDecorator
;
use
Irstea\PlantUmlBundle\Doctrine\DoctrineNamespace
;
use
Irstea\PlantUmlBundle\Doctrine\EntityDecorator
;
use
Irstea\PlantUmlBundle\Doctrine\EntityDecorator
;
use
Irstea\PlantUmlBundle\Model\ClassVisitor
;
use
Irstea\PlantUmlBundle\Model\ClassVisitor
;
use
Irstea\PlantUmlBundle\Model\Decorator\CompositeDecorator
;
use
Irstea\PlantUmlBundle\Model\Decorator\CompositeDecorator
;
use
Irstea\PlantUmlBundle\Model\Decorator\FilteringDecorator
;
use
Irstea\PlantUmlBundle\Model\Decorator\FilteringDecorator
;
use
Irstea\PlantUmlBundle\Model\Decorator\InheritanceDecorator
;
use
Irstea\PlantUmlBundle\Model\Decorator\InheritanceDecorator
;
use
Irstea\PlantUmlBundle\Model\Filter\Whitelist
;
use
Irstea\PlantUmlBundle\Model\Filter\Whitelist
;
use
Irstea\PlantUmlBundle\Model\Namespace_\BundleNamespace
;
use
Irstea\PlantUmlBundle\Model\Namespace_\FlatNamespace
;
use
Irstea\PlantUmlBundle\Model\Namespace_\FlatNamespace
;
use
Irstea\PlantUmlBundle\Writer\OutputWriter
;
use
Irstea\PlantUmlBundle\Writer\OutputWriter
;
use
Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand
;
use
Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand
;
...
@@ -56,6 +58,8 @@ class EntitySchemaCommand extends ContainerAwareCommand
...
@@ -56,6 +58,8 @@ class EntitySchemaCommand extends ContainerAwareCommand
$allMetadata
$allMetadata
);
);
$namespace
=
new
BundleNamespace
(
$this
->
getContainer
()
->
getParameter
(
'kernel.bundles'
));
$decorator
=
new
FilteringDecorator
(
$decorator
=
new
FilteringDecorator
(
new
CompositeDecorator
([
new
CompositeDecorator
([
new
InheritanceDecorator
(),
new
InheritanceDecorator
(),
...
@@ -65,7 +69,7 @@ class EntitySchemaCommand extends ContainerAwareCommand
...
@@ -65,7 +69,7 @@ class EntitySchemaCommand extends ContainerAwareCommand
new
Whitelist
(
$classes
)
new
Whitelist
(
$classes
)
);
);
$visitor
=
new
ClassVisitor
(
$decorator
,
null
,
n
ew
FlatN
amespace
()
);
$visitor
=
new
ClassVisitor
(
$decorator
,
null
,
$
namespace
);
array_walk
(
$classes
,
[
$visitor
,
'visitClass'
]);
array_walk
(
$classes
,
[
$visitor
,
'visitClass'
]);
...
...
Doctrine/AssociationDecorator.php
View file @
5e787728
...
@@ -44,7 +44,7 @@ class AssociationDecorator extends AbstractDoctrineDecorator
...
@@ -44,7 +44,7 @@ class AssociationDecorator extends AbstractDoctrineDecorator
return
;
return
;
}
}
$link
=
"-
-
>"
;
$link
=
"->"
;
if
(
$association
[
"isCascadeRemove"
])
{
if
(
$association
[
"isCascadeRemove"
])
{
$link
=
"o"
.
$link
;
$link
=
"o"
.
$link
;
}
}
...
...
Doctrine/DoctrineNamespace.php
0 → 100644
View file @
5e787728
<?php
/*
* © 2016 IRSTEA
* Guillaume Perréal <guillaume.perreal@irstea.fr>
* Tous droits réservés.
*/
namespace
Irstea\PlantUmlBundle\Doctrine
;
/**
* Description of DoctrineNamespace
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
class
DoctrineNamespace
extends
\
Irstea\PlantUmlBundle\Model\Namespace_\MappedNamespace
{
const
SEPARATOR
=
'::'
;
public
function
__construct
(
array
$entityNamespaces
)
{
$mapping
=
[];
foreach
(
$entityNamespaces
as
$alias
=>
$namespace
)
{
$mapping
[
$namespace
.
'\\'
]
=
$alias
.
'::'
;
}
parent
::
__construct
(
$mapping
);
}
}
Model/ClassVisitor.php
View file @
5e787728
...
@@ -10,12 +10,11 @@ namespace Irstea\PlantUmlBundle\Model;
...
@@ -10,12 +10,11 @@ namespace Irstea\PlantUmlBundle\Model;
use
Irstea\PlantUmlBundle\Model\Decorator\NullDecorator
;
use
Irstea\PlantUmlBundle\Model\Decorator\NullDecorator
;
use
Irstea\PlantUmlBundle\Model\Filter\AcceptAllFilter
;
use
Irstea\PlantUmlBundle\Model\Filter\AcceptAllFilter
;
use
Irstea\PlantUmlBundle\Model\Namespace_\RootNamespace
;
use
Irstea\PlantUmlBundle\Model\Namespace_\
Php\
RootNamespace
;
use
Irstea\PlantUmlBundle\Model\Node\Class_
;
use
Irstea\PlantUmlBundle\Model\Node\Class_
;
use
Irstea\PlantUmlBundle\Model\Node\Interface_
;
use
Irstea\PlantUmlBundle\Model\Node\Interface_
;
use
Irstea\PlantUmlBundle\Model\Node\Trait_
;
use
Irstea\PlantUmlBundle\Model\Node\Trait_
;
use
Irstea\PlantUmlBundle\Writer\WritableInterface
;
use
Irstea\PlantUmlBundle\Writer\WritableInterface
;
use
Irstea\PlantUmlBundle\Writer\WritableNodeInterface
;
use
Irstea\PlantUmlBundle\Writer\WriterInterface
;
use
Irstea\PlantUmlBundle\Writer\WriterInterface
;
use
ReflectionClass
;
use
ReflectionClass
;
...
@@ -103,18 +102,15 @@ class ClassVisitor implements ClassVisitorInterface, WritableInterface
...
@@ -103,18 +102,15 @@ class ClassVisitor implements ClassVisitorInterface, WritableInterface
{
{
$className
=
$class
->
getName
();
$className
=
$class
->
getName
();
$id
=
str_replace
(
'\\'
,
'.'
,
$className
)
.
'_node'
;
$label
=
$namespace
->
getShortName
(
$className
);
if
(
$class
->
isTrait
())
{
if
(
$class
->
isTrait
())
{
return
new
Trait_
(
$namespace
,
$
id
,
$label
);
return
new
Trait_
(
$namespace
,
$
className
);
}
}
if
(
$class
->
isInterface
())
{
if
(
$class
->
isInterface
())
{
return
new
Interface_
(
$namespace
,
$
id
,
$label
,
$class
->
get
Name
()
);
return
new
Interface_
(
$namespace
,
$
class
Name
);
}
}
return
new
Class_
(
$namespace
,
$
id
,
$label
,
$class
->
isAbstract
(),
$class
->
isFinal
());
return
new
Class_
(
$namespace
,
$
className
,
$class
->
isAbstract
(),
$class
->
isFinal
());
}
}
public
function
outputTo
(
WriterInterface
$writer
)
public
function
outputTo
(
WriterInterface
$writer
)
...
...
Model/NamespaceInterface.php
View file @
5e787728
...
@@ -23,10 +23,16 @@ interface NamespaceInterface extends WritableInterface
...
@@ -23,10 +23,16 @@ interface NamespaceInterface extends WritableInterface
public
function
getNamespace
(
$namespaceName
);
public
function
getNamespace
(
$namespaceName
);
/**
/**
* @param string $
n
ame
* @param string $
classN
ame
* @return string
* @return string
*/
*/
public
function
getShortName
(
$name
);
public
function
getNodeId
(
$className
);
/**
* @param string $className
* @return string
*/
public
function
getNodeLabel
(
$className
);
/**
/**
* @param NodeInterface $node
* @param NodeInterface $node
...
...
Model/Namespace_/BundleNamespace.php
0 → 100644
View file @
5e787728
<?php
/*
* © 2016 IRSTEA
* Guillaume Perréal <guillaume.perreal@irstea.fr>
* Tous droits réservés.
*/
namespace
Irstea\PlantUmlBundle\Model\Namespace_
;
/**
* Description of BundleNamespace
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
class
BundleNamespace
extends
MappedNamespace
{
const
SEPARATOR
=
'::'
;
public
function
__construct
(
array
$bundles
)
{
$mapping
=
[];
foreach
(
$bundles
as
$bundle
=>
$php
)
{
$mapping
[
substr
(
$php
,
0
,
1
+
strrpos
(
$php
,
'\\'
))]
=
$bundle
.
'::'
;
}
parent
::
__construct
(
$mapping
);
}
}
Model/Namespace_/FlatNamespace.php
View file @
5e787728
...
@@ -18,6 +18,8 @@ use Irstea\PlantUmlBundle\Writer\WriterInterface;
...
@@ -18,6 +18,8 @@ use Irstea\PlantUmlBundle\Writer\WriterInterface;
*/
*/
class
FlatNamespace
extends
AbstractNamespace
class
FlatNamespace
extends
AbstractNamespace
{
{
const
SEPARATOR
=
'none'
;
/**
/**
* @var ArrowInterface[]
* @var ArrowInterface[]
*/
*/
...
@@ -31,7 +33,7 @@ class FlatNamespace extends AbstractNamespace
...
@@ -31,7 +33,7 @@ class FlatNamespace extends AbstractNamespace
public
function
outputTo
(
WriterInterface
$writer
)
public
function
outputTo
(
WriterInterface
$writer
)
{
{
$writer
->
w
ri
te
(
"set namespaceSeparator
none
\n
"
);
$writer
->
p
ri
ntf
(
"set namespaceSeparator
%s
\n
"
,
static
::
SEPARATOR
);
$this
$this
->
outputNodesTo
(
$writer
)
->
outputNodesTo
(
$writer
)
->
outputArrowsTo
(
$writer
);
->
outputArrowsTo
(
$writer
);
...
@@ -51,7 +53,12 @@ class FlatNamespace extends AbstractNamespace
...
@@ -51,7 +53,12 @@ class FlatNamespace extends AbstractNamespace
return
$this
;
return
$this
;
}
}
public
function
getShortName
(
$name
)
public
function
getNodeId
(
$name
)
{
return
str_replace
(
'\\'
,
'_'
,
$name
);
}
public
function
getNodeLabel
(
$name
)
{
{
return
$name
;
return
$name
;
}
}
...
...
Model/Namespace_/MappedNamespace.php
0 → 100644
View file @
5e787728
<?php
/*
* © 2016 IRSTEA
* Guillaume Perréal <guillaume.perreal@irstea.fr>
* Tous droits réservés.
*/
namespace
Irstea\PlantUmlBundle\Model\Namespace_
;
/**
* Description of BundleNamespace
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
class
MappedNamespace
extends
FlatNamespace
{
const
SEPARATOR
=
'::'
;
/**
* @var string[]
*/
private
$mappedNamespaces
=
[];
/**
* @var string[]
*/
private
$phpNamespaces
=
[];
public
function
__construct
(
array
$mapping
)
{
$this
->
phpNamespaces
=
array_keys
(
$mapping
);
$this
->
mappedNamespaces
=
array_values
(
$mapping
);
}
public
function
getNodeId
(
$name
)
{
return
str_replace
(
'\\'
,
'__'
,
str_replace
(
$this
->
phpNamespaces
,
$this
->
mappedNamespaces
,
$name
));
}
public
function
getNodeLabel
(
$name
)
{
return
str_replace
(
$this
->
phpNamespaces
,
''
,
$name
);
}
}
Model/Namespace_/Abstract
Hierachical
Namespace.php
→
Model/Namespace_/
Php/
AbstractNamespace.php
View file @
5e787728
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
* Tous droits réservés.
* Tous droits réservés.
*/
*/
namespace
Irstea\PlantUmlBundle\Model\Namespace_
;
namespace
Irstea\PlantUmlBundle\Model\Namespace_
\Php
;
use
Irstea\PlantUmlBundle\Model\NamespaceInterface
;
use
Irstea\PlantUmlBundle\Model\NamespaceInterface
;
use
Irstea\PlantUmlBundle\Model\NodeInterface
;
use
Irstea\PlantUmlBundle\Model\NodeInterface
;
...
@@ -18,7 +18,7 @@ use Irstea\PlantUmlBundle\Writer\WriterInterface;
...
@@ -18,7 +18,7 @@ use Irstea\PlantUmlBundle\Writer\WriterInterface;
*
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
*/
abstract
class
Abstract
Hierachical
Namespace
extends
AbstractNamespace
abstract
class
AbstractNamespace
extends
AbstractNamespace
{
{
/**
/**
* @var NamespaceInterface
* @var NamespaceInterface
...
@@ -50,7 +50,7 @@ abstract class AbstractHierachicalNamespace extends AbstractNamespace
...
@@ -50,7 +50,7 @@ abstract class AbstractHierachicalNamespace extends AbstractNamespace
*/
*/
abstract
protected
function
getNamespacePrefix
();
abstract
protected
function
getNamespacePrefix
();
public
function
get
ShortName
(
$name
)
public
function
get
NodeLabel
(
$name
)
{
{
$prefix
=
$this
->
getNamespacePrefix
();
$prefix
=
$this
->
getNamespacePrefix
();
if
(
0
===
strpos
(
$name
,
$prefix
))
{
if
(
0
===
strpos
(
$name
,
$prefix
))
{
...
@@ -59,6 +59,11 @@ abstract class AbstractHierachicalNamespace extends AbstractNamespace
...
@@ -59,6 +59,11 @@ abstract class AbstractHierachicalNamespace extends AbstractNamespace
return
$name
;
return
$name
;
}
}
public
function
getNodeId
(
$name
)
{
return
str_replace
(
'\\'
,
'.'
,
$name
)
.
'_node'
;
}
/**
/**
* @param WriterInterface $writer
* @param WriterInterface $writer
* @return self
* @return self
...
...
Model/Namespace_/Namespace_.php
→
Model/Namespace_/
Php/
Namespace_.php
View file @
5e787728
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
* Tous droits réservés.
* Tous droits réservés.
*/
*/
namespace
Irstea\PlantUmlBundle\Model\Namespace_
;
namespace
Irstea\PlantUmlBundle\Model\Namespace_
\Php
;
use
Irstea\PlantUmlBundle\Model\ArrowInterface
;
use
Irstea\PlantUmlBundle\Model\ArrowInterface
;
use
Irstea\PlantUmlBundle\Model\NamespaceInterface
;
use
Irstea\PlantUmlBundle\Model\NamespaceInterface
;
...
...
Model/Namespace_/RootNamespace.php
→
Model/Namespace_/
Php/
RootNamespace.php
View file @
5e787728
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
* Tous droits réservés.
* Tous droits réservés.
*/
*/
namespace
Irstea\PlantUmlBundle\Model\Namespace_
;
namespace
Irstea\PlantUmlBundle\Model\Namespace_
\Php
;
use
Irstea\PlantUmlBundle\Model\ArrowInterface
;
use
Irstea\PlantUmlBundle\Model\ArrowInterface
;
use
Irstea\PlantUmlBundle\Writer\WriterInterface
;
use
Irstea\PlantUmlBundle\Writer\WriterInterface
;
...
@@ -16,7 +16,7 @@ use Irstea\PlantUmlBundle\Writer\WriterInterface;
...
@@ -16,7 +16,7 @@ use Irstea\PlantUmlBundle\Writer\WriterInterface;
*
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
*/
class
RootNamespace
extends
Abstract
Hierachical
Namespace
class
RootNamespace
extends
AbstractNamespace
{
{
/**
/**
* @var ArrowInterface[]
* @var ArrowInterface[]
...
...
Model/Node/BaseNode.php
View file @
5e787728
...
@@ -52,17 +52,16 @@ class BaseNode implements NodeInterface
...
@@ -52,17 +52,16 @@ class BaseNode implements NodeInterface
/**
/**
* @param NamespaceInterface $namespace
* @param NamespaceInterface $namespace
* @param string $id
* @param string $name
* @param string $label
* @param string $nodeType
* @param string $nodeType
* @param array $classifiers
* @param array $classifiers
* @param array $stereotypes
* @param array $stereotypes
*/
*/
function
__construct
(
NamespaceInterface
$namespace
,
$
id
,
$label
,
$nodeType
,
array
$classifiers
=
[],
array
$stereotypes
=
[])
function
__construct
(
NamespaceInterface
$namespace
,
$
name
,
$nodeType
,
array
$classifiers
=
[],
array
$stereotypes
=
[])
{
{
$this
->
namespace
=
$namespace
;
$this
->
namespace
=
$namespace
;
$this
->
id
=
$
id
;
$this
->
id
=
$
namespace
->
getNodeId
(
$name
)
;
$this
->
label
=
$
label
;
$this
->
label
=
$
namespace
->
getNodeLabel
(
$name
)
;
$this
->
nodeType
=
$nodeType
;
$this
->
nodeType
=
$nodeType
;
$this
->
classifiers
=
$classifiers
;
$this
->
classifiers
=
$classifiers
;
...
...
Model/Node/Class_.php
View file @
5e787728
...
@@ -17,7 +17,7 @@ use Irstea\PlantUmlBundle\Model\NamespaceInterface;
...
@@ -17,7 +17,7 @@ use Irstea\PlantUmlBundle\Model\NamespaceInterface;
*/
*/
class
Class_
extends
BaseNode
class
Class_
extends
BaseNode
{
{
public
function
__construct
(
NamespaceInterface
$namespace
,
$
id
,
$label
,
$isAbstract
,
$isFinal
)
public
function
__construct
(
NamespaceInterface
$namespace
,
$
name
,
$isAbstract
,
$isFinal
)
{
{
$classifiers
=
[];
$classifiers
=
[];
if
(
$isAbstract
)
{
if
(
$isAbstract
)
{
...
@@ -25,6 +25,6 @@ class Class_ extends BaseNode
...
@@ -25,6 +25,6 @@ class Class_ extends BaseNode
}
elseif
(
$isFinal
)
{
}
elseif
(
$isFinal
)
{
$classifiers
[]
=
'final'
;
$classifiers
[]
=
'final'
;
}
}
parent
::
__construct
(
$namespace
,
$
id
,
$label
,
"class"
,
$classifiers
,
[]);
parent
::
__construct
(
$namespace
,
$
name
,
"class"
,
$classifiers
,
[]);
}
}
}
}
Model/Node/Interface_.php
View file @
5e787728
...
@@ -17,8 +17,8 @@ use Irstea\PlantUmlBundle\Model\NamespaceInterface;
...
@@ -17,8 +17,8 @@ use Irstea\PlantUmlBundle\Model\NamespaceInterface;
*/
*/
class
Interface_
extends
BaseNode
class
Interface_
extends
BaseNode
{
{
public
function
__construct
(
NamespaceInterface
$namespace
,
$
id
,
$label
)
public
function
__construct
(
NamespaceInterface
$namespace
,
$
name
)
{
{
parent
::
__construct
(
$namespace
,
$
id
,
$label
,
'interface'
,
[],
[]);
parent
::
__construct
(
$namespace
,
$
name
,
'interface'
,
[],
[]);
}
}
}
}
Model/Node/Trait_.php
View file @
5e787728
...
@@ -17,8 +17,8 @@ use Irstea\PlantUmlBundle\Model\NamespaceInterface;
...
@@ -17,8 +17,8 @@ use Irstea\PlantUmlBundle\Model\NamespaceInterface;
*/
*/
class
Trait_
extends
BaseNode
class
Trait_
extends
BaseNode
{
{
public
function
__construct
(
NamespaceInterface
$namespace
,
$
id
,
$label
)
public
function
__construct
(
NamespaceInterface
$namespace
,
$
name
)
{
{
parent
::
__construct
(
$namespace
,
$
id
,
$label
,
'class'
,
[],
[
'trait'
]);
parent
::
__construct
(
$namespace
,
$
name
,
'class'
,
[],
[
'trait'
]);
}
}
}
}
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