This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
121 additions
and
122 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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
142 changes: 71 additions & 71 deletions
142
...Renderer/ReactorBasedPropertyRenderer.php → ...Renderer/ReactorBasedPropertyRenderer.php
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 |
---|---|---|
@@ -1,72 +1,72 @@ | ||
<?php | ||
/** | ||
* Spiral Framework, IDE Helper | ||
* | ||
* @author Dmitry Mironov <[email protected]> | ||
* @licence MIT | ||
*/ | ||
|
||
namespace Spiral\IdeHelper\Renderer; | ||
|
||
use Spiral\IdeHelper\Helpers; | ||
use Spiral\IdeHelper\Model\ClassProperty; | ||
use Spiral\Reactor\ClassDeclaration; | ||
use Spiral\Reactor\ClassDeclaration\PropertyDeclaration; | ||
use Spiral\Reactor\FileDeclaration; | ||
|
||
|
||
/** | ||
* Class ReactorBasedPropertyRenderer | ||
* | ||
* WARNING: this class only support rendering multiple classes in the same namespace. | ||
* | ||
* @package Spiral\IdeHelper\Renderer | ||
*/ | ||
class ReactorBasedPropertyRenderer implements RendererInterface | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function render(array $classes): string | ||
{ | ||
if (count($classes) === 0) { | ||
$declaration = new FileDeclaration(); | ||
|
||
return $declaration->render(); | ||
} | ||
|
||
$namespace = $classes[0]->getNamespace() ?? ''; | ||
$fileDeclaration = new FileDeclaration($namespace); | ||
foreach ($classes as $class) { | ||
$classDeclaration = new ClassDeclaration($class->getShortName()); | ||
$properties = $classDeclaration->getProperties(); | ||
|
||
foreach ($class->getMembers() as $member) { | ||
if ($member instanceof ClassProperty) { | ||
$name = $member->getName(); | ||
$comment = $this->renderProperty($member->getTypes()); | ||
|
||
$property = new PropertyDeclaration($name, null, $comment); | ||
$property->setAccess("protected"); | ||
|
||
$properties->add($property); | ||
} | ||
} | ||
|
||
$fileDeclaration->addElement($classDeclaration); | ||
} | ||
|
||
return $fileDeclaration->render(); | ||
} | ||
|
||
/** | ||
* @param array $types | ||
* @return string | ||
*/ | ||
private function renderProperty(array $types): string | ||
{ | ||
$type = implode('|', array_map([Helpers::class, 'fqcn'], $types)); | ||
|
||
return "@var {$type}"; | ||
} | ||
<?php | ||
/** | ||
* Spiral Framework, IDE Helper | ||
* | ||
* @author Dmitry Mironov <[email protected]> | ||
* @licence MIT | ||
*/ | ||
|
||
namespace Spiral\IdeHelper\Renderer; | ||
|
||
use Spiral\IdeHelper\Helpers; | ||
use Spiral\IdeHelper\Model\ClassProperty; | ||
use Spiral\Reactor\ClassDeclaration; | ||
use Spiral\Reactor\ClassDeclaration\PropertyDeclaration; | ||
use Spiral\Reactor\FileDeclaration; | ||
|
||
|
||
/** | ||
* Class ReactorBasedPropertyRenderer | ||
* | ||
* WARNING: this class only support rendering multiple classes in the same namespace. | ||
* | ||
* @package Spiral\IdeHelper\Renderer | ||
*/ | ||
class ReactorBasedPropertyRenderer implements RendererInterface | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function render(array $classes): string | ||
{ | ||
if (count($classes) === 0) { | ||
$declaration = new FileDeclaration(); | ||
|
||
return $declaration->render(); | ||
} | ||
|
||
$namespace = $classes[0]->getNamespace() ?? ''; | ||
$fileDeclaration = new FileDeclaration($namespace); | ||
foreach ($classes as $class) { | ||
$classDeclaration = new ClassDeclaration($class->getShortName()); | ||
$properties = $classDeclaration->getProperties(); | ||
|
||
foreach ($class->getMembers() as $member) { | ||
if ($member instanceof ClassProperty) { | ||
$name = $member->getName(); | ||
$comment = $this->renderProperty($member->getTypes()); | ||
|
||
$property = new PropertyDeclaration($name, null, $comment); | ||
$property->setAccess("protected"); | ||
|
||
$properties->add($property); | ||
} | ||
} | ||
|
||
$fileDeclaration->addElement($classDeclaration); | ||
} | ||
|
||
return $fileDeclaration->render(); | ||
} | ||
|
||
/** | ||
* @param array $types | ||
* @return string | ||
*/ | ||
private function renderProperty(array $types): string | ||
{ | ||
$type = implode('|', array_map([Helpers::class, 'fqcn'], $types)); | ||
|
||
return "@var {$type}"; | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -1,45 +1,44 @@ | ||
<?php | ||
/** | ||
* Spiral Framework, IDE Helper | ||
* | ||
* @author Dmitry Mironov <[email protected]> | ||
* @licence MIT | ||
*/ | ||
|
||
namespace Spiral; | ||
|
||
|
||
use Spiral\Core\DirectoriesInterface; | ||
use Spiral\IdeHelper\IdeHelperConfig; | ||
use Spiral\Modules\ModuleInterface; | ||
use Spiral\Modules\PublisherInterface; | ||
use Spiral\Modules\RegistratorInterface; | ||
|
||
/** | ||
* Class IdeHelperModule | ||
* | ||
* @package Spiral\IdeHelper | ||
*/ | ||
class IdeHelperModule implements ModuleInterface | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function register(RegistratorInterface $registrator) | ||
{ | ||
$registrator->configure('tokenizer', 'directories', 'spiral/idehelper', [ | ||
"directory('libraries') . 'spiral/idehelper/src/',", | ||
]); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function publish(PublisherInterface $publisher, DirectoriesInterface $directories) | ||
{ | ||
$publisher->publish( | ||
__DIR__ . '/../resources/config.php', | ||
$directories->directory('config') . IdeHelperConfig::CONFIG . '.php' | ||
); | ||
} | ||
<?php | ||
/** | ||
* Spiral Framework, IDE Helper | ||
* | ||
* @author Dmitry Mironov <[email protected]> | ||
* @licence MIT | ||
*/ | ||
|
||
namespace Spiral; | ||
|
||
use Spiral\Core\DirectoriesInterface; | ||
use Spiral\IdeHelper\IdeHelperConfig; | ||
use Spiral\Modules\ModuleInterface; | ||
use Spiral\Modules\PublisherInterface; | ||
use Spiral\Modules\RegistratorInterface; | ||
|
||
/** | ||
* Class IdeHelperModule | ||
* | ||
* @package Spiral\IdeHelper | ||
*/ | ||
class IdeHelperModule implements ModuleInterface | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function register(RegistratorInterface $registrator) | ||
{ | ||
$registrator->configure('tokenizer', 'directories', 'spiral/idehelper', [ | ||
"directory('libraries') . 'spiral/ide-helper/src/',", | ||
]); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function publish(PublisherInterface $publisher, DirectoriesInterface $directories) | ||
{ | ||
$publisher->publish( | ||
__DIR__ . '/../resources/config.php', | ||
$directories->directory('config') . IdeHelperConfig::CONFIG . '.php' | ||
); | ||
} | ||
} |