当前位置: 首页>>代码示例>>PHP>>正文


PHP ClassType::addComment方法代码示例

本文整理汇总了PHP中Nette\PhpGenerator\ClassType::addComment方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassType::addComment方法的具体用法?PHP ClassType::addComment怎么用?PHP ClassType::addComment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Nette\PhpGenerator\ClassType的用法示例。


在下文中一共展示了ClassType::addComment方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createModel

 private function createModel()
 {
     $class = new ClassType('Orm', $this->namespace);
     $class->setExtends('\\Nextras\\Orm\\Model\\Model');
     foreach ($this->parsedSql as $block) {
         if (isset($block['CREATE'], $block['TABLE'])) {
             $table = $this->normalizeSqlName($block['TABLE']['name']);
             $type = $this->getCamelCase($table) . "Repository";
             $property = '$' . $this->getCamelCase($table, true) . 's';
             $class->addComment("@property-read {$type} {$property}");
         }
     }
     $this->createClass($class);
 }
开发者ID:zarganwar,项目名称:nextras-orm-generator,代码行数:14,代码来源:Generator.php

示例2: afterCompile

 public function afterCompile(Nette\PhpGenerator\ClassType $class)
 {
     $initialize = $class->getMethod('initialize');
     $container = $this->getContainerBuilder();
     if ($this->debugMode && $this->config['debugger']) {
         Nette\Bridges\DITracy\ContainerPanel::$compilationTime = $this->time;
         $initialize->addBody($container->formatPhp('?;', array(new Nette\DI\Statement('@Tracy\\Bar::addPanel', array(new Nette\DI\Statement('Nette\\Bridges\\DITracy\\ContainerPanel'))))));
     }
     foreach (array_filter($container->findByTag('run')) as $name => $on) {
         $initialize->addBody('$this->getService(?);', array($name));
     }
     if (!empty($this->config['accessors'])) {
         $definitions = $container->getDefinitions();
         ksort($definitions);
         foreach ($definitions as $name => $def) {
             if (Nette\PhpGenerator\Helpers::isIdentifier($name)) {
                 $type = $def->getImplement() ?: $def->getClass();
                 $class->addComment("@property {$type} \${$name}");
             }
         }
     }
 }
开发者ID:knedle,项目名称:twitter-nette-skeleton,代码行数:22,代码来源:DIExtension.php

