This repository has been archived by the owner on Jul 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Refactor SchemaGenerator and remove php: prefix in XSD
- Loading branch information
1 parent
7e1ca30
commit 48c8c84
Showing
5 changed files
with
138 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
namespace TYPO3Fluid\SchemaGenerator; | ||
|
||
/** | ||
* Class ClassFinder | ||
*/ | ||
class ClassFinder { | ||
|
||
/** | ||
* @param $packagePaths | ||
* @param $phpNamespace | ||
*/ | ||
public function getClassNamesInPackages(array $packagePaths) { | ||
$classNames = array(); | ||
foreach ($packagePaths as $namespace => $classesPath) { | ||
$classNames = array_replace($classNames, $this->getClassNamesInPackage($classesPath, $namespace)); | ||
if (count($classNames) === 0) { | ||
throw new \RuntimeException(sprintf('No ViewHelpers found in path "%s"', $classesPath), 1330029328); | ||
} | ||
} | ||
return $classNames; | ||
} | ||
|
||
/** | ||
* Get all class names inside this namespace and return them as array. | ||
* To generate a merged namespace simply provide multiple paths (with | ||
* comma as separator) as $packagePaths argument value. | ||
* | ||
* @param string $packagePath | ||
* @param string $phpNamespace | ||
* @return array | ||
*/ | ||
public function getClassNamesInPackage($packagePath, $phpNamespace) { | ||
$allViewHelperClassNames = array(); | ||
$affectedViewHelperClassNames = array(); | ||
|
||
$packagePath = rtrim($packagePath, '/') . '/'; | ||
$filesInPath = new \RecursiveDirectoryIterator($packagePath, \RecursiveDirectoryIterator::SKIP_DOTS); | ||
$packagePathLength = strlen($packagePath); | ||
foreach ($filesInPath as $filePathAndFilename) { | ||
$relativePath = substr($filePathAndFilename, $packagePathLength, -4); | ||
$classLocation = str_replace('/', '\\', $relativePath); | ||
$className = $phpNamespace . $classLocation; | ||
if (class_exists($className)) { | ||
$parent = $className; | ||
while ($parent = get_parent_class($parent)) { | ||
array_push($allViewHelperClassNames, $className); | ||
} | ||
} | ||
} | ||
foreach ($allViewHelperClassNames as $viewHelperClassName) { | ||
$classReflection = new \ReflectionClass($viewHelperClassName); | ||
if ($classReflection->isAbstract() === FALSE) { | ||
$affectedViewHelperClassNames[] = $viewHelperClassName; | ||
} | ||
} | ||
|
||
sort($affectedViewHelperClassNames); | ||
return $affectedViewHelperClassNames; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
namespace TYPO3Fluid\SchemaGenerator; | ||
use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperInterface; | ||
|
||
/** | ||
* Class ViewHelperDocumentation | ||
*/ | ||
class ViewHelperDocumentation { | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $className; | ||
|
||
/** | ||
* @param string $className | ||
*/ | ||
public function __construct($className) { | ||
$this->className = $className; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getClass() { | ||
return $this->className; | ||
} | ||
|
||
/** | ||
* Returns TRUE if the class should be included in the schema, FALSE otherwise. | ||
* | ||
* @return boolean | ||
*/ | ||
public function isIncluded() { | ||
$reflectionClass = new \ReflectionClass($this->className); | ||
return $reflectionClass->implementsInterface(ViewHelperInterface::class); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getDescription() { | ||
$reflectionClass = new \ReflectionClass($this->className); | ||
$docCommentParser = new DocCommentParser(); | ||
return $docCommentParser->parseDocComment($reflectionClass->getDocComment()); | ||
} | ||
|
||
/** | ||
* @return ArgumentDefinition[] | ||
*/ | ||
public function getArgumentDefinitions() { | ||
$className = $this->className; | ||
$viewHelper = new $className(); | ||
return $viewHelper->prepareArguments(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters