Skip to content
Browse files

Added possibility of skipping library namespaces

  • Loading branch information...
1 parent 09e6945 commit 60062c2b2bcd464c0f128120951173dfd8206650 @giorgiosironi committed
View
22 library/UmlReflector/Introspector.php
@@ -4,6 +4,12 @@
class Introspector
{
private $examinedClassNames = array();
+ private $skippedNamespaces = array();
+
+ public function addSkippedNamespace($namespace)
+ {
+ $this->skippedNamespaces[] = $namespace;
+ }
/**
* @param object $rootObject
@@ -15,6 +21,9 @@ public function visualize($rootObject, Directives $directives)
if (in_array($reflectionObject->getName(), $this->examinedClassNames)) {
return;
}
+ if ($this->isInSkippedNamespace($reflectionObject->getName())) {
+ return;
+ }
$this->examinedClassNames[] = $reflectionObject->getName();
$this->classNameToDirectives($directives, $reflectionObject);
$this->propertiesToDirectives($directives, $reflectionObject, $rootObject);
@@ -31,6 +40,19 @@ private function getBasename($fullyQualifiedClassName)
}
}
+ /**
+ * @return bool
+ */
+ private function isInSkippedNamespace($className)
+ {
+ foreach ($this->skippedNamespaces as $namespace) {
+ if (strstr($className, $namespace) == $className) {
+ return true;
+ }
+ }
+ return false;
+ }
+
private function classNameToDirectives(Directives $directives, \ReflectionObject $reflectionObject)
{
$fullyQualifiedClassName = $reflectionObject->getName();
View
13 tests/OtherStubs/LuxuryShop.php
@@ -0,0 +1,13 @@
+<?php
+namespace OtherStubs;
+use Stubs\Product;
+
+class LuxuryShop
+{
+ private $product;
+
+ public function __construct(Product $product)
+ {
+ $this->product = $product;
+ }
+}
View
8 tests/UmlReflector/IntrospectorTest.php
@@ -82,6 +82,14 @@ public function testBaseClassNamesAreJustClassNamesForNonNamespacedClasses()
$this->assertResultIs("[stdClass]");
}
+ public function testCanSkipLibraryNamespaces()
+ {
+ $this->introspector->addSkippedNamespace('Stubs');
+ $shop = new \OtherStubs\LuxuryShop(new Product(new ProductDescription));
+ $this->visualize($shop);
+ $this->assertResultIs("[LuxuryShop]->[Product]");
+ }
+
private function assertResultIs($yumlCode)
{
$this->assertEquals($yumlCode, $this->directives->toString());
View
2 tests/bootstrap.php
@@ -4,3 +4,5 @@
$classLoader->register();
$classLoader = new UmlReflector\SplClassLoader('Stubs', __DIR__);
$classLoader->register();
+$classLoader = new UmlReflector\SplClassLoader('OtherStubs', __DIR__);
+$classLoader->register();

0 comments on commit 60062c2

Please sign in to comment.
Something went wrong with that request. Please try again.