當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ClassType::setImplements方法代碼示例

本文整理匯總了PHP中Nette\PhpGenerator\ClassType::setImplements方法的典型用法代碼示例。如果您正苦於以下問題:PHP ClassType::setImplements方法的具體用法?PHP ClassType::setImplements怎麽用?PHP ClassType::setImplements使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Nette\PhpGenerator\ClassType的用法示例。


在下文中一共展示了ClassType::setImplements方法的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::setImplements方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。