/** * Registry for the Zend\Code package. * * @param FileGenerator $fileCodeGenerator * @param string $fileName * @throws RuntimeException */ public static function registerFileCodeGenerator(FileGenerator $fileCodeGenerator, $fileName = null) { if ($fileName === null) { $fileName = $fileCodeGenerator->getFilename(); } if ($fileName == '') { throw new RuntimeException('FileName does not exist.'); } // cannot use realpath since the file might not exist, but we do need to have the index // in the same DIRECTORY_SEPARATOR that realpath would use: $fileName = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $fileName); static::$fileCodeGenerators[$fileName] = $fileCodeGenerator; }
/** * @inheritDoc */ public function writeClass(FileGenerator $fileGenerator) { file_put_contents($fileGenerator->getFilename(), $this->replaceNamespace($fileGenerator)); }
/** * Generate Madel class from metadata * * @param stdClass $metadata * @return Generator\ClassGenerator|null */ protected function generateModelFromMetadata($metadata) { $console = $this->getServiceLocator()->get('console'); $name = $metadata->Name; $ucName = ucfirst($name); // Create Api Class $class = new Generator\ClassGenerator($ucName, 'Mailjet\\Model'); $class->setImplementedInterfaces(array('ModelInterface'))->setDocBlock(new Generator\DocBlockGenerator($class->getName() . ' Model', $metadata->Description, array())); $this->addProperties($class, $metadata->Properties); // Create and Write Api Class File $file = new Generator\FileGenerator(); $file->setClass($class); $file->setDocBlock(new Generator\DocBlockGenerator('MailJet Model', self::LICENSE)); $file->setFilename(dirname(__DIR__) . '/Model/' . $class->getName() . '.php'); if (file_put_contents($file->getFilename(), $file->generate())) { $console->writeLine(sprintf("The Model '%s' has been created.", $class->getName()), Color::GREEN); return $class; } else { $console->writeLine(sprintf("There was an error during '%s' Model creation.", $class->getName()), Color::RED); } return $class; }
/** * @inheritDoc */ public function writeClass(FileGenerator $fileGenerator) { file_put_contents($fileGenerator->getFilename(), $fileGenerator->generate()); }
/** * Function writeClass. * * @param ClassGenerator $class * @param Filesystem $filesystem * @param $destinationDir * * @return string|false * * @throws CliException */ protected function writeClass(ClassGenerator $class, Filesystem $filesystem, $destinationDir) { $className = $class->getName(); $file = new FileGenerator(['fileName' => $className . '.php', 'classes' => [$class]]); $contents = $file->generate(); $relativePath = $destinationDir . DIRECTORY_SEPARATOR . $file->getFilename(); if ($filesystem->has($relativePath)) { throw new CliException(sprintf('Could not generate migration. File already exists: %s', $relativePath)); } $result = $filesystem->write($relativePath, $contents); return $result ? $relativePath : false; }