diff --git a/docs/MdGen/__CLASS__.md b/docs/MdGen/__CLASS__.md new file mode 100644 index 0000000..c9c19e4 --- /dev/null +++ b/docs/MdGen/__CLASS__.md @@ -0,0 +1,25 @@ +# **Class** MdGen + +Full name : `alphayax\mdGen\MdGen` + +## Properties + +- `srcDirectory` +- `loadedClasses` +- `chapters` +- `rootPage` + +## Constants + +- `DEFAULT_SRC_DIRECTORY = ''` + +## Methods summary + +| Method | Description | +|---|---| +| [`__construct`](__construct.md) | MdGen constructor. | +| [`loadClasses`](loadClasses.md) | Load class in the source directory | +| [`filterNamespace`](filterNamespace.md) | Filter class who are in a specific namespace | +| [`filterSubClasses`](filterSubClasses.md) | Filter class who are sub-classes of a specific class | +| [`generateClassMdFromLoadedClasses`](generateClassMdFromLoadedClasses.md) | Create a chapter form loaded classes | +| [`generate`](generate.md) | Generate markdown files | diff --git a/docs/MdGen/__construct.md b/docs/MdGen/__construct.md new file mode 100644 index 0000000..c4d3590 --- /dev/null +++ b/docs/MdGen/__construct.md @@ -0,0 +1,37 @@ +**Namespace** : [alphayax\mdGen](../__NAMESPACE__.md) - +**Class** : [MdGen](__CLASS__.md) + +## `MdGen::__construct` + +#### Description + +> MdGen constructor. + +#### Signature + +```php + public function __construct($srcDirectory, $rootNamespace); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$srcDirectory` | unknown | | +| `$rootNamespace` | unknown | | + +#### Return + +> No Return + +#### Implementation + +```php + public function __construct( $srcDirectory = self::DEFAULT_SRC_DIRECTORY, $rootNamespace){ + $this->rootNamespace = $rootNamespace; + $this->srcDirectory = $srcDirectory; + $this->loadClasses(); + $this->filterNamespace( $rootNamespace); + } + +``` diff --git a/docs/MdGen/filterNamespace.md b/docs/MdGen/filterNamespace.md new file mode 100644 index 0000000..a1ef5dd --- /dev/null +++ b/docs/MdGen/filterNamespace.md @@ -0,0 +1,39 @@ +**Namespace** : [alphayax\mdGen](../__NAMESPACE__.md) - +**Class** : [MdGen](__CLASS__.md) + +## `MdGen::filterNamespace` + +#### Description + +> Filter class who are in a specific namespace + +#### Signature + +```php + public function filterNamespace($namespaceName); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$namespaceName` | string | Namespace Name to filter | + +#### Return + +> No Return + +#### Implementation + +```php + public function filterNamespace( $namespaceName) { + $FilteredClasses = []; + foreach( $this->loadedClasses as $loadedClass){ + if( 0 == substr_compare( $loadedClass, $namespaceName, 0, strlen( $namespaceName))){ + $FilteredClasses[] = $loadedClass; + } + } + $this->loadedClasses = $FilteredClasses; + } + +``` diff --git a/docs/MdGen/filterSubClasses.md b/docs/MdGen/filterSubClasses.md new file mode 100644 index 0000000..117411e --- /dev/null +++ b/docs/MdGen/filterSubClasses.md @@ -0,0 +1,39 @@ +**Namespace** : [alphayax\mdGen](../__NAMESPACE__.md) - +**Class** : [MdGen](__CLASS__.md) + +## `MdGen::filterSubClasses` + +#### Description + +> Filter class who are sub-classes of a specific class + +#### Signature + +```php + public function filterSubClasses($className); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$className` | string | Super class name to filter | + +#### Return + +> No Return + +#### Implementation + +```php + public function filterSubClasses( $className) { + $FilteredClasses = []; + foreach( $this->loadedClasses as $loadedClass){ + if( is_subclass_of( $loadedClass, $className)){ + $FilteredClasses[] = $loadedClass; + } + } + $this->loadedClasses = $FilteredClasses; + } + +``` diff --git a/docs/MdGen/generate.md b/docs/MdGen/generate.md new file mode 100644 index 0000000..5ef2afb --- /dev/null +++ b/docs/MdGen/generate.md @@ -0,0 +1,36 @@ +**Namespace** : [alphayax\mdGen](../__NAMESPACE__.md) - +**Class** : [MdGen](__CLASS__.md) + +## `MdGen::generate` + +#### Description + +> Generate markdown files + +#### Signature + +```php + public function generate($directory); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$directory` | string | Path to generated files | + +#### Return + +> No Return + +#### Implementation + +```php + public function generate( $directory = '.'){ + $chapters = $this->generateClassMdFromLoadedClasses(); + $this->rootPage = new models\NamespaceMd( $this->rootNamespace, $chapters); + $this->rootPage->setDirectory( $directory); + $this->rootPage->write(); + } + +``` diff --git a/docs/MdGen/generateClassMdFromLoadedClasses.md b/docs/MdGen/generateClassMdFromLoadedClasses.md new file mode 100644 index 0000000..aa029a7 --- /dev/null +++ b/docs/MdGen/generateClassMdFromLoadedClasses.md @@ -0,0 +1,35 @@ +**Namespace** : [alphayax\mdGen](../__NAMESPACE__.md) - +**Class** : [MdGen](__CLASS__.md) + +## `MdGen::generateClassMdFromLoadedClasses` + +#### Description + +> Create a chapter form loaded classes + +#### Signature + +```php + protected function generateClassMdFromLoadedClasses(); +``` + +#### Parameters + +> No parameters + +#### Return + + ClassMd[] + +#### Implementation + +```php + protected function generateClassMdFromLoadedClasses(){ + $classMds = []; + foreach( $this->loadedClasses as $class){ + $classMds[] = new ClassMd( $class); + } + return $classMds; + } + +``` diff --git a/docs/MdGen/loadClasses.md b/docs/MdGen/loadClasses.md new file mode 100644 index 0000000..a6d88b6 --- /dev/null +++ b/docs/MdGen/loadClasses.md @@ -0,0 +1,48 @@ +**Namespace** : [alphayax\mdGen](../__NAMESPACE__.md) - +**Class** : [MdGen](__CLASS__.md) + +## `MdGen::loadClasses` + +#### Description + +> Load class in the source directory + +#### Signature + +```php + protected function loadClasses(); +``` + +#### Parameters + +> No parameters + +#### Return + +> No Return + +#### Implementation + +```php + protected function loadClasses(){ + if( ! is_dir( $this->srcDirectory)){ + throw new \Exception( 'Source directory not found : '. $this->srcDirectory); + } + + /// Recursively scan PHP Files + $objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator( $this->srcDirectory), \RecursiveIteratorIterator::SELF_FIRST); + $Regex = new \RegexIterator( $objects, '/^.+\.php$/i', \RecursiveRegexIterator::GET_MATCH); + foreach( $Regex as $name => $object){ + if ( ! empty( $name)) { + require_once $name; + } + } + + /// Extract data from loaded classes + $classes = get_declared_classes(); + $traits = get_declared_traits(); + $interfaces = get_declared_interfaces(); + $this->loadedClasses = array_merge( $classes, $traits, $interfaces); + } + +``` diff --git a/docs/__NAMESPACE__.md b/docs/__NAMESPACE__.md index b1c6f01..5cf1815 100644 --- a/docs/__NAMESPACE__.md +++ b/docs/__NAMESPACE__.md @@ -1,30 +1,15 @@ +# Namespace mdGen -# mdGen - -**Namespace** : alphayax\mdGen +**Full name** : `alphayax\mdGen` # Overview - [models](./models/__NAMESPACE__.md) - - [NamespaceMd](models/__NAMESPACE__.md#NamespaceMd) - - [ClassMd](models/__NAMESPACE__.md#ClassMd) - - [MethodMd](models/__NAMESPACE__.md#MethodMd) + - [NamespaceMd](models/NamespaceMd/__CLASS__.md) + - [ClassMd](models/ClassMd/__CLASS__.md) + - [MethodMd](models/MethodMd/__CLASS__.md) + - [ParamMd](models/ParamMd/__CLASS__.md) - [utils](./utils/__NAMESPACE__.md) - - [arrayAccessProperties](utils/__NAMESPACE__.md#arrayAccessProperties) -- [MdGen](__NAMESPACE__.md#MdGen) - - ---- - -## MdGen - -**Class** : alphayax\mdGen\MdGen - -### Public methods - -| Method | Description | -|---|---| -| `filterNamespace` | Filter class who are in a specific namespace | -| `filterSubClasses` | Filter class who are sub-classes of a specific class | -| `generate` | Generate markdown files | + - [arrayAccessProperties](utils/arrayAccessProperties/__CLASS__.md) +- [MdGen](MdGen/__CLASS__.md) diff --git a/docs/models/ClassMd/__CLASS__.md b/docs/models/ClassMd/__CLASS__.md new file mode 100644 index 0000000..8c4506e --- /dev/null +++ b/docs/models/ClassMd/__CLASS__.md @@ -0,0 +1,33 @@ +# **Class** ClassMd + +Full name : `alphayax\mdGen\models\ClassMd` + +## Properties + +- `class` +- `reflexion` +- `publicMethods` +- `methods` +- `type` +- `properties` +- `constants` + +## Constants + +> No constants + +## Methods summary + +| Method | Description | +|---|---| +| [`__construct`](__construct.md) | ClassChapter constructor. | +| [`computeType`](computeType.md) | Determine the type of class | +| [`getNextComponent`](getNextComponent.md) | Get the next namespace component (according the NS given) | +| [`getNamespace`](getNamespace.md) | Get the namespace of the current reflected class | +| [`getReflexion`](getReflexion.md) | Get the reflected class | +| [`write`](write.md) | | +| [`writeMethods`](writeMethods.md) | | +| [`offsetExists`](offsetExists.md) | Whether a offset exists | +| [`offsetGet`](offsetGet.md) | Offset to retrieve | +| [`offsetSet`](offsetSet.md) | Offset to set | +| [`offsetUnset`](offsetUnset.md) | Offset to unset | diff --git a/docs/models/ClassMd/__construct.md b/docs/models/ClassMd/__construct.md new file mode 100644 index 0000000..405537a --- /dev/null +++ b/docs/models/ClassMd/__construct.md @@ -0,0 +1,69 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [ClassMd](__CLASS__.md) + +## `ClassMd::__construct` + +#### Description + +> ClassChapter constructor. + +#### Signature + +```php + public function __construct($class); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$class` | string | | + +#### Return + +> No Return + +#### Implementation + +```php + public function __construct( $class){ + $this->class = $class; + $this->reflexion = new \ReflectionClass( $class); + $this->computeType(); + + /// Properties + $properties = $this->reflexion->getProperties(); + foreach ($properties as $property){ + $this->properties[] = $property->getName(); + } + + /// Methods + $methods = $this->reflexion->getMethods(); + foreach ( $methods as $method){ + + $methodMd = new MethodMd( $this->reflexion->getName(), $method->getName()); + $this->methods[] = $methodMd; + + /// Filter only public and non constructor methods + if( ! $method->isPublic() || $method->isConstructor()){ + continue; + } + + /// Filter only methods inside class (not derived) + if( $method->getDeclaringClass()->getName() != $this->reflexion->getName()){ + continue; + } + + $this->publicMethods[] = $methodMd; + } + + /// Constants + foreach ( $this->reflexion->getConstants() as $constantName => $constantValue){ + $this->constants[] = [ + 'name' => $constantName, + 'value' => $constantValue, + ]; + } + } + +``` diff --git a/docs/models/ClassMd/computeType.md b/docs/models/ClassMd/computeType.md new file mode 100644 index 0000000..657af49 --- /dev/null +++ b/docs/models/ClassMd/computeType.md @@ -0,0 +1,39 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [ClassMd](__CLASS__.md) + +## `ClassMd::computeType` + +#### Description + +> Determine the type of class + +#### Signature + +```php + protected function computeType(); +``` + +#### Parameters + +> No parameters + +#### Return + +> No Return + +#### Implementation + +```php + protected function computeType(){ + if( interface_exists( $this->class, false)){ + $this->type = 'Interface'; + return; + } + if( trait_exists( $this->class, false)){ + $this->type = 'Trait'; + return; + } + $this->type = 'Class'; + } + +``` diff --git a/docs/models/ClassMd/getNamespace.md b/docs/models/ClassMd/getNamespace.md new file mode 100644 index 0000000..1beeccf --- /dev/null +++ b/docs/models/ClassMd/getNamespace.md @@ -0,0 +1,31 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [ClassMd](__CLASS__.md) + +## `ClassMd::getNamespace` + +#### Description + +> Get the namespace of the current reflected class + +#### Signature + +```php + public function getNamespace(); +``` + +#### Parameters + +> No parameters + +#### Return + +> No Return + +#### Implementation + +```php + public function getNamespace() { + return $this->reflexion->getNamespaceName(); + } + +``` diff --git a/docs/models/ClassMd/getNextComponent.md b/docs/models/ClassMd/getNextComponent.md new file mode 100644 index 0000000..750294c --- /dev/null +++ b/docs/models/ClassMd/getNextComponent.md @@ -0,0 +1,40 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [ClassMd](__CLASS__.md) + +## `ClassMd::getNextComponent` + +#### Description + +> Get the next namespace component (according the NS given) + +#### Signature + +```php + public function getNextComponent($namespace); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$namespace` | string | | + +#### Return + + string + +#### Implementation + +```php + public function getNextComponent( $namespace) { + $namespaceComponents = explode( '\\', $namespace); + $class_x = explode( '\\', $this->class); + + while( array_shift( $namespaceComponents)){ + array_shift( $class_x); + } + + return array_shift( $class_x); + } + +``` diff --git a/docs/models/ClassMd/getReflexion.md b/docs/models/ClassMd/getReflexion.md new file mode 100644 index 0000000..7286b28 --- /dev/null +++ b/docs/models/ClassMd/getReflexion.md @@ -0,0 +1,31 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [ClassMd](__CLASS__.md) + +## `ClassMd::getReflexion` + +#### Description + +> Get the reflected class + +#### Signature + +```php + public function getReflexion(); +``` + +#### Parameters + +> No parameters + +#### Return + + \ReflectionClass + +#### Implementation + +```php + public function getReflexion(){ + return $this->reflexion; + } + +``` diff --git a/docs/models/ClassMd/offsetExists.md b/docs/models/ClassMd/offsetExists.md new file mode 100644 index 0000000..c9e39b6 --- /dev/null +++ b/docs/models/ClassMd/offsetExists.md @@ -0,0 +1,33 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [ClassMd](__CLASS__.md) + +## `ClassMd::offsetExists` + +#### Description + +> Whether a offset exists + +#### Signature + +```php + public function offsetExists($offset); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$offset` | mixed | <p> An offset to check for. </p> | + +#### Return + + boolean true on success or false on failure. + +#### Implementation + +```php + public function offsetExists($offset) { + return property_exists( static::class, $offset); + } + +``` diff --git a/docs/models/ClassMd/offsetGet.md b/docs/models/ClassMd/offsetGet.md new file mode 100644 index 0000000..d0f5d51 --- /dev/null +++ b/docs/models/ClassMd/offsetGet.md @@ -0,0 +1,33 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [ClassMd](__CLASS__.md) + +## `ClassMd::offsetGet` + +#### Description + +> Offset to retrieve + +#### Signature + +```php + public function offsetGet($offset); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$offset` | mixed | <p> The offset to retrieve. </p> | + +#### Return + + mixed Can return all value types. + +#### Implementation + +```php + public function offsetGet( $offset) { + return $this->$offset; + } + +``` diff --git a/docs/models/ClassMd/offsetSet.md b/docs/models/ClassMd/offsetSet.md new file mode 100644 index 0000000..6543982 --- /dev/null +++ b/docs/models/ClassMd/offsetSet.md @@ -0,0 +1,34 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [ClassMd](__CLASS__.md) + +## `ClassMd::offsetSet` + +#### Description + +> Offset to set + +#### Signature + +```php + public function offsetSet($offset, $value); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$offset` | mixed | <p> The offset to assign the value to. </p> | +| `$value` | mixed | <p> The value to set. </p> | + +#### Return + + void + +#### Implementation + +```php + public function offsetSet( $offset, $value) { + $this->$offset = $value; + } + +``` diff --git a/docs/models/ClassMd/offsetUnset.md b/docs/models/ClassMd/offsetUnset.md new file mode 100644 index 0000000..bb10e2c --- /dev/null +++ b/docs/models/ClassMd/offsetUnset.md @@ -0,0 +1,33 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [ClassMd](__CLASS__.md) + +## `ClassMd::offsetUnset` + +#### Description + +> Offset to unset + +#### Signature + +```php + public function offsetUnset($offset); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$offset` | mixed | <p> The offset to unset. </p> | + +#### Return + + void + +#### Implementation + +```php + public function offsetUnset($offset) { + $this->$offset = null; + } + +``` diff --git a/docs/models/ClassMd/write.md b/docs/models/ClassMd/write.md new file mode 100644 index 0000000..361a257 --- /dev/null +++ b/docs/models/ClassMd/write.md @@ -0,0 +1,28 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [ClassMd](__CLASS__.md) + +## `ClassMd::write` + +#### Description + +> + +#### Signature + +```php + public function write(); +``` + +#### Parameters + +> No parameters + +#### Return + +> No Return + +#### Implementation + +```php + +``` diff --git a/docs/models/ClassMd/writeMethods.md b/docs/models/ClassMd/writeMethods.md new file mode 100644 index 0000000..98eddce --- /dev/null +++ b/docs/models/ClassMd/writeMethods.md @@ -0,0 +1,28 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [ClassMd](__CLASS__.md) + +## `ClassMd::writeMethods` + +#### Description + +> + +#### Signature + +```php + private function writeMethods(); +``` + +#### Parameters + +> No parameters + +#### Return + +> No Return + +#### Implementation + +```php + +``` diff --git a/docs/models/MethodMd/__CLASS__.md b/docs/models/MethodMd/__CLASS__.md new file mode 100644 index 0000000..0ec6be6 --- /dev/null +++ b/docs/models/MethodMd/__CLASS__.md @@ -0,0 +1,31 @@ +# **Class** MethodMd + +Full name : `alphayax\mdGen\models\MethodMd` + +## Properties + +- `reflexion` +- `name` +- `description` +- `params` +- `return` +- `impl` + +## Constants + +> No constants + +## Methods summary + +| Method | Description | +|---|---| +| [`__construct`](__construct.md) | MethodMd constructor. | +| [`extractImplementation`](extractImplementation.md) | | +| [`hasParams`](hasParams.md) | | +| [`getParams`](getParams.md) | | +| [`getModifiers`](getModifiers.md) | | +| [`write`](write.md) | | +| [`offsetExists`](offsetExists.md) | Whether a offset exists | +| [`offsetGet`](offsetGet.md) | Offset to retrieve | +| [`offsetSet`](offsetSet.md) | Offset to set | +| [`offsetUnset`](offsetUnset.md) | Offset to unset | diff --git a/docs/models/MethodMd/__construct.md b/docs/models/MethodMd/__construct.md new file mode 100644 index 0000000..88ddbba --- /dev/null +++ b/docs/models/MethodMd/__construct.md @@ -0,0 +1,63 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [MethodMd](__CLASS__.md) + +## `MethodMd::__construct` + +#### Description + +> MethodMd constructor. + +#### Signature + +```php + public function __construct($className, $methodName); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$className` | unknown | | +| `$methodName` | unknown | | + +#### Return + +> No Return + +#### Implementation + +```php + public function __construct( $className, $methodName) { + + try { + + $this->reflexion = new \Zend_Reflection_Method( $className, $methodName); + + $this->name = $this->reflexion->getName(); + $docBlock = $this->reflexion->getDocblock(); + + $this->extractImplementation(); + + /// Desc + $shortDesc = str_replace(PHP_EOL, ' ', $docBlock->getShortDescription()); + $this->description = str_replace(PHP_EOL, ' ', $shortDesc); + + /// Params + /** @var \Zend_Reflection_Docblock_Tag_Param[] $params */ + $params = $docBlock->getTags( 'param'); + foreach ( $params as $param){ + $this->params[] = new ParamMd( $param); + } + + /** @var \Zend_Reflection_Docblock_Tag_Return $return */ + $return = $docBlock->getTag( 'return'); + if( $return){ + $this->return = $return->getType() . ' ' . $return->getDescription(); + } + } + catch( \Exception $e) { + // Unable to parse PHPDoc Block... Skip it :( + } + } + +``` diff --git a/docs/models/MethodMd/getModifiers.md b/docs/models/MethodMd/getModifiers.md new file mode 100644 index 0000000..a928063 --- /dev/null +++ b/docs/models/MethodMd/getModifiers.md @@ -0,0 +1,38 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [MethodMd](__CLASS__.md) + +## `MethodMd::getModifiers` + +#### Description + +> + +#### Signature + +```php + public function getModifiers(); +``` + +#### Parameters + +> No parameters + +#### Return + + string + +#### Implementation + +```php + public function getModifiers() { + return + ($this->reflexion->isFinal() ? ' final' : ''). + ($this->reflexion->isAbstract() ? ' abstract' : ''). + ($this->reflexion->isPublic() ? ' public' : ''). + ($this->reflexion->isProtected() ? ' protected' : ''). + ($this->reflexion->isPrivate() ? ' private' : ''). + ($this->reflexion->isStatic() ? ' static' : ''); + + } + +``` diff --git a/docs/models/MethodMd/getParams.md b/docs/models/MethodMd/getParams.md new file mode 100644 index 0000000..1a713be --- /dev/null +++ b/docs/models/MethodMd/getParams.md @@ -0,0 +1,35 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [MethodMd](__CLASS__.md) + +## `MethodMd::getParams` + +#### Description + +> + +#### Signature + +```php + public function getParams(); +``` + +#### Parameters + +> No parameters + +#### Return + + string + +#### Implementation + +```php + public function getParams(){ + $variablesNames = []; + foreach( $this->params as $param){ + $variablesNames[] = $param['variableName']; + } + return implode(', ', $variablesNames); + } + +``` diff --git a/docs/models/MethodMd/hasParams.md b/docs/models/MethodMd/hasParams.md new file mode 100644 index 0000000..e3c7656 --- /dev/null +++ b/docs/models/MethodMd/hasParams.md @@ -0,0 +1,31 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [MethodMd](__CLASS__.md) + +## `MethodMd::hasParams` + +#### Description + +> + +#### Signature + +```php + public function hasParams(); +``` + +#### Parameters + +> No parameters + +#### Return + + bool + +#### Implementation + +```php + public function hasParams() { + return ! empty( $this->params); + } + +``` diff --git a/docs/models/MethodMd/offsetExists.md b/docs/models/MethodMd/offsetExists.md new file mode 100644 index 0000000..7fa8682 --- /dev/null +++ b/docs/models/MethodMd/offsetExists.md @@ -0,0 +1,33 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [MethodMd](__CLASS__.md) + +## `MethodMd::offsetExists` + +#### Description + +> Whether a offset exists + +#### Signature + +```php + public function offsetExists($offset); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$offset` | mixed | <p> An offset to check for. </p> | + +#### Return + + boolean true on success or false on failure. + +#### Implementation + +```php + public function offsetExists($offset) { + return property_exists( static::class, $offset); + } + +``` diff --git a/docs/models/MethodMd/offsetGet.md b/docs/models/MethodMd/offsetGet.md new file mode 100644 index 0000000..fcf45c9 --- /dev/null +++ b/docs/models/MethodMd/offsetGet.md @@ -0,0 +1,33 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [MethodMd](__CLASS__.md) + +## `MethodMd::offsetGet` + +#### Description + +> Offset to retrieve + +#### Signature + +```php + public function offsetGet($offset); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$offset` | mixed | <p> The offset to retrieve. </p> | + +#### Return + + mixed Can return all value types. + +#### Implementation + +```php + public function offsetGet( $offset) { + return $this->$offset; + } + +``` diff --git a/docs/models/MethodMd/offsetSet.md b/docs/models/MethodMd/offsetSet.md new file mode 100644 index 0000000..4251cdb --- /dev/null +++ b/docs/models/MethodMd/offsetSet.md @@ -0,0 +1,34 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [MethodMd](__CLASS__.md) + +## `MethodMd::offsetSet` + +#### Description + +> Offset to set + +#### Signature + +```php + public function offsetSet($offset, $value); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$offset` | mixed | <p> The offset to assign the value to. </p> | +| `$value` | mixed | <p> The value to set. </p> | + +#### Return + + void + +#### Implementation + +```php + public function offsetSet( $offset, $value) { + $this->$offset = $value; + } + +``` diff --git a/docs/models/MethodMd/offsetUnset.md b/docs/models/MethodMd/offsetUnset.md new file mode 100644 index 0000000..f6e48c0 --- /dev/null +++ b/docs/models/MethodMd/offsetUnset.md @@ -0,0 +1,33 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [MethodMd](__CLASS__.md) + +## `MethodMd::offsetUnset` + +#### Description + +> Offset to unset + +#### Signature + +```php + public function offsetUnset($offset); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$offset` | mixed | <p> The offset to unset. </p> | + +#### Return + + void + +#### Implementation + +```php + public function offsetUnset($offset) { + $this->$offset = null; + } + +``` diff --git a/docs/models/MethodMd/write.md b/docs/models/MethodMd/write.md new file mode 100644 index 0000000..e7dd622 --- /dev/null +++ b/docs/models/MethodMd/write.md @@ -0,0 +1,40 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [MethodMd](__CLASS__.md) + +## `MethodMd::write` + +#### Description + +> + +#### Signature + +```php + public function write($path); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$path` | unknown | | + +#### Return + +> No Return + +#### Implementation + +```php + public function write( $path) { + $m = new \Mustache_Engine([ + 'loader' => new \Mustache_Loader_FilesystemLoader( __DIR__.'/../views'), + 'partials_loader' => new \Mustache_Loader_FilesystemLoader(__DIR__ . '/../views/MethodMd'), + + ]); + + $generatedMd = $m->loadTemplate('Method')->render( $this); + file_put_contents( $path . DIRECTORY_SEPARATOR . $this->name . '.md', $generatedMd); + } + +``` diff --git a/docs/models/NamespaceMd/__CLASS__.md b/docs/models/NamespaceMd/__CLASS__.md new file mode 100644 index 0000000..382ffdf --- /dev/null +++ b/docs/models/NamespaceMd/__CLASS__.md @@ -0,0 +1,33 @@ +# **Class** NamespaceMd + +Full name : `alphayax\mdGen\models\NamespaceMd` + +## Properties + +- `classMds` +- `subPages` +- `namespace` +- `page_bfe` +- `page_rd` +- `pageName` + +## Constants + +> No constants + +## Methods summary + +| Method | Description | +|---|---| +| [`__construct`](__construct.md) | Page constructor | +| [`computePageName`](computePageName.md) | Compute the page name (according to the page namespace) | +| [`generateTree`](generateTree.md) | Generate overview markdown tree | +| [`write`](write.md) | Write markdown file | +| [`writeMdClasses`](writeMdClasses.md) | | +| [`writeSubPages`](writeSubPages.md) | Write sub pages of this page | +| [`setDirectory`](setDirectory.md) | Define the current page directory | +| [`getPageBfe`](getPageBfe.md) | Return the page basename file with extension | +| [`offsetExists`](offsetExists.md) | Whether a offset exists | +| [`offsetGet`](offsetGet.md) | Offset to retrieve | +| [`offsetSet`](offsetSet.md) | Offset to set | +| [`offsetUnset`](offsetUnset.md) | Offset to unset | diff --git a/docs/models/NamespaceMd/__construct.md b/docs/models/NamespaceMd/__construct.md new file mode 100644 index 0000000..39bcecb --- /dev/null +++ b/docs/models/NamespaceMd/__construct.md @@ -0,0 +1,53 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [NamespaceMd](__CLASS__.md) + +## `NamespaceMd::__construct` + +#### Description + +> Page constructor + +#### Signature + +```php + public function __construct($pageNamespace, $chapters); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$pageNamespace` | string | | +| `$chapters` | ClassMd[] | | + +#### Return + +> No Return + +#### Implementation + +```php + public function __construct( $pageNamespace, array $chapters) { + $this->namespace = $pageNamespace; + $this->pageName = $this->computePageName(); + $this->page_bfe = '__NAMESPACE__.md'; + + $pagesBtComponents = []; + foreach( $chapters as $chapter){ + + if( $chapter->getNamespace() == $pageNamespace){ + $this->classMds[] = $chapter; + continue; + } + + $component = $chapter->getNextComponent( $pageNamespace); + $pagesBtComponents[ $component][] = $chapter; + } + + $subPages = array_keys( $pagesBtComponents); + foreach( $subPages as $subPage){ + $this->subPages[$subPage] = new NamespaceMd( $pageNamespace . '\\'. $subPage, $pagesBtComponents[$subPage]); + } + } + +``` diff --git a/docs/models/NamespaceMd/computePageName.md b/docs/models/NamespaceMd/computePageName.md new file mode 100644 index 0000000..2636d45 --- /dev/null +++ b/docs/models/NamespaceMd/computePageName.md @@ -0,0 +1,32 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [NamespaceMd](__CLASS__.md) + +## `NamespaceMd::computePageName` + +#### Description + +> Compute the page name (according to the page namespace) + +#### Signature + +```php + protected function computePageName(); +``` + +#### Parameters + +> No parameters + +#### Return + + string + +#### Implementation + +```php + protected function computePageName(){ + $namespaceComponents = explode( '\\', $this->namespace); + return array_pop( $namespaceComponents); + } + +``` diff --git a/docs/models/NamespaceMd/generateTree.md b/docs/models/NamespaceMd/generateTree.md new file mode 100644 index 0000000..13906d6 --- /dev/null +++ b/docs/models/NamespaceMd/generateTree.md @@ -0,0 +1,54 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [NamespaceMd](__CLASS__.md) + +## `NamespaceMd::generateTree` + +#### Description + +> Generate overview markdown tree + +#### Signature + +```php + public function generateTree($pad, $relativePath); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$pad` | string | | +| `$relativePath` | string | | + +#### Return + + string + +#### Implementation + +```php + public function generateTree( $pad = '', $relativePath = '') { + $generatedMd = ''; + + /// SubNamespaces + if( ! empty( $this->subPages)){ + foreach( $this->subPages as $subPageName => $subPage){ + $subPageFile = './' . $relativePath . $subPageName . DIRECTORY_SEPARATOR . $subPage->getPageBfe(); + $generatedMd .= "$pad- [$subPageName]($subPageFile)". PHP_EOL; + $generatedMd .= $subPage->generateTree( $pad . ' ', $relativePath . $subPageName . DIRECTORY_SEPARATOR); + } + } + + /// Classes + if( ! empty( $this->classMds)){ + foreach($this->classMds as $classMd){ + $className = $classMd->getReflexion()->getShortName(); + $classFile = $relativePath . $className . DIRECTORY_SEPARATOR . '__CLASS__.md'; + $generatedMd .= "$pad- [$className]($classFile)" . PHP_EOL; + } + } + + return $generatedMd; + } + +``` diff --git a/docs/models/NamespaceMd/getPageBfe.md b/docs/models/NamespaceMd/getPageBfe.md new file mode 100644 index 0000000..407758f --- /dev/null +++ b/docs/models/NamespaceMd/getPageBfe.md @@ -0,0 +1,31 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [NamespaceMd](__CLASS__.md) + +## `NamespaceMd::getPageBfe` + +#### Description + +> Return the page basename file with extension + +#### Signature + +```php + public function getPageBfe(); +``` + +#### Parameters + +> No parameters + +#### Return + + string The page base name + +#### Implementation + +```php + public function getPageBfe() { + return $this->page_bfe; + } + +``` diff --git a/docs/models/NamespaceMd/offsetExists.md b/docs/models/NamespaceMd/offsetExists.md new file mode 100644 index 0000000..a2af2a5 --- /dev/null +++ b/docs/models/NamespaceMd/offsetExists.md @@ -0,0 +1,33 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [NamespaceMd](__CLASS__.md) + +## `NamespaceMd::offsetExists` + +#### Description + +> Whether a offset exists + +#### Signature + +```php + public function offsetExists($offset); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$offset` | mixed | <p> An offset to check for. </p> | + +#### Return + + boolean true on success or false on failure. + +#### Implementation + +```php + public function offsetExists($offset) { + return property_exists( static::class, $offset); + } + +``` diff --git a/docs/models/NamespaceMd/offsetGet.md b/docs/models/NamespaceMd/offsetGet.md new file mode 100644 index 0000000..d497762 --- /dev/null +++ b/docs/models/NamespaceMd/offsetGet.md @@ -0,0 +1,33 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [NamespaceMd](__CLASS__.md) + +## `NamespaceMd::offsetGet` + +#### Description + +> Offset to retrieve + +#### Signature + +```php + public function offsetGet($offset); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$offset` | mixed | <p> The offset to retrieve. </p> | + +#### Return + + mixed Can return all value types. + +#### Implementation + +```php + public function offsetGet( $offset) { + return $this->$offset; + } + +``` diff --git a/docs/models/NamespaceMd/offsetSet.md b/docs/models/NamespaceMd/offsetSet.md new file mode 100644 index 0000000..3b62549 --- /dev/null +++ b/docs/models/NamespaceMd/offsetSet.md @@ -0,0 +1,34 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [NamespaceMd](__CLASS__.md) + +## `NamespaceMd::offsetSet` + +#### Description + +> Offset to set + +#### Signature + +```php + public function offsetSet($offset, $value); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$offset` | mixed | <p> The offset to assign the value to. </p> | +| `$value` | mixed | <p> The value to set. </p> | + +#### Return + + void + +#### Implementation + +```php + public function offsetSet( $offset, $value) { + $this->$offset = $value; + } + +``` diff --git a/docs/models/NamespaceMd/offsetUnset.md b/docs/models/NamespaceMd/offsetUnset.md new file mode 100644 index 0000000..9694dd1 --- /dev/null +++ b/docs/models/NamespaceMd/offsetUnset.md @@ -0,0 +1,33 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [NamespaceMd](__CLASS__.md) + +## `NamespaceMd::offsetUnset` + +#### Description + +> Offset to unset + +#### Signature + +```php + public function offsetUnset($offset); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$offset` | mixed | <p> The offset to unset. </p> | + +#### Return + + void + +#### Implementation + +```php + public function offsetUnset($offset) { + $this->$offset = null; + } + +``` diff --git a/docs/models/NamespaceMd/setDirectory.md b/docs/models/NamespaceMd/setDirectory.md new file mode 100644 index 0000000..c1b880b --- /dev/null +++ b/docs/models/NamespaceMd/setDirectory.md @@ -0,0 +1,33 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [NamespaceMd](__CLASS__.md) + +## `NamespaceMd::setDirectory` + +#### Description + +> Define the current page directory + +#### Signature + +```php + public function setDirectory($string); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$string` | unknown | | + +#### Return + +> No Return + +#### Implementation + +```php + public function setDirectory( $string) { + $this->page_rd = $string; + } + +``` diff --git a/docs/models/NamespaceMd/write.md b/docs/models/NamespaceMd/write.md new file mode 100644 index 0000000..4d9856e --- /dev/null +++ b/docs/models/NamespaceMd/write.md @@ -0,0 +1,45 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [NamespaceMd](__CLASS__.md) + +## `NamespaceMd::write` + +#### Description + +> Write markdown file + +#### Signature + +```php + public function write(); +``` + +#### Parameters + +> No parameters + +#### Return + +> No Return + +#### Implementation + +```php + public function write(){ + + $m = new \Mustache_Engine([ + 'loader' => new \Mustache_Loader_FilesystemLoader( __DIR__.'/../views') + ]); + $template = $m->loadTemplate('Namespace'); + + $generatedMd = $template->render( $this); + + /// Write page + @mkdir( $this->page_rd, 0777, true); + file_put_contents( $this->page_rd . DIRECTORY_SEPARATOR . $this->page_bfe, $generatedMd); + + + $this->writeMdClasses(); + $this->writeSubPages(); + } + +``` diff --git a/docs/models/NamespaceMd/writeMdClasses.md b/docs/models/NamespaceMd/writeMdClasses.md new file mode 100644 index 0000000..25ad939 --- /dev/null +++ b/docs/models/NamespaceMd/writeMdClasses.md @@ -0,0 +1,33 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [NamespaceMd](__CLASS__.md) + +## `NamespaceMd::writeMdClasses` + +#### Description + +> + +#### Signature + +```php + protected function writeMdClasses(); +``` + +#### Parameters + +> No parameters + +#### Return + +> No Return + +#### Implementation + +```php + protected function writeMdClasses() { + foreach( $this->classMds as $classMd){ + $classMd->write( $this->page_rd); + } + } + +``` diff --git a/docs/models/NamespaceMd/writeSubPages.md b/docs/models/NamespaceMd/writeSubPages.md new file mode 100644 index 0000000..93c80a3 --- /dev/null +++ b/docs/models/NamespaceMd/writeSubPages.md @@ -0,0 +1,35 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [NamespaceMd](__CLASS__.md) + +## `NamespaceMd::writeSubPages` + +#### Description + +> Write sub pages of this page + +#### Signature + +```php + public function writeSubPages(); +``` + +#### Parameters + +> No parameters + +#### Return + +> No Return + +#### Implementation + +```php + public function writeSubPages() { + foreach( $this->subPages as $subPageName => $subPage) { + $subPageDirectory = $this->page_rd . DIRECTORY_SEPARATOR . $subPageName; + $subPage->setDirectory( $subPageDirectory); + $subPage->write(); + } + } + +``` diff --git a/docs/models/ParamMd/__CLASS__.md b/docs/models/ParamMd/__CLASS__.md new file mode 100644 index 0000000..a1f1c48 --- /dev/null +++ b/docs/models/ParamMd/__CLASS__.md @@ -0,0 +1,23 @@ +# **Class** ParamMd + +Full name : `alphayax\mdGen\models\ParamMd` + +## Properties + +- `type` +- `description` +- `variableName` + +## Constants + +> No constants + +## Methods summary + +| Method | Description | +|---|---| +| [`__construct`](__construct.md) | ParamMd constructor. | +| [`offsetExists`](offsetExists.md) | Whether a offset exists | +| [`offsetGet`](offsetGet.md) | Offset to retrieve | +| [`offsetSet`](offsetSet.md) | Offset to set | +| [`offsetUnset`](offsetUnset.md) | Offset to unset | diff --git a/docs/models/ParamMd/__construct.md b/docs/models/ParamMd/__construct.md new file mode 100644 index 0000000..5527abf --- /dev/null +++ b/docs/models/ParamMd/__construct.md @@ -0,0 +1,40 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [ParamMd](__CLASS__.md) + +## `ParamMd::__construct` + +#### Description + +> ParamMd constructor. + +#### Signature + +```php + public function __construct($param); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$param` | \Zend_Reflection_Docblock_Tag_Param | | + +#### Return + +> No Return + +#### Implementation + +```php + public function __construct( \Zend_Reflection_Docblock_Tag_Param $param){ + $this->type = $param->getType(); + $this->description = $param->getDescription(); + $this->variableName = $param->getVariableName(); + + if( empty( $this->variableName) && 0 === strpos( $this->type, '$')){ + $this->variableName = $this->type; + $this->type = 'unknown'; + } + } + +``` diff --git a/docs/models/ParamMd/offsetExists.md b/docs/models/ParamMd/offsetExists.md new file mode 100644 index 0000000..549a9c7 --- /dev/null +++ b/docs/models/ParamMd/offsetExists.md @@ -0,0 +1,33 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [ParamMd](__CLASS__.md) + +## `ParamMd::offsetExists` + +#### Description + +> Whether a offset exists + +#### Signature + +```php + public function offsetExists($offset); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$offset` | mixed | <p> An offset to check for. </p> | + +#### Return + + boolean true on success or false on failure. + +#### Implementation + +```php + public function offsetExists($offset) { + return property_exists( static::class, $offset); + } + +``` diff --git a/docs/models/ParamMd/offsetGet.md b/docs/models/ParamMd/offsetGet.md new file mode 100644 index 0000000..077e6b5 --- /dev/null +++ b/docs/models/ParamMd/offsetGet.md @@ -0,0 +1,33 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [ParamMd](__CLASS__.md) + +## `ParamMd::offsetGet` + +#### Description + +> Offset to retrieve + +#### Signature + +```php + public function offsetGet($offset); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$offset` | mixed | <p> The offset to retrieve. </p> | + +#### Return + + mixed Can return all value types. + +#### Implementation + +```php + public function offsetGet( $offset) { + return $this->$offset; + } + +``` diff --git a/docs/models/ParamMd/offsetSet.md b/docs/models/ParamMd/offsetSet.md new file mode 100644 index 0000000..d24b9b3 --- /dev/null +++ b/docs/models/ParamMd/offsetSet.md @@ -0,0 +1,34 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [ParamMd](__CLASS__.md) + +## `ParamMd::offsetSet` + +#### Description + +> Offset to set + +#### Signature + +```php + public function offsetSet($offset, $value); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$offset` | mixed | <p> The offset to assign the value to. </p> | +| `$value` | mixed | <p> The value to set. </p> | + +#### Return + + void + +#### Implementation + +```php + public function offsetSet( $offset, $value) { + $this->$offset = $value; + } + +``` diff --git a/docs/models/ParamMd/offsetUnset.md b/docs/models/ParamMd/offsetUnset.md new file mode 100644 index 0000000..6ed3ff5 --- /dev/null +++ b/docs/models/ParamMd/offsetUnset.md @@ -0,0 +1,33 @@ +**Namespace** : [alphayax\mdGen\models](../__NAMESPACE__.md) - +**Class** : [ParamMd](__CLASS__.md) + +## `ParamMd::offsetUnset` + +#### Description + +> Offset to unset + +#### Signature + +```php + public function offsetUnset($offset); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$offset` | mixed | <p> The offset to unset. </p> | + +#### Return + + void + +#### Implementation + +```php + public function offsetUnset($offset) { + $this->$offset = null; + } + +``` diff --git a/docs/models/__NAMESPACE__.md b/docs/models/__NAMESPACE__.md index 4fda077..4fd5668 100644 --- a/docs/models/__NAMESPACE__.md +++ b/docs/models/__NAMESPACE__.md @@ -1,64 +1,11 @@ +# Namespace models -# models - -**Namespace** : alphayax\mdGen\models +**Full name** : `alphayax\mdGen\models` # Overview -- [NamespaceMd](__NAMESPACE__.md#NamespaceMd) -- [ClassMd](__NAMESPACE__.md#ClassMd) -- [MethodMd](__NAMESPACE__.md#MethodMd) - - ---- - -## NamespaceMd - -**Class** : alphayax\mdGen\models\NamespaceMd - -### Public methods - -| Method | Description | -|---|---| -| `generateTree` | Generate overview markdown tree | -| `write` | Write markdown file | -| `writeSubPages` | Write sub pages of this page | -| `setDirectory` | Define the current page directory | -| `getPageBfe` | Return the page basename file with extension | -| `offsetExists` | Whether a offset exists | -| `offsetGet` | Offset to retrieve | -| `offsetSet` | Offset to set | -| `offsetUnset` | Offset to unset | - - -## ClassMd - -**Class** : alphayax\mdGen\models\ClassMd - -### Public methods - -| Method | Description | -|---|---| -| `getNextComponent` | Get the next namespace component (according the NS given) | -| `getNamespace` | Get the namespace of the current reflected class | -| `getReflexion` | Get the reflected class | -| `getType` | Return the real kind of class (Trait, Interface, Class) | -| `offsetExists` | Whether a offset exists | -| `offsetGet` | Offset to retrieve | -| `offsetSet` | Offset to set | -| `offsetUnset` | Offset to unset | - - -## MethodMd - -**Class** : alphayax\mdGen\models\MethodMd - -### Public methods - -| Method | Description | -|---|---| -| `offsetExists` | Whether a offset exists | -| `offsetGet` | Offset to retrieve | -| `offsetSet` | Offset to set | -| `offsetUnset` | Offset to unset | +- [NamespaceMd](NamespaceMd/__CLASS__.md) +- [ClassMd](ClassMd/__CLASS__.md) +- [MethodMd](MethodMd/__CLASS__.md) +- [ParamMd](ParamMd/__CLASS__.md) diff --git a/docs/utils/__NAMESPACE__.md b/docs/utils/__NAMESPACE__.md index 892e0de..06a2f4e 100644 --- a/docs/utils/__NAMESPACE__.md +++ b/docs/utils/__NAMESPACE__.md @@ -1,25 +1,8 @@ +# Namespace utils -# utils - -**Namespace** : alphayax\mdGen\utils +**Full name** : `alphayax\mdGen\utils` # Overview -- [arrayAccessProperties](__NAMESPACE__.md#arrayAccessProperties) - - ---- - -## arrayAccessProperties - -**Trait** : alphayax\mdGen\utils\arrayAccessProperties - -### Public methods - -| Method | Description | -|---|---| -| `offsetExists` | Whether a offset exists | -| `offsetGet` | Offset to retrieve | -| `offsetSet` | Offset to set | -| `offsetUnset` | Offset to unset | +- [arrayAccessProperties](arrayAccessProperties/__CLASS__.md) diff --git a/docs/utils/arrayAccessProperties/__CLASS__.md b/docs/utils/arrayAccessProperties/__CLASS__.md new file mode 100644 index 0000000..854d068 --- /dev/null +++ b/docs/utils/arrayAccessProperties/__CLASS__.md @@ -0,0 +1,20 @@ +# **Trait** arrayAccessProperties + +Full name : `alphayax\mdGen\utils\arrayAccessProperties` + +## Properties + +> No properties + +## Constants + +> No constants + +## Methods summary + +| Method | Description | +|---|---| +| [`offsetExists`](offsetExists.md) | Whether a offset exists | +| [`offsetGet`](offsetGet.md) | Offset to retrieve | +| [`offsetSet`](offsetSet.md) | Offset to set | +| [`offsetUnset`](offsetUnset.md) | Offset to unset | diff --git a/docs/utils/arrayAccessProperties/offsetExists.md b/docs/utils/arrayAccessProperties/offsetExists.md new file mode 100644 index 0000000..a6525e6 --- /dev/null +++ b/docs/utils/arrayAccessProperties/offsetExists.md @@ -0,0 +1,33 @@ +**Namespace** : [alphayax\mdGen\utils](../__NAMESPACE__.md) - +**Class** : [arrayAccessProperties](__CLASS__.md) + +## `arrayAccessProperties::offsetExists` + +#### Description + +> Whether a offset exists + +#### Signature + +```php + public function offsetExists($offset); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$offset` | mixed | <p> An offset to check for. </p> | + +#### Return + + boolean true on success or false on failure. + +#### Implementation + +```php + public function offsetExists($offset) { + return property_exists( static::class, $offset); + } + +``` diff --git a/docs/utils/arrayAccessProperties/offsetGet.md b/docs/utils/arrayAccessProperties/offsetGet.md new file mode 100644 index 0000000..d7a8fab --- /dev/null +++ b/docs/utils/arrayAccessProperties/offsetGet.md @@ -0,0 +1,33 @@ +**Namespace** : [alphayax\mdGen\utils](../__NAMESPACE__.md) - +**Class** : [arrayAccessProperties](__CLASS__.md) + +## `arrayAccessProperties::offsetGet` + +#### Description + +> Offset to retrieve + +#### Signature + +```php + public function offsetGet($offset); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$offset` | mixed | <p> The offset to retrieve. </p> | + +#### Return + + mixed Can return all value types. + +#### Implementation + +```php + public function offsetGet( $offset) { + return $this->$offset; + } + +``` diff --git a/docs/utils/arrayAccessProperties/offsetSet.md b/docs/utils/arrayAccessProperties/offsetSet.md new file mode 100644 index 0000000..1457db6 --- /dev/null +++ b/docs/utils/arrayAccessProperties/offsetSet.md @@ -0,0 +1,34 @@ +**Namespace** : [alphayax\mdGen\utils](../__NAMESPACE__.md) - +**Class** : [arrayAccessProperties](__CLASS__.md) + +## `arrayAccessProperties::offsetSet` + +#### Description + +> Offset to set + +#### Signature + +```php + public function offsetSet($offset, $value); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$offset` | mixed | <p> The offset to assign the value to. </p> | +| `$value` | mixed | <p> The value to set. </p> | + +#### Return + + void + +#### Implementation + +```php + public function offsetSet( $offset, $value) { + $this->$offset = $value; + } + +``` diff --git a/docs/utils/arrayAccessProperties/offsetUnset.md b/docs/utils/arrayAccessProperties/offsetUnset.md new file mode 100644 index 0000000..5a748ac --- /dev/null +++ b/docs/utils/arrayAccessProperties/offsetUnset.md @@ -0,0 +1,33 @@ +**Namespace** : [alphayax\mdGen\utils](../__NAMESPACE__.md) - +**Class** : [arrayAccessProperties](__CLASS__.md) + +## `arrayAccessProperties::offsetUnset` + +#### Description + +> Offset to unset + +#### Signature + +```php + public function offsetUnset($offset); +``` + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| `$offset` | mixed | <p> The offset to unset. </p> | + +#### Return + + void + +#### Implementation + +```php + public function offsetUnset($offset) { + $this->$offset = null; + } + +``` diff --git a/src/MdGen.php b/src/MdGen.php index b65a418..f9252e0 100644 --- a/src/MdGen.php +++ b/src/MdGen.php @@ -8,16 +8,19 @@ */ class MdGen { - /** @var string */ + /// Default values + const DEFAULT_SRC_DIRECTORY = ''; + + /** @var string Source directory. PHP Files will be scanned in this folder */ protected $srcDirectory = ''; - /** @var string[] */ + /** @var string[] List of all founded PHP Classes, Interfaces and Traits */ protected $loadedClasses; - /** @var models\ClassMd[] */ + /** @var models\ClassMd[] Filtered list of PHP Classes, Interfaces and Traits */ protected $chapters = []; - /** @var models\NamespaceMd */ + /** @var models\NamespaceMd Root Namespace */ protected $rootPage; @@ -26,7 +29,7 @@ class MdGen { * @param $srcDirectory * @param $rootNamespace */ - public function __construct( $srcDirectory, $rootNamespace){ + public function __construct( $srcDirectory = self::DEFAULT_SRC_DIRECTORY, $rootNamespace){ $this->rootNamespace = $rootNamespace; $this->srcDirectory = $srcDirectory; $this->loadClasses(); @@ -41,6 +44,7 @@ protected function loadClasses(){ throw new \Exception( 'Source directory not found : '. $this->srcDirectory); } + /// Recursively scan PHP Files $objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator( $this->srcDirectory), \RecursiveIteratorIterator::SELF_FIRST); $Regex = new \RegexIterator( $objects, '/^.+\.php$/i', \RecursiveRegexIterator::GET_MATCH); foreach( $Regex as $name => $object){ @@ -49,6 +53,7 @@ protected function loadClasses(){ } } + /// Extract data from loaded classes $classes = get_declared_classes(); $traits = get_declared_traits(); $interfaces = get_declared_interfaces(); @@ -57,7 +62,7 @@ protected function loadClasses(){ /** * Filter class who are in a specific namespace - * @param $namespaceName + * @param string $namespaceName Namespace Name to filter */ public function filterNamespace( $namespaceName) { $FilteredClasses = []; @@ -71,7 +76,7 @@ public function filterNamespace( $namespaceName) { /** * Filter class who are sub-classes of a specific class - * @param $className + * @param string $className Super class name to filter */ public function filterSubClasses( $className) { $FilteredClasses = []; @@ -85,19 +90,19 @@ public function filterSubClasses( $className) { /** * Create a chapter form loaded classes - * @return array + * @return ClassMd[] */ protected function generateClassMdFromLoadedClasses(){ - $chapters = []; + $classMds = []; foreach( $this->loadedClasses as $class){ - $chapters[] = new ClassMd( $class); + $classMds[] = new ClassMd( $class); } - return $chapters; + return $classMds; } /** * Generate markdown files - * @param string $directory + * @param string $directory Path to generated files */ public function generate( $directory = '.'){ $chapters = $this->generateClassMdFromLoadedClasses(); diff --git a/src/models/ClassMd.php b/src/models/ClassMd.php index b405f9a..951af8a 100644 --- a/src/models/ClassMd.php +++ b/src/models/ClassMd.php @@ -15,12 +15,21 @@ class ClassMd implements \ArrayAccess { /** @var \ReflectionClass */ protected $reflexion; + /** @var MethodMd[] */ + protected $publicMethods; + /** @var MethodMd[] */ protected $methods; /** @var string Class type (Interface, Trait or Class) */ protected $type; + /** @var array */ + protected $properties = []; + + /** @var array */ + protected $constants = []; + /** * ClassChapter constructor. * @param string $class @@ -30,9 +39,19 @@ public function __construct( $class){ $this->reflexion = new \ReflectionClass( $class); $this->computeType(); + /// Properties + $properties = $this->reflexion->getProperties(); + foreach ($properties as $property){ + $this->properties[] = $property->getName(); + } + + /// Methods $methods = $this->reflexion->getMethods(); foreach ( $methods as $method){ + $methodMd = new MethodMd( $this->reflexion->getName(), $method->getName()); + $this->methods[] = $methodMd; + /// Filter only public and non constructor methods if( ! $method->isPublic() || $method->isConstructor()){ continue; @@ -43,7 +62,15 @@ public function __construct( $class){ continue; } - $this->methods[] = new MethodMd( $this->reflexion->getName(), $method->getName()); + $this->publicMethods[] = $methodMd; + } + + /// Constants + foreach ( $this->reflexion->getConstants() as $constantName => $constantValue){ + $this->constants[] = [ + 'name' => $constantName, + 'value' => $constantValue, + ]; } } @@ -93,10 +120,27 @@ public function getReflexion(){ return $this->reflexion; } - /** - * Return the real kind of class (Trait, Interface, Class) - */ - public function getType(){ + public function write( $path) { + + $m = new \Mustache_Engine([ + 'loader' => new \Mustache_Loader_FilesystemLoader( __DIR__.'/../views'), + 'partials_loader' => new \Mustache_Loader_FilesystemLoader( __DIR__. '/../views/MethodMd'), + + ]); + + $generatedMd = $m->loadTemplate('Class')->render( $this); + $page_rd = $path . DIRECTORY_SEPARATOR . $this->getReflexion()->getShortName(); + /// Write page + @mkdir( $page_rd, 0777, true); + file_put_contents( $page_rd . DIRECTORY_SEPARATOR . '__CLASS__.md', $generatedMd); + + $this->writeMethods( $page_rd); + } + + private function writeMethods( $path) { + foreach( $this->methods as $method){ + $method->write( $path); + } } } diff --git a/src/models/MethodMd.php b/src/models/MethodMd.php index 0a2f6ac..acf1256 100644 --- a/src/models/MethodMd.php +++ b/src/models/MethodMd.php @@ -9,6 +9,9 @@ class MethodMd implements \ArrayAccess { use utils\arrayAccessProperties; + /** @var \Zend_Reflection_Method */ + protected $reflexion; + /** @var string Method Name */ protected $name; @@ -21,25 +24,108 @@ class MethodMd implements \ArrayAccess { /** @var mixed Method Return */ protected $return; + protected $impl; + /** * MethodMd constructor. * @param $className * @param $methodName */ - public function __construct($className, $methodName) { + public function __construct( $className, $methodName) { try { - $method2 = new \Zend_Reflection_Method( $className, $methodName); + $this->reflexion = new \Zend_Reflection_Method( $className, $methodName); + + $this->name = $this->reflexion->getName(); + $docBlock = $this->reflexion->getDocblock(); + + $this->extractImplementation(); - $this->name = $method2->getName(); - $docBlock = $method2->getDocblock(); + /// Desc $shortDesc = str_replace(PHP_EOL, ' ', $docBlock->getShortDescription()); $this->description = str_replace(PHP_EOL, ' ', $shortDesc); - } catch (\Exception $e) { + /// Params + /** @var \Zend_Reflection_Docblock_Tag_Param[] $params */ + $params = $docBlock->getTags( 'param'); + foreach ( $params as $param){ + $this->params[] = new ParamMd( $param); + } + + /** @var \Zend_Reflection_Docblock_Tag_Return $return */ + $return = $docBlock->getTag( 'return'); + if( $return){ + $this->return = $return->getType() . ' ' . $return->getDescription(); + } + } + catch( \Exception $e) { // Unable to parse PHPDoc Block... Skip it :( } } + protected function extractImplementation(){ + + /// Implementation + $this->impl = ''; + $f = fopen( $this->reflexion->getFileName(), 'r'); + $lineNo = 0; + while ($line = fgets($f)) { + $lineNo++; + if ($lineNo >= $this->reflexion->getStartLine()) { + $this->impl .= $line; + } + if ($lineNo == $this->reflexion->getEndLine()) { + break; + } + } + fclose($f); + } + + /** + * @return bool + */ + public function hasParams() { + return ! empty( $this->params); + } + + /** + * @return string + */ + public function getParams(){ + $variablesNames = []; + foreach( $this->params as $param){ + $variablesNames[] = $param['variableName']; + } + return implode(', ', $variablesNames); + } + + /** + * @return string + */ + public function getModifiers() { + return + ($this->reflexion->isFinal() ? ' final' : ''). + ($this->reflexion->isAbstract() ? ' abstract' : ''). + ($this->reflexion->isPublic() ? ' public' : ''). + ($this->reflexion->isProtected() ? ' protected' : ''). + ($this->reflexion->isPrivate() ? ' private' : ''). + ($this->reflexion->isStatic() ? ' static' : ''); + + } + + /** + * @param $path + */ + public function write( $path) { + $m = new \Mustache_Engine([ + 'loader' => new \Mustache_Loader_FilesystemLoader( __DIR__.'/../views'), + 'partials_loader' => new \Mustache_Loader_FilesystemLoader(__DIR__ . '/../views/MethodMd'), + + ]); + + $generatedMd = $m->loadTemplate('Method')->render( $this); + file_put_contents( $path . DIRECTORY_SEPARATOR . $this->name . '.md', $generatedMd); + } + } diff --git a/src/models/NamespaceMd.php b/src/models/NamespaceMd.php index 1fe44e4..65fafd0 100644 --- a/src/models/NamespaceMd.php +++ b/src/models/NamespaceMd.php @@ -73,7 +73,7 @@ protected function computePageName(){ public function generateTree( $pad = '', $relativePath = '') { $generatedMd = ''; - /// SubPages + /// SubNamespaces if( ! empty( $this->subPages)){ foreach( $this->subPages as $subPageName => $subPage){ $subPageFile = './' . $relativePath . $subPageName . DIRECTORY_SEPARATOR . $subPage->getPageBfe(); @@ -82,13 +82,12 @@ public function generateTree( $pad = '', $relativePath = '') { } } - /// Chapters + /// Classes if( ! empty( $this->classMds)){ - foreach($this->classMds as $chapter){ - $chapterName = $chapter->getReflexion()->getShortName(); - $chapterFile = $relativePath . $this->getPageBfe(); - $chapterAnchor = $chapterFile .'#'. $chapter->getReflexion()->getShortName(); - $generatedMd .= "$pad- [$chapterName]($chapterAnchor)" . PHP_EOL; + foreach($this->classMds as $classMd){ + $className = $classMd->getReflexion()->getShortName(); + $classFile = $relativePath . $className . DIRECTORY_SEPARATOR . '__CLASS__.md'; + $generatedMd .= "$pad- [$className]($classFile)" . PHP_EOL; } } @@ -103,15 +102,26 @@ public function write(){ $m = new \Mustache_Engine([ 'loader' => new \Mustache_Loader_FilesystemLoader( __DIR__.'/../views') ]); - $template = $m->loadTemplate('Page'); + $template = $m->loadTemplate('Namespace'); $generatedMd = $template->render( $this); - $this->writeSubPages(); - /// Write page @mkdir( $this->page_rd, 0777, true); file_put_contents( $this->page_rd . DIRECTORY_SEPARATOR . $this->page_bfe, $generatedMd); + + + $this->writeMdClasses(); + $this->writeSubPages(); + } + + /** + * + */ + protected function writeMdClasses() { + foreach( $this->classMds as $classMd){ + $classMd->write( $this->page_rd); + } } /** @@ -135,7 +145,7 @@ public function setDirectory( $string) { /** * Return the page basename file with extension - * @return string + * @return string The page base name */ public function getPageBfe() { return $this->page_bfe; diff --git a/src/models/ParamMd.php b/src/models/ParamMd.php new file mode 100644 index 0000000..b1b6c1f --- /dev/null +++ b/src/models/ParamMd.php @@ -0,0 +1,33 @@ +type = $param->getType(); + $this->description = $param->getDescription(); + $this->variableName = $param->getVariableName(); + + if( empty( $this->variableName) && 0 === strpos( $this->type, '$')){ + $this->variableName = $this->type; + $this->type = 'unknown'; + } + } + +} diff --git a/src/views/Class.mustache b/src/views/Class.mustache new file mode 100644 index 0000000..57b8c37 --- /dev/null +++ b/src/views/Class.mustache @@ -0,0 +1,29 @@ +# **{{ type }}** {{ reflexion.getShortName }} + +Full name : `{{ class }}` + +## Properties + +{{# properties}} +- `{{.}}` +{{/ properties}} +{{^ properties}} +> No properties +{{/ properties}} + +## Constants + +{{# constants}} +- `{{name}} = '{{{value}}}'` +{{/ constants}} +{{^ constants}} +> No constants +{{/ constants}} + +## Methods summary + +| Method | Description | +|---|---| +{{# methods }} +| [`{{name}}`]({{name}}.md) | {{description}} | +{{/ methods }} diff --git a/src/views/Method.mustache b/src/views/Method.mustache new file mode 100644 index 0000000..45e348d --- /dev/null +++ b/src/views/Method.mustache @@ -0,0 +1,14 @@ +**Namespace** : [{{ reflexion.getDeclaringClass.getNamespaceName }}](../__NAMESPACE__.md) - +**Class** : [{{ reflexion.getDeclaringClass.getShortName }}](__CLASS__.md) + +## `{{ reflexion.getDeclaringClass.getShortName }}::{{ name }}` + +{{> Description}} + +{{> Signature}} + +{{> Param}} + +{{> Return}} + +{{> Implementation}} diff --git a/src/views/MethodMd/Description.mustache b/src/views/MethodMd/Description.mustache new file mode 100644 index 0000000..1f0569a --- /dev/null +++ b/src/views/MethodMd/Description.mustache @@ -0,0 +1,3 @@ +#### Description + +> {{description}} diff --git a/src/views/MethodMd/Implementation.mustache b/src/views/MethodMd/Implementation.mustache new file mode 100644 index 0000000..0bc7820 --- /dev/null +++ b/src/views/MethodMd/Implementation.mustache @@ -0,0 +1,5 @@ +#### Implementation + +```php +{{{ impl }}} +``` diff --git a/src/views/MethodMd/Param.mustache b/src/views/MethodMd/Param.mustache new file mode 100644 index 0000000..5d798d7 --- /dev/null +++ b/src/views/MethodMd/Param.mustache @@ -0,0 +1,12 @@ +#### Parameters + +{{# hasParams}} +| Name | Type | Description | +|---|---|---| +{{# params }} +| `{{variableName}}` | {{type}} | {{description}} | +{{/ params }} +{{/ hasParams }} +{{^ hasParams }} +> No parameters +{{/ hasParams }} diff --git a/src/views/MethodMd/Return.mustache b/src/views/MethodMd/Return.mustache new file mode 100644 index 0000000..6a0eb2a --- /dev/null +++ b/src/views/MethodMd/Return.mustache @@ -0,0 +1,8 @@ +#### Return + +{{# return }} + {{.}} +{{/ return }} +{{^ return }} +> No Return +{{/ return }} diff --git a/src/views/MethodMd/Signature.mustache b/src/views/MethodMd/Signature.mustache new file mode 100644 index 0000000..bbd3c9b --- /dev/null +++ b/src/views/MethodMd/Signature.mustache @@ -0,0 +1,5 @@ +#### Signature + +```php +{{getModifiers}} function {{name}}({{getParams}}); +``` diff --git a/src/views/Namespace.mustache b/src/views/Namespace.mustache new file mode 100644 index 0000000..0bf82c9 --- /dev/null +++ b/src/views/Namespace.mustache @@ -0,0 +1,7 @@ +# Namespace {{ pageName }} + +**Full name** : `{{ namespace }}` + +# Overview + +{{ generateTree }} diff --git a/src/views/Page.mustache b/src/views/Page.mustache deleted file mode 100644 index a9f8eab..0000000 --- a/src/views/Page.mustache +++ /dev/null @@ -1,25 +0,0 @@ - -# {{ pageName }} - -**Namespace** : {{ namespace }} - -# Overview - -{{ generateTree }} - ---- -{{# classMds }} - -## {{getReflexion.getShortName}} - -**{{type}}** : {{getReflexion.getName}} - -### Public methods - -| Method | Description | -|---|---| -{{# methods }} -| `{{name}}` | {{description}} | -{{/ methods }} - -{{/ classMds }}