Incorporate
Handles the setup and installation process for a Laravel Neuro Corporation.
Incorporate is responsible for validating and processing a corporation's setup configuration (typically provided via a JSON setup file) and installing it by:
- Creating the necessary directory structure and files.
- Creating corresponding database models and migrations.
- Registering units, transitions, and models defined in the setup.
Table of Contents
Properties
- $charta : string
- The charta or foundational document for the corporation.
- $description : string
- A short description of the corporation.
- $errors : Collection
- A collection of errors encountered during setup.
- $models : Collection
- A collection of additional model configurations.
- $name : string
- The name of the corporation.
- $nameSpace : string
- The namespace for the corporation.
- $transitions : Collection
- A collection of transition definitions for the corporation.
- $units : Collection
- A collection of Unit objects associated with the corporation.
Methods
- __construct() : mixed
- Incorporate constructor.
- getCharta() : string
- Retrieves the corporation's charta.
- getDescription() : string
- Retrieves the corporation's description.
- getName() : string
- Retrieves the corporation's name.
- getNameSpace() : string
- Retrieves the corporation's namespace.
- getStub() : string
- Retrieves the content of a stub file for the corporation.
- install() : array<string|int, mixed>
- Installs the corporation by creating a NetworkCorporation record and generating necessary files.
- installFromJSON() : mixed
- Installs the corporation based on a JSON setup.
- prebuild() : bool
- Prebuilds the corporation setup file based on the given namespace and type.
- pushModel() : self
- Adds a model configuration to the corporation.
- pushTransition() : self
- Adds a transition definition to the corporation.
- pushUnit() : self
- Adds a Unit instance to the corporation.
- setCharta() : self
- Sets the charta for the corporation.
- setDescription() : self
- Sets the description for the corporation.
- setName() : self
- Sets the name of the corporation.
- setNameSpace() : self
- Sets the namespace for the corporation.
- validateProperty() : mixed
- Validates that a property exists in an object and is of the expected type.
Properties
$charta
The charta or foundational document for the corporation.
protected
string
$charta
$description
A short description of the corporation.
protected
string
$description
$errors
A collection of errors encountered during setup.
protected
Collection
$errors
$models
A collection of additional model configurations.
protected
Collection
$models
$name
The name of the corporation.
protected
string
$name
$nameSpace
The namespace for the corporation.
protected
string
$nameSpace
$transitions
A collection of transition definitions for the corporation.
protected
Collection
$transitions
$units
A collection of Unit objects associated with the corporation.
protected
Collection
$units
Methods
__construct()
Incorporate constructor.
public
__construct() : mixed
Initializes empty collections for units, transitions, models, and errors.
getCharta()
Retrieves the corporation's charta.
public
getCharta() : string
Return values
string —The charta.
getDescription()
Retrieves the corporation's description.
public
getDescription() : string
Return values
string —The description.
getName()
Retrieves the corporation's name.
public
getName() : string
Return values
string —The name of the corporation.
getNameSpace()
Retrieves the corporation's namespace.
public
getNameSpace() : string
Return values
string —The namespace.
getStub()
Retrieves the content of a stub file for the corporation.
public
static getStub(string $stub) : string
Looks for a stub file in the /resources/stubs/Corporation/ directory relative to the current directory.
Parameters
- $stub : string
-
The name of the stub file (without the .stub extension).
Return values
string —The contents of the stub file.
install()
Installs the corporation by creating a NetworkCorporation record and generating necessary files.
public
install() : array<string|int, mixed>
Creates a new NetworkCorporation record with the corporation's name, namespace, description, and charta. Then, it creates the required directories, models, migrations, and transition files based on the setup information. Returns an array of installation details.
Return values
array<string|int, mixed> —An array containing the corporation ID, name, description, units, transitions, and any errors.
installFromJSON()
Installs the corporation based on a JSON setup.
public
static installFromJSON([mixed $json = false ]) : mixed
Parses the provided JSON, validates required properties for the corporation, units, transitions, and models, and creates the necessary database models and files via Artisan commands. Returns an array with installation details.
Parameters
- $json : mixed = false
-
The JSON string containing the corporation setup.
Tags
Return values
mixed —An array containing corporation ID, name, description, units, transitions, and errors.
prebuild()
Prebuilds the corporation setup file based on the given namespace and type.
public
static prebuild(string $nameSpace[, IncorporatePrebuild $type = IncorporatePrebuild::JSON ]) : bool
Normalizes the provided namespace, selects the appropriate stub (JSON or PHP), and writes the setup file to the designated storage disk.
Parameters
- $nameSpace : string
-
The desired namespace for the corporation.
- $type : IncorporatePrebuild = IncorporatePrebuild::JSON
-
The type of setup file to create (JSON or PHP).
Tags
Return values
bool —True if the file was successfully created; false otherwise.
pushModel()
Adds a model configuration to the corporation.
public
pushModel(mixed $model) : self
Parameters
- $model : mixed
-
The model configuration.
Return values
selfpushTransition()
Adds a transition definition to the corporation.
public
pushTransition(mixed $transition) : self
Parameters
- $transition : mixed
-
The transition definition.
Return values
selfpushUnit()
Adds a Unit instance to the corporation.
public
pushUnit(Unit $unit) : self
Parameters
- $unit : Unit
-
The Unit to add.
Return values
selfsetCharta()
Sets the charta for the corporation.
public
setCharta(string $set) : self
Parameters
- $set : string
-
The charta.
Return values
selfsetDescription()
Sets the description for the corporation.
public
setDescription(string $set) : self
Parameters
- $set : string
-
The description.
Return values
selfsetName()
Sets the name of the corporation.
public
setName(string $set) : self
Parameters
- $set : string
-
The corporation's name.
Return values
selfsetNameSpace()
Sets the namespace for the corporation.
public
setNameSpace(string $set) : self
Parameters
- $set : string
-
The namespace.
Return values
selfvalidateProperty()
Validates that a property exists in an object and is of the expected type.
private
static validateProperty(object $object, string $propertyName, string $expectedType) : mixed
For enum types, it validates that the property value matches one of the enum cases, and converts the value to the enum instance.
Parameters
- $object : object
-
The object containing the property.
- $propertyName : string
-
The name of the property to validate.
- $expectedType : string
-
The expected type (or enum name) of the property.
Tags
Return values
mixed —The validated property value.