Commit c24432f0 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Meilleur support des types de classes et des fieldsets

parent bf88712c
Loading
Loading
Loading
Loading
Loading
+10 −0
Changes for code/generator/awareTrait.php: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -40,6 +40,16 @@ return [

        if ('Entity' == $type) {
            $method = Util::classClassname($class);
        }elseif('Fieldset' == $type){
            $method     = Util::classTruncated($class, $module);
            if (0 === strpos($method, 'Form\\')){
                $method = 'Fieldset\\'.substr($method, 5);
            }
            $methodBase = Util::classRoot($method);
            $method     = Util::classCamelCase($method);
            if (substr($method, -strlen($methodBase)) == $methodBase) {
                $method = substr($method, 0, -strlen($methodBase));
            }
        } else {
            $method     = Util::classTruncated($class, $module);
            $methodBase = Util::classRoot($method);
+2 −1
Changes for src/Service/CodeGeneratorService.php: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -110,6 +110,7 @@ class CodeGeneratorService

        if ($cmd = $this->genCmd($oriParams, $params)) {
            $params['commandLine'] = $cmd;
            $params['echoCommandLine'] = !Console::isConsole() && !$hasInputData;
        }

        if ($doGen) {
@@ -179,7 +180,7 @@ class CodeGeneratorService
            $this->echo($params);
        }

        if (!Console::isConsole() && isset($params['commandLine'])) {
        if ($params['echoCommandLine'] ?? false) {
            ?>
            <h1>Création des fichiers depuis la ligne de commandes</h1>
            <div class="alert alert-warning">
+20 −8
Changes for src/Util.php: 20 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -543,21 +543,32 @@ class Util
     */
    public static function classType(string $class): ?string
    {
        $subClassTypes = [
            \Laminas\Form\Form::class                                    => 'Form',
            \Laminas\Form\Fieldset::class                                => 'Fieldset',
            \Laminas\View\Helper\HelperInterface::class                  => 'ViewHelper',
            \Laminas\Mvc\Controller\AbstractController::class            => 'Controller',
            \Laminas\Validator\ValidatorInterface::class                 => 'Validator',
            \Laminas\Hydrator\HydratorInterface::class                   => 'Hydrator',
            \Laminas\Permissions\Acl\Assertion\AssertionInterface::class => 'Assertion',

        ];

        $types = [
            'View\Helper' => 'ViewHelper',
            'ViewHelper'  => 'ViewHelper',
            'Form'        => 'Form',
            'Fieldset'    => 'Fieldset',
            'Service'   => 'Service',
            'Entity'    => 'Entity',
            'Hydrator'    => 'Hydrator',
            'Assertion'   => 'Assertion',
            'Controller'  => 'Controller',
            'Provider'  => 'Provider',
            'Processus' => 'Processus',
            'Validator'   => 'Validator',
            'Proxy'     => 'Proxy',
        ];

        $rc = new \ReflectionClass($class);
        foreach ($subClassTypes as $parent => $type) {
            if ($rc->isSubclassOf($parent)) {
                return $type;
            }
        }

        foreach ($types as $key => $type) {
            if (false !== strpos($class, '\\' . $key . '\\')) {
                return $type;
@@ -661,6 +672,7 @@ class Util
            /* @var $config ConfigService */
            $config = self::getContainer()->get(ConfigService::class);
            $author = $config->getAuthor();

            return $author;
        } catch (\Exception $e) {
        }