src/DavidePastore/ParisModelGenerator/ParisGeneratorCommand.php
private function generateCode($className, $primaryKey){
		$tags = $this->config->getTags();
		
		$class    = new ClassGenerator();
		$docblock = DocBlockGenerator::fromArray(array(
			'shortDescription' => ucfirst($className) .' model class',
			'longDescription'  => 'This is a model class generated with DavidePastore\ParisModelGenerator.',
			'tags'             => $tags
		));
		
		$idColumn = new PropertyGenerator('_id_column');
		
		$idColumn
			->setStatic(true)
			->setDefaultValue($primaryKey);
		
		$table = new PropertyGenerator('_table');
		
		$table
			->setStatic(true)
			->setDefaultValue($className);
			
		$tableUseShortName = new PropertyGenerator('_table_use_short_name');
		
		$tableUseShortName
			->setStatic(true)
			->setDefaultValue(true);
		
		$namespace = $this->config->getNamespace();
		$extendedClass = '\Model';
		if(isset($namespace) && !empty($namespace)){
			$class->setNamespaceName($this->config->getNamespace());
		}
		
		$class
			->setName(ucfirst($className))
			->setDocblock($docblock)
			->setExtendedClass($extendedClass)
			->addProperties(array(
				$idColumn,
				$table,
				$tableUseShortName
			));
		
		
			
		$file = FileGenerator::fromArray(array(
			'classes'  => array($class),
			'docblock' => DocBlockGenerator::fromArray(array(
				'shortDescription' => ucfirst($className) . ' class file',
				'longDescription'   => null,
				'tags'             => $tags
			))
		));
		
		$generatedCode = $file->generate();
		
		$directory = $this->config->getDestinationFolder() . $namespace;
		
		if(!file_exists($directory)){
			mkdir($directory, 0777, true);
		}
		
		$filePath = $directory . "/" . $class->getName() . ".php";
		
		if(file_exists($filePath) && !$this->force){
			$helper = $this->getHelper('question');
			$realPath = realpath($filePath);
			$this->output->writeln("\n");
			$question = new ConfirmationQuestion('Do you want to overwrite the file "' . $realPath . '"?', false);

			if ($helper->ask($this->input, $this->output, $question)) {
				$this->writeInFile($filePath, $generatedCode);
			}
		}
		else {
			$this->writeInFile($filePath, $generatedCode);
		}
	}
private function generateCode($className, $primaryKey){
		$tags = $this->config->getTags();
		
		$class    = new ClassGenerator();
		$docblock = DocBlockGenerator::fromArray(array(
			'shortDescription' => ucfirst($className) .' model class',
			'longDescription'  => 'This is a model class generated with DavidePastore\ParisModelGenerator.',
			'tags'             => $tags
		));
		
		$idColumn = new PropertyGenerator('_id_column');
		
		$idColumn
			->setStatic(true)
			->setDefaultValue($primaryKey);
		
		$table = new PropertyGenerator('_table');
		
		$table
			->setStatic(true)
			->setDefaultValue($className);
			
		$tableUseShortName = new PropertyGenerator('_table_use_short_name');
		
		$tableUseShortName
			->setStatic(true)
			->setDefaultValue(true);
		
		$namespace = $this->config->getNamespace();
		$extendedClass = '\Model';
		if(isset($namespace) && !empty($namespace)){
			$class->setNamespaceName($this->config->getNamespace());
		}
		
		$class
			->setName(ucfirst($className))
			->setDocblock($docblock)
			->setExtendedClass($extendedClass)
			->addProperties(array(
				$idColumn,
				$table,
				$tableUseShortName
			));
		
		
			
		$file = FileGenerator::fromArray(array(
			'classes'  => array($class),
			'docblock' => DocBlockGenerator::fromArray(array(
				'shortDescription' => ucfirst($className) . ' class file',
				'longDescription'   => null,
				'tags'             => $tags
			))
		));
		
		$generatedCode = $file->generate();
		
		$directory = $this->config->getDestinationFolder() . $namespace;
		
		if(!file_exists($directory)){
			mkdir($directory, 0777, true);
		}
		
		$filePath = $directory . "/" . $class->getName() . ".php";
		
		if(file_exists($filePath) && !$this->force){
			$helper = $this->getHelper('question');
			$realPath = realpath($filePath);
			$this->output->writeln("\n");
			$question = new ConfirmationQuestion('Do you want to overwrite the file "' . $realPath . '"?', false);

			if ($helper->ask($this->input, $this->output, $question)) {
				$this->writeInFile($filePath, $generatedCode);
			}
		}
		else {
			$this->writeInFile($filePath, $generatedCode);
		}
	}
private function generateCode ( $ className , $ primaryKey ) { $ tags = $ this -> config -> getTags ( ) ; $ class = new ClassGenerator ( ) ; $ docblock = DocBlockGenerator :: fromArray ( array ( 'shortDescription' => ucfirst ( $ className ) . ' model class' , 'longDescription' => 'This is a model class generated with DavidePastore\ParisModelGenerator.' , 'tags' => $ tags ) ) ; $ idColumn = new PropertyGenerator ( '_id_column' ) ; $ idColumn -> setStatic ( true ) -> setDefaultValue ( $ primaryKey ) ; $ table = new PropertyGenerator ( '_table' ) ; $ table -> setStatic ( true ) -> setDefaultValue ( $ className ) ; $ tableUseShortName = new PropertyGenerator ( '_table_use_short_name' ) ; $ tableUseShortName -> setStatic ( true ) -> setDefaultValue ( true ) ; $ namespace = $ this -> config -> getNamespace ( ) ; $ extendedClass = '\Model' ; if ( isset ( $ namespace ) && ! empty ( $ namespace ) ) { $ class -> setNamespaceName ( $ this -> config -> getNamespace ( ) ) ; } $ class -> setName ( ucfirst ( $ className ) ) -> setDocblock ( $ docblock ) -> setExtendedClass ( $ extendedClass ) -> addProperties ( array ( $ idColumn , $ table , $ tableUseShortName ) ) ; $ file = FileGenerator :: fromArray ( array ( 'classes' => array ( $ class ) , 'docblock' => DocBlockGenerator :: fromArray ( array ( 'shortDescription' => ucfirst ( $ className ) . ' class file' , 'longDescription' => null , 'tags' => $ tags ) ) ) ) ; $ generatedCode = $ file -> generate ( ) ; $ directory = $ this -> config -> getDestinationFolder ( ) . $ namespace ; if ( ! file_exists ( $ directory ) ) { mkdir ( $ directory , 0777 , true ) ; } $ filePath = $ directory . "/" . $ class -> getName ( ) . ".php" ; if ( file_exists ( $ filePath ) && ! $ this -> force ) { $ helper = $ this -> getHelper ( 'question' ) ; $ realPath = realpath ( $ filePath ) ; $ this -> output -> writeln ( "\n" ) ; $ question = new ConfirmationQuestion ( 'Do you want to overwrite the file "' . $ realPath . '"?' , false ) ; if ( $ helper -> ask ( $ this -> input , $ this -> output , $ question ) ) { $ this -> writeInFile ( $ filePath , $ generatedCode ) ; } } else { $ this -> writeInFile ( $ filePath , $ generatedCode ) ; } }
Generate the code for the given className and primaryKey and write it in a file.
@param string $className The class name.
@param string $primaryKey The primary key.
Generate the code for the given className and primaryKey and write it in a file .