TraitUsageGenerator
extends AbstractGenerator
in package
implements
TraitUsageInterface
Table of Contents
Interfaces
Constants
- LINE_FEED = "\n"
- Line feed to use in place of EOL
Properties
- $classGenerator : ClassGenerator
- $indentation : string
- $isSourceDirty : bool
- $sourceContent : string|null
- TODO: Type should be changed to "string" in the next major version. Nullable for BC
- $traitAliases : array<string|int, mixed>
- $traitOverrides : array<string|int, mixed>
- $traits : array<string|int, mixed>
- $uses : array<string|int, mixed>
Methods
- __construct() : mixed
- addTrait() : self
- Add trait takes an array of trait options or string as arguments.
- addTraitAlias() : mixed
- Add a trait alias. This will be used to generate the AS portion of the use statement.
- addTraitOverride() : mixed
- Add a trait method override. This will be used to generate the INSTEADOF portion of the use statement.
- addTraits() : self
- Add multiple traits. Trait can be an array of trait names or array of trait configurations
- addUse() : self
- Add a class to "use" classes
- generate() : mixed
- getIndentation() : string
- getSourceContent() : string|null
- getTraitAliases() : array<string|int, mixed>
- getTraitOverrides() : array<string|int, mixed>
- Return trait overrides
- getTraits() : array<string|int, mixed>
- Get a list of trait names
- getUseAlias() : string|null
- Returns the alias of the provided FQCN
- getUses() : array<string|int, mixed>
- Returns the "use" classes
- hasTrait() : bool
- Check to see if the class has a trait defined
- hasUse() : bool
- hasUseAlias() : bool
- isSourceDirty() : bool
- isUseAlias() : bool
- Returns true if the alias is defined in the use list
- removeTrait() : mixed
- Remove a trait by its name
- removeTraitOverride() : self
- Remove an override for a given trait::method
- removeUse() : TraitUsageGenerator
- removeUseAlias() : TraitUsageGenerator
- setIndentation() : AbstractGenerator
- setOptions() : AbstractGenerator
- setSourceContent() : AbstractGenerator
- setSourceDirty() : AbstractGenerator
Constants
LINE_FEED
Line feed to use in place of EOL
public
mixed
LINE_FEED
= "\n"
Properties
$classGenerator
protected
ClassGenerator
$classGenerator
$indentation
protected
string
$indentation
= ' '
4 spaces by default
$isSourceDirty
protected
bool
$isSourceDirty
= true
$sourceContent
TODO: Type should be changed to "string" in the next major version. Nullable for BC
protected
string|null
$sourceContent
= null
$traitAliases
protected
array<string|int, mixed>
$traitAliases
= []
Array of trait aliases
$traitOverrides
protected
array<string|int, mixed>
$traitOverrides
= []
Array of trait overrides
$traits
protected
array<string|int, mixed>
$traits
= []
Tags
$uses
protected
array<string|int, mixed>
$uses
= []
Array of string names
Methods
__construct()
public
__construct(ClassGenerator $classGenerator) : mixed
Parameters
- $classGenerator : ClassGenerator
addTrait()
Add trait takes an array of trait options or string as arguments.
public
addTrait(mixed $trait) : self
Parameters
- $trait : mixed
Tags
Return values
selfaddTraitAlias()
Add a trait alias. This will be used to generate the AS portion of the use statement.
public
addTraitAlias(mixed $method, mixed $alias[, mixed $visibility = null ]) : mixed
Parameters
- $method : mixed
-
String or Array
- $alias : mixed
- $visibility : mixed = null
Tags
addTraitOverride()
Add a trait method override. This will be used to generate the INSTEADOF portion of the use statement.
public
addTraitOverride(mixed $method, mixed $traitsToReplace) : mixed
Parameters
- $method : mixed
- $traitsToReplace : mixed
Tags
addTraits()
Add multiple traits. Trait can be an array of trait names or array of trait configurations
public
addTraits(array<string|int, mixed> $traits) : self
Parameters
- $traits : array<string|int, mixed>
-
Array of string names or configurations (@see addTrait)
Tags
Return values
selfaddUse()
Add a class to "use" classes
public
addUse(mixed $use[, mixed $useAlias = null ]) : self
Parameters
- $use : mixed
- $useAlias : mixed = null
Tags
Return values
selfgenerate()
public
generate() : mixed
Tags
getIndentation()
public
getIndentation() : string
Return values
stringgetSourceContent()
public
getSourceContent() : string|null
Return values
string|nullgetTraitAliases()
public
getTraitAliases() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>getTraitOverrides()
Return trait overrides
public
getTraitOverrides() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>getTraits()
Get a list of trait names
public
getTraits() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>getUseAlias()
Returns the alias of the provided FQCN
public
getUseAlias(string $use) : string|null
Parameters
- $use : string
Return values
string|nullgetUses()
Returns the "use" classes
public
getUses() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>hasTrait()
Check to see if the class has a trait defined
public
hasTrait(mixed $traitName) : bool
Parameters
- $traitName : mixed
Tags
Return values
boolhasUse()
public
hasUse(string $use) : bool
Parameters
- $use : string
Return values
boolhasUseAlias()
public
hasUseAlias(string $use) : bool
Parameters
- $use : string
Return values
boolisSourceDirty()
public
isSourceDirty() : bool
Return values
boolisUseAlias()
Returns true if the alias is defined in the use list
public
isUseAlias(string $alias) : bool
Parameters
- $alias : string
Return values
boolremoveTrait()
Remove a trait by its name
public
removeTrait(mixed $traitName) : mixed
Parameters
- $traitName : mixed
Tags
removeTraitOverride()
Remove an override for a given trait::method
public
removeTraitOverride(mixed $method[, mixed $overridesToRemove = null ]) : self
Parameters
- $method : mixed
- $overridesToRemove : mixed = null
Tags
Return values
selfremoveUse()
public
removeUse(string $use) : TraitUsageGenerator
Parameters
- $use : string
Return values
TraitUsageGeneratorremoveUseAlias()
public
removeUseAlias(string $use) : TraitUsageGenerator
Parameters
- $use : string
Return values
TraitUsageGeneratorsetIndentation()
public
setIndentation(string $indentation) : AbstractGenerator
Parameters
- $indentation : string
Return values
AbstractGeneratorsetOptions()
public
setOptions(array<string|int, mixed>|Traversable $options) : AbstractGenerator
Parameters
- $options : array<string|int, mixed>|Traversable
Tags
Return values
AbstractGeneratorsetSourceContent()
public
setSourceContent(string|null $sourceContent) : AbstractGenerator
Parameters
- $sourceContent : string|null
Return values
AbstractGeneratorsetSourceDirty()
public
setSourceDirty([bool $isSourceDirty = true ]) : AbstractGenerator
Parameters
- $isSourceDirty : bool = true