示例3: addAutoGeneratedWarning

 private function addAutoGeneratedWarning(ClassType $class)
 {
     if (count($class->getDocuments())) {
         $class->addComment("");
     }
     $class->addComment("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")->addComment("!!!                                                     !!!")->addComment("!!!   THIS CLASS HAS BEEN AUTO-GENERATED, DO NOT EDIT   !!!")->addComment("!!!                                                     !!!")->addComment("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
 }
开发者ID:jakubkulhan,项目名称:meta,代码行数:7,代码来源:ProtocGenPhp.php

示例4: __construct

 public function __construct($namespace, $className, $document = 'Generated Class')
 {
     $this->currentFile = new PhpFile();
     $this->currentClass = $this->currentFile->addClass($namespace . '\\' . ucfirst($className));
     $this->currentClass->addComment($document);
 }
开发者ID:yoghi,项目名称:madda,代码行数:6,代码来源:ClassGenerator.php

示例5: generateTests

    public function generateTests($outputFolder)
    {
        $container = \Testbench\ContainerFactory::create(FALSE);
        $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory');
        $presenters = $container->findByType('Nette\\Application\\UI\\Presenter');
        foreach ($presenters as $presenter) {
            $this->renderMethods = $this->handleMethods = $this->componentMethods = [];
            /** @var \Nette\Application\UI\Presenter $service */
            $service = $container->getService($presenter);
            if ($service instanceof \Testbench\Mocks\PresenterMock) {
                continue;
            }
            if ($service instanceof \KdybyModule\CliPresenter) {
                //Oh, Kdyby! :-(
                continue;
            }
            $rc = new \ReflectionClass($service);
            $renderPrefix = $service->formatActionMethod('') . '|' . $service->formatRenderMethod('');
            $methods = $rc->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED);
            foreach ($methods as $method) {
                $methodName = $method->getName();
                if (preg_match("~^({$renderPrefix})[a-z0-9]+~i", $methodName)) {
                    try {
                        $optionalArgs = $this->tryCall($service, $methodName, $service->getParameters(), TRUE);
                        if (preg_match('~.*rss.*~i', $methodName)) {
                            $this->renderMethods[$methodName] = 'rss';
                        } elseif (preg_match('~.*sitemap.*~i', $methodName)) {
                            $this->renderMethods[$methodName] = 'sitemap';
                        } else {
                            $requiredArgs = $this->tryCall($service, $methodName, $service->getParameters(), FALSE);
                            $this->renderMethods[$methodName] = ['action', [$optionalArgs, $requiredArgs]];
                        }
                    } catch (\Nette\Application\AbortException $exc) {
                        $this->renderMethods[$methodName] = ['action', $this->getResponse($service)];
                    } catch (\Exception $exc) {
                        $this->renderMethods[$methodName] = ['exception', $exc];
                    }
                }
                if (preg_match('~^handle[a-z0-9]+~i', $methodName)) {
                    if ($methodName === 'handleInvalidLink') {
                        //internal method
                        continue;
                    }
                    $this->handleMethods[] = $methodName;
                }
                if (preg_match('~^createComponent[a-z0-9]+~i', $methodName)) {
                    $method->setAccessible(TRUE);
                    $form = $method->invoke($service);
                    if ($form instanceof \Nette\Application\UI\Form) {
                        $this->componentMethods[$methodName] = $form;
                    }
                }
            }
            $testClassName = $rc->getShortName() . 'Test';
            $testClass = new PhpGenerator\ClassType($testClassName);
            $testClass->setExtends('\\Tester\\TestCase');
            $testClass->addTrait('\\Testbench\\TPresenter');
            $testClass->addComment('@testCase');
            foreach ($this->renderMethods as $testMethod => $testMethodType) {
                $generatedMethod = $testClass->addMethod('test' . ucfirst($testMethod));
                $destination = $presenterFactory->unformatPresenterClass($rc->getName()) . ':';
                $destination .= lcfirst(preg_replace('~^(action|render)([a-z]+)~i', '$2', $testMethod));
                $extra = NULL;
                if (is_array($testMethodType)) {
                    /** @var \Exception|\Nette\Application\IResponse $extra */
                    $extra = $testMethodType[1];
                    $testMethodType = $testMethodType[0];
                    //FIXME: fuj, hnus
                }
                switch ($testMethodType) {
                    case 'rss':
                        $generatedMethod->addBody('$this->checkRss(?);', [$destination]);
                        break;
                    case 'sitemap':
                        $generatedMethod->addBody('$this->checkSitemap(?);', [$destination]);
                        break;
                    case 'action':
                        if ($extra instanceof \Nette\Application\Responses\RedirectResponse) {
                            $url = new \Nette\Http\Url($extra->getUrl());
                            $generatedMethod->addBody('$this->checkRedirect(?, ?);', [$destination, $url->getPath()]);
                        } elseif ($extra instanceof \Nette\Application\Responses\JsonResponse) {
                            $generatedMethod->addBody('$this->checkJson(?);', [$destination]);
                        } else {
                            if ($extra[0]) {
                                $generatedMethod->addBody('//FIXME: parameters may not be correct');
                                $generatedMethod->addBody("\$this->checkAction(?, ?);\n", [$destination, $extra[0]]);
                                $generatedMethod->addBody('$this->checkAction(?, ?);', [$destination, $extra[1]]);
                            } else {
                                $generatedMethod->addBody('$this->checkAction(?);', [$destination]);
                            }
                        }
                        break;
                    case 'exception':
                        $this->generateExceptionBody($generatedMethod, $destination, $extra);
                        break;
                }
            }
            foreach ($this->handleMethods as $testMethod) {
                $destination = $presenterFactory->unformatPresenterClass($rc->getName());
                $action = lcfirst(preg_replace('~^handle([a-z]+)~i', '$1', $testMethod));
//.........这里部分代码省略.........
开发者ID:mrtnzlml,项目名称:testbench,代码行数:101,代码来源:TestsGenerator.php

示例6: onGenerate

 public function onGenerate(AbstractMetaSpec $spec, MetaSpecMatcher $matcher, Type $type, ClassType $class)
 {
     $namespace = $class->getNamespace();
     // extend base class
     $namespace->addUse($type->getName(), null, $typeAlias);
     $class->addExtend($type->getName());
     $class->addComment("Meta class for \\{$type->getName()}")->addComment("")->addComment("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")->addComment("!!!                                                     !!!")->addComment("!!!   THIS CLASS HAS BEEN AUTO-GENERATED, DO NOT EDIT   !!!")->addComment("!!!                                                     !!!")->addComment("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
     // constructor
     $constructor = $class->addMethod("__construct");
     $constructor->addComment("Constructor")->addBody("self::\$instance = \$this; // avoids cyclic dependency stack overflow");
     if ($type->getConstructor()) {
         if ($type->getConstructor()->isPublic()) {
             $constructor->setVisibility("public");
         } elseif ($type->getConstructor()->isProtected()) {
             $constructor->setVisibility("protected");
         } elseif ($type->getConstructor()->isPrivate()) {
             $constructor->setVisibility("private");
         }
     } else {
         $constructor->setVisibility("private");
     }
     // implement base interface
     $namespace->addUse("Skrz\\Meta\\MetaInterface", null, $metaInterfaceAlias);
     $class->addImplement("Skrz\\Meta\\MetaInterface");
     // getInstance() method
     $instance = $class->addProperty("instance");
     $instance->setStatic(true);
     $instance->setVisibility("private");
     $instance->addComment("@var {$class->getName()}");
     $getInstance = $class->addMethod("getInstance");
     $getInstance->setStatic(true);
     $getInstance->addComment("Returns instance of this meta class")->addComment("")->addComment("@return {$class->getName()}");
     $getInstance->addBody("if (self::\$instance === null) {")->addBody("\tnew self(); // self::\$instance assigned in __construct")->addBody("}")->addBody("return self::\$instance;");
     // create() method
     $create = $class->addMethod("create");
     $create->setStatic(true);
     $create->addComment("Creates new instance of \\{$type->getName()}")->addComment("")->addComment("@throws \\InvalidArgumentException")->addComment("")->addComment("@return {$typeAlias}");
     $create->addBody("switch (func_num_args()) {");
     $maxArguments = 8;
     $constructMethod = $type->getConstructor();
     for ($i = 0; $i <= $maxArguments; ++$i) {
         $create->addBody("\tcase {$i}:");
         if ($constructMethod && $i < $constructMethod->getNumberOfRequiredParameters()) {
             $create->addBody("\t\tthrow new \\InvalidArgumentException('At least {$constructMethod->getNumberOfRequiredParameters()} arguments have to be supplied.');");
         } else {
             $args = array();
             for ($j = 0; $j < $i; ++$j) {
                 $args[] = "func_get_arg({$j})";
             }
             $create->addBody("\t\treturn new {$typeAlias}(" . implode(", ", $args) . ");");
         }
     }
     $create->addBody("\tdefault:");
     $create->addBody("\t\tthrow new \\InvalidArgumentException('More than {$maxArguments} arguments supplied, please be reasonable.');");
     $create->addBody("}");
     // reset() method
     $reset = $class->addMethod("reset");
     $reset->setStatic(true);
     $reset->addComment("Resets properties of \\{$type->getName()} to default values\n")->addComment("")->addComment("@param {$typeAlias} \$object")->addComment("")->addComment("@throws \\InvalidArgumentException")->addComment("")->addComment("@return void");
     $reset->addParameter("object");
     $reset->addBody("if (!(\$object instanceof {$typeAlias})) {")->addBody("\tthrow new \\InvalidArgumentException('You have to pass object of class {$type->getName()}.');")->addBody("}");
     foreach ($type->getProperties() as $property) {
         if ($property->hasAnnotation("Skrz\\Meta\\Transient")) {
             continue;
         }
         if ($property->isPrivate()) {
             throw new MetaException("Private property '{$type->getName()}::\${$property->getName()}'. " . "Either make the property protected/public if you need to process it, " . "or mark it using @Transient annotation.");
         }
         $reset->addBody("\$object->{$property->getName()} = " . var_export($property->getDefaultValue(), true) . ";");
     }
     // hash() method
     $hash = $class->addMethod("hash");
     $hash->setStatic(true);
     $hash->addComment("Computes hash of \\{$type->getName()}")->addComment("")->addComment("@param object \$object")->addComment("@param string|resource \$algoOrCtx")->addComment("@param bool \$raw")->addComment("")->addComment("@return string|void");
     $hash->addParameter("object");
     $hash->addParameter("algoOrCtx")->setDefaultValue("md5")->setOptional(true);
     $hash->addParameter("raw")->setDefaultValue(false)->setOptional(true);
     $hash->addBody("if (is_string(\$algoOrCtx)) {")->addBody("\t\$ctx = hash_init(\$algoOrCtx);")->addBody("} else {")->addBody("\t\$ctx = \$algoOrCtx;")->addBody("}")->addBody("");
     foreach ($type->getProperties() as $property) {
         if ($property->hasAnnotation("Skrz\\Meta\\Transient")) {
             continue;
         }
         if ($property->hasAnnotation("Skrz\\Meta\\Hash")) {
             continue;
         }
         $objectPath = "\$object->{$property->getName()}";
         $hash->addBody("if (isset({$objectPath})) {");
         $hash->addBody("\thash_update(\$ctx, " . var_export($property->getName(), true) . ");");
         $baseType = $property->getType();
         $indent = "\t";
         $before = "";
         $after = "";
         for ($i = 0; $baseType instanceof ArrayType; ++$i) {
             $arrayType = $baseType;
             $baseType = $arrayType->getBaseType();
             $before .= "{$indent}foreach ({$objectPath} instanceof \\Traversable ? {$objectPath} : (array){$objectPath} as \$v{$i}) {\n";
             $after = "{$indent}}\n" . $after;
             $indent .= "\t";
             $objectPath = "\$v{$i}";
         }
//.........这里部分代码省略.........
开发者ID:jakubkulhan,项目名称:meta,代码行数:101,代码来源:BaseModule.php

示例7: generateTableGeneratedHyperRow

 /**
  * @param string $tableName
  * @param array $columns
  * @return void
  */
 protected function generateTableGeneratedHyperRow($tableName, $columns)
 {
     $classFqn = $this->config['classes']['row']['generated'];
     $classFqn = Helpers::substituteClassWildcard($classFqn, $tableName);
     $className = Helpers::extractClassName($classFqn);
     $classNamespace = Helpers::extractNamespace($classFqn);
     $extendsFqn = $this->config['classes']['row']['base'];
     $extends = Helpers::formatClassName($extendsFqn, $classNamespace);
     $class = new ClassType($className);
     $class->setExtends($extends);
     // Add property annotations based on columns
     foreach ($columns as $column => $type) {
         if (in_array($type, [IStructure::FIELD_DATETIME, IStructure::FIELD_TIME, IStructure::FIELD_DATE, IStructure::FIELD_UNIX_TIMESTAMP])) {
             $type = '\\Nette\\Utils\\DateTime';
         }
         $class->addComment("@property-read {$type} \${$column}");
     }
     // Generate methods.row.getter
     foreach ((array) $this->config['methods']['row']['getter'] as $methodTemplate) {
         // Generate column getters
         foreach ($columns as $column => $type) {
             if (in_array($type, [IStructure::FIELD_DATETIME, IStructure::FIELD_TIME, IStructure::FIELD_DATE, IStructure::FIELD_UNIX_TIMESTAMP])) {
                 $type = '\\Nette\\Utils\\DateTime';
             }
             $methodName = Helpers::substituteMethodWildcard($methodTemplate, $column);
             $returnType = $type;
             $class->addMethod($methodName)->addBody('return $this->activeRow->?;', [$column])->addComment("@return {$returnType}");
             // Add property annotation
             if (Strings::startsWith($methodName, 'get')) {
                 $property = Strings::firstLower(Strings::substring($methodName, 3));
                 if ($property != $column) {
                     $class->addComment("@property-read {$type} \${$property}");
                 }
             }
         }
     }
     // Generate methods.row.ref
     foreach ((array) $this->config['methods']['row']['ref'] as $methodTemplate) {
         // Generate 'ref' methods
         foreach ($this->structure->getBelongsToReference($tableName) as $referencingColumn => $referencedTable) {
             if (is_array($this->config['tables']) && !in_array($referencedTable, $this->config['tables'])) {
                 continue;
             }
             $result = Helpers::underscoreToCamelWithoutPrefix(Strings::replace($referencingColumn, '~_id$~'), $tableName);
             $methodName = Helpers::substituteMethodWildcard($methodTemplate, $result);
             $returnType = $this->getTableClass('row', $referencedTable, $classNamespace);
             $class->addMethod($methodName)->addBody('return $this->ref(?, ?);', [$referencedTable, $referencingColumn])->addComment("@return {$returnType}");
             // Add property annotations
             if (Strings::startsWith($methodName, 'get')) {
                 $property = Strings::firstLower(Strings::substring($methodName, 3));
                 $class->addComment("@property-read {$returnType} \${$property}");
             }
         }
     }
     // Generate methods.row.related
     foreach ((array) $this->config['methods']['row']['related'] as $methodTemplate) {
         // Generate 'related' methods
         foreach ($this->structure->getHasManyReference($tableName) as $relatedTable => $referencingColumns) {
             if (is_array($this->config['tables']) && !in_array($relatedTable, $this->config['tables'])) {
                 continue;
             }
             foreach ($referencingColumns as $referencingColumn) {
                 // Omit longest common prefix between $relatedTable and (this) $tableName
                 $result = Helpers::underscoreToCamelWithoutPrefix($relatedTable, $tableName);
                 if (count($referencingColumns) > 1) {
                     $suffix = 'As' . Helpers::underscoreToCamel(Strings::replace($referencingColumn, '~_id$~'));
                 } else {
                     $suffix = NULL;
                 }
                 $methodName = Helpers::substituteMethodWildcard($methodTemplate, $result, $suffix);
                 $returnType = $this->getTableClass('selection', $relatedTable, $classNamespace);
                 $class->addMethod($methodName)->addBody('return $this->related(?, ?);', [$relatedTable, $referencingColumn])->addComment("@return {$returnType}");
                 // Add property annotations
                 if (Strings::startsWith($methodName, 'get')) {
                     $property = Strings::firstLower(Strings::substring($methodName, 3));
                     $class->addComment("@property-read {$returnType} \${$property}");
                 }
             }
         }
     }
     $code = implode("\n\n", ['<?php', "/**\n * This is a generated file. DO NOT EDIT. It will be overwritten.\n */", "namespace {$classNamespace};", $class]);
     $dir = $this->config['dir'] . '/' . 'tables' . '/' . $tableName;
     $file = $dir . '/' . $className . '.php';
     $this->writeIfChanged($file, $code);
 }
开发者ID:filsedla,项目名称:hyperrow,代码行数:90,代码来源:Generator.php


注:本文中的Nette\PhpGenerator\ClassType::addComment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。