Skip to content

Commit

Permalink
filter config for classes
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalkaoz committed Jun 12, 2014
1 parent 811ee0e commit 0632f1e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -31,7 +31,7 @@ Usage
### the `classes` command generates a class diagram from all classes in the given folder

Usage:
classes [--console] [--debug] [--properties] [--methods] folder
classes [--console] [--debug] [--properties] [--methods] [--filter] folder

Arguments:
folder the folder to scan for classes
Expand All @@ -41,6 +41,7 @@ Usage
--debug debug
--properties build with properties
--methods build with methods
--filter to include/exclude files/folder


```sh
Expand Down
10 changes: 9 additions & 1 deletion composer.json
Expand Up @@ -18,7 +18,7 @@
"pimple/pimple": "@stable",
"symfony/console": "@stable",
"kriswallsmith/buzz": "@stable",
"andrewsville/php-token-reflection": "@stable"
"andrewsville/php-token-reflection": "dev-develop@dev"
},

"require-dev" : {
Expand All @@ -37,5 +37,13 @@
}
},

"repositories" : [
{
"type" : "vcs",
"url" : "https://github.com/digitalkaoz/PHP-Token-Reflection"
}
],


"bin": ["bin/yuml-php"]
}
2 changes: 2 additions & 0 deletions src/YumlPhp/Command/ClassesCommand.php
Expand Up @@ -31,6 +31,7 @@ protected function configure()

$this->getDefinition()->addOption(new InputOption('properties', null, InputOption::VALUE_NONE, 'build with properties'));
$this->getDefinition()->addOption(new InputOption('methods', null, InputOption::VALUE_NONE, 'build with methods'));
$this->getDefinition()->addOption(new InputOption('filter', null, InputOption::VALUE_IS_ARRAY|InputOption::VALUE_REQUIRED, 'glob pattern filter'));

$this
->setName('classes')
Expand Down Expand Up @@ -60,6 +61,7 @@ protected function getBuilderConfig(BuilderInterface $builder, InputInterface $i
'withMethods' => $input->getOption('methods'),
'withProperties' => $input->getOption('properties'),
'style' => $style,
'filter' => $input->getOption('filter'),
'autoload_path' => $input->getArgument('source')
);
}
Expand Down
19 changes: 14 additions & 5 deletions src/YumlPhp/Request/ClassesRequest.php
Expand Up @@ -14,6 +14,7 @@
use TokenReflection\Broker;
use TokenReflection\IReflectionClass;
use TokenReflection\IReflectionMethod;
use TokenReflection\IReflectionProperty;

/**
* The console application that handles the commands
Expand All @@ -22,7 +23,14 @@
*/
abstract class ClassesRequest implements RequestInterface
{
private $config = array(), $path;
private $config = array(
'filter' => array(),
'withProperties' => false,
'withMethods' => false,
'debug' => false
);

private $path;

/**
* @inheritDoc
Expand All @@ -39,7 +47,7 @@ public function setPath($path)
*/
public function configure(array $config)
{
$this->config = $config;
$this->config = array_merge($this->config, $config);

return $this;
}
Expand All @@ -52,7 +60,7 @@ public function configure(array $config)
protected function getClasses()
{
$broker = new Broker(new Broker\Backend\Memory());
$broker->processDirectory(realpath($this->path));
$broker->processDirectory(realpath($this->path), $this->config['filter']);
$classes = $broker->getClasses();

sort($classes);
Expand Down Expand Up @@ -120,11 +128,12 @@ protected function buildProperties(IReflectionClass $class, $public = '+', $priv
{
$props = array();

if (!isset($this->config['withProperties']) || !$this->config['withProperties'] || $class->isInterface()) {
if (!$this->config['withProperties'] || $class->isInterface()) {
return $props;
}

foreach ($class->getProperties() as $property) {
/** @var IReflectionProperty $property */
if ($property->getDeclaringClass() == $class) {
$props[] = ($property->isPublic() ? $public : $private) . $property->getName();
}
Expand All @@ -148,7 +157,7 @@ protected function buildMethods(IReflectionClass $class, $public = '+', $private
{
$methods = array();

if (!isset($this->config['withMethods']) || !$this->config['withMethods']) {
if (!$this->config['withMethods']) {
return $methods;
}

Expand Down

0 comments on commit 0632f1e

Please sign in to comment.