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


PHP ClassType::setFinal方法代码示例

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


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

示例1: generateClassType

 /**
  * [generateClassType description].
  *
  * @param string      $properties       elementi possibili 'fields', 'extend', 'implements'
  * @param array       $typesReference   [description]
  * @param array       $typesDescription [description]
  * @param ClassConfig $config           [description]
  */
 public function generateClassType(array $properties, $typesReference, $typesDescription, ClassConfig $config)
 {
     $phpNamespace = $this->currentClass->getNamespace();
     if ($config->isInterface) {
         $this->info('Passo a interfaccia', [$this->currentClass->getName()]);
         $docs = $this->currentClass->getComment();
         $this->currentClass = $this->currentFile->addInterface($phpNamespace->getName() . '\\' . ucfirst($this->currentClass->getName()));
         $this->currentClass->setComment($docs);
         $this->info('Check haveConstructor, in caso metto a false', [$config->haveConstructor]);
         $config->haveConstructor = false;
     }
     $this->info('Generate', ['class' => $this->currentClass->getName(), 'namespace' => $phpNamespace->getName(), 'comment' => $this->currentClass->getComment(), 'properties' => $properties]);
     // extend class
     if (array_key_exists('extend', $properties)) {
         $extendClassName = $properties['extend'];
         $this->info('Aggiungo extend', ['class' => $this->currentClass->getName(), 'extend' => $extendClassName]);
         $this->currentClass->setExtends($extendClassName);
         $this->currentClass->getNamespace()->addUse($extendClassName);
     }
     // implements class
     if (array_key_exists('implements', $properties)) {
         $implementsList = [];
         if (!is_array($properties['implements'])) {
             $implementsList[] = $properties['implements'];
         } else {
             $implementsList = array_merge($implementsList, $properties['implements']);
         }
         $this->currentClass->setImplements($implementsList);
         foreach ($implementsList as $implementUse) {
             $this->info('Aggiungo implement', ['class' => $this->currentClass->getName(), 'implements' => $implementUse]);
             $this->currentClass->getNamespace()->addUse($implementUse);
         }
     }
     // traits
     if (array_key_exists('traits', $properties)) {
         if (is_array($properties['traits'])) {
             foreach ($properties['traits'] as $trait) {
                 $this->addTrait($trait, $typesReference);
             }
         } else {
             $traitObject = $properties['traits'];
             $this->addTrait($traitObject, $typesReference);
         }
     }
     if ($config->isFinalClass) {
         $this->currentClass->setFinal(true);
     }
     $first = true;
     if (array_key_exists('fields', $properties)) {
         /** @var $methodConstructor \Nette\PhpGenerator\Method */
         $methodConstructor = null;
         if ($config->haveConstructor) {
             $methodConstructor = $this->addConstructor();
         }
         $body = '';
         foreach ($properties['fields'] as $name => $fieldProperties) {
             $isStatic = false;
             $isAutoinizialize = false;
             $defaultValue = null;
             if (array_key_exists('static', $fieldProperties)) {
                 $isStatic = $fieldProperties['static'];
             }
             if (array_key_exists('autoinizialize', $fieldProperties)) {
                 $isAutoinizialize = boolval($fieldProperties['autoinizialize']);
             }
             if (array_key_exists('default', $fieldProperties)) {
                 $defaultValue = $fieldProperties['default'];
             }
             if (!$isAutoinizialize) {
                 if (null != $defaultValue) {
                     //TODO: usare "primitive type per determinare il corretto IF"
                     //FARE UN TEST PER I BOOLEAN
                     //@see https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/
                     $body .= 'if ( empty($' . $name . ') ) { ' . "\n";
                     if ($isStatic) {
                         $body .= ' self::$';
                     } else {
                         $body .= ' $this->';
                     }
                     $body .= $name . ' = ' . $defaultValue . ';' . "\n";
                     $body .= '} else {';
                     if ($isStatic) {
                         $body .= ' self::$';
                     } else {
                         $body .= ' $this->';
                     }
                     $body .= $name . ' = $' . $name . ';' . "\n";
                     $body .= '}' . "\n";
                 } else {
                     if (!$isStatic) {
                         $body .= ' $this->' . $name . ' = $' . $name . ';' . "\n";
                     }
//.........这里部分代码省略.........
开发者ID:yoghi,项目名称:madda,代码行数:101,代码来源:ClassGenerator.php


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