Neos\Kickstarter\Command\KickstartCommandController::modelCommand PHP Method

modelCommand() public method

This command generates a new domain model class. The fields are specified as a variable list of arguments with field name and type separated by a colon (for example "title:string" "size:int" "type:MyType").
public modelCommand ( string $packageKey, string $modelName, boolean $force = false ) : string
$packageKey string The package key of the package for the domain model
$modelName string The name of the new domain model class
$force boolean Overwrite any existing model.
return string
    public function modelCommand($packageKey, $modelName, $force = false)
    {
        $this->validatePackageKey($packageKey);
        if (!$this->packageManager->isPackageAvailable($packageKey)) {
            $this->outputLine('Package "%s" is not available.', array($packageKey));
            exit(2);
        }
        $this->validateModelName($modelName);
        $fieldsArguments = $this->request->getExceedingArguments();
        $fieldDefinitions = array();
        foreach ($fieldsArguments as $fieldArgument) {
            list($fieldName, $fieldType) = explode(':', $fieldArgument, 2);
            $fieldDefinitions[$fieldName] = array('type' => $fieldType);
            if (strpos($fieldType, 'array') !== false) {
                $fieldDefinitions[$fieldName]['typeHint'] = 'array';
            } elseif (strpos($fieldType, '\\') !== false) {
                if (strpos($fieldType, '<') !== false) {
                    $fieldDefinitions[$fieldName]['typeHint'] = substr($fieldType, 0, strpos($fieldType, '<'));
                } else {
                    $fieldDefinitions[$fieldName]['typeHint'] = $fieldType;
                }
            }
        }
        $generatedFiles = $this->generatorService->generateModel($packageKey, $modelName, $fieldDefinitions, $force);
        $this->outputLine(implode(PHP_EOL, $generatedFiles));
        $this->outputLine('As a new model was generated, don\'t forget to update the database schema with the respective doctrine:* commands.');
    }