October\Rain\Halcyon\Model

Source: ~/vendor/october/rain/src/Halcyon/Model.php

Extends:

Implements:

  • ArrayAccess
  • Illuminate\Contracts\Support\Arrayable
  • Illuminate\Contracts\Support\Jsonable
  • JsonSerializable

This is a base template object. Equivalent to a Model in ORM.

Public properties

public array $attributes

The model's attributes, saved to the settings area.

public bool $exists

Indicates if the model exists.

Show inherited public properties

Inherited public properties

Protected properties

protected string $datasource

The data source for the model, a directory path.

protected string $dirName

The container name associated with the model, eg: pages.

protected array $original

The model attribute's original state.

protected array $appends

The accessors to append to the model's array form.

protected array $fillable

The attributes that are mass assignable.

protected array $purgeable

List of attribute names which are not considered "settings".

protected array $allowedExtensions

Allowable file extensions.

protected string $defaultExtension

Default file extension.

protected bool $isCompoundObject

Model supports code and settings sections.

protected bool $wrapCode

Wrap code section in PHP tags.

protected int $maxNesting

The maximum allowed path nesting level. The default value is 2, meaning that files can only exist in the root directory, or in a subdirectory. Set to null if any level is allowed.

protected boolean $loadedFromCache

Indicated whether the object was loaded from the cache.

protected array $observables

User exposed observable events.

protected static Illuminate\Cache\CacheManager $cache

The cache manager instance.

protected static October\Rain\Halcyon\Datasource\ResolverInterface $resolver

The datasource resolver instance.

protected static Illuminate\Contracts\Events\Dispatcher $dispatcher

The event dispatcher instance.

protected static array $mutatorCache

The cache of the mutated attributes for each class.

protected static array $eventsBooted

The array of models booted events.

protected static array $booted

The array of booted models.

protected array $emitterSingleEventCollection

Collection of registered events to be fired once only.

protected array $emitterEventCollection

Collection of registered events.

protected array $emitterEventSorted

Sorted collection of events.

Show inherited protected properties

Inherited protected properties

Public methods

public mixed __call(string $method, array $parameters)

Handle dynamic method calls into the model.

Parameters
  • string $method
  • array $parameters

public static mixed __callStatic(string $method, array $parameters)

Handle dynamic static method calls into the method.

Parameters
  • string $method
  • array $parameters

public void __construct(array $attributes=array())

Create a new Halcyon model instance.

Parameters
  • array $attributes

public mixed __get(string $key)

Dynamically retrieve attributes on the model.

Parameters
  • string $key

public bool __isset(string $key)

Determine if an attribute exists on the model.

Parameters
  • string $key

public void __set(string $key, mixed $value)

Dynamically set attributes on the model.

Parameters
  • string $key
  • mixed $value

public string __toString()

Convert the model to its string representation.

public void __unset(string $key)

Unset an attribute on the model.

Parameters
  • string $key

public void addObservableEvents(array|mixed $observables)

Add an observable event name.

Parameters
  • array|mixed $observables

public $this addPurgeable(array|string|null $attributes=NULL)

Adds an attribute to the purgeable attributes list

Parameters
  • array|string|null $attributes

public static October\Rain\Halcyon\Collection|static[] all()

Get all of the models from the datasource.

public array attributesToArray()

Convert the model's attributes to an array.

public self bindEvent($event, $callback, $priority=0)

Create a new event binding.

Parameters
  • $event
  • $callback
  • $priority

public self bindEventOnce($event, $callback)

Create a new event binding that fires once only

Parameters
  • $event
  • $callback

public static void cacheMutatedAttributes(string $class)

Extract and cache all the mutated attributes of a class.

Parameters
  • string $class

public static void clearBootedModels()

Clear the list of booted models so they will be re-booted.

public static static create(array $attributes=array())

Save a new model and return the instance.

Parameters
  • array $attributes

public static void created(Closure|string $callback, int $priority=0)

Register a created model event with the dispatcher.

Parameters
  • Closure|string $callback
  • int $priority

public static void creating(Closure|string $callback, int $priority=0)

Register a creating model event with the dispatcher.

Parameters
  • Closure|string $callback
  • int $priority

public bool|null delete()

Delete the model from the database.

public static void deleted(Closure|string $callback, int $priority=0)

Register a deleted model event with the dispatcher.

Parameters
  • Closure|string $callback
  • int $priority

public static void deleting(Closure|string $callback, int $priority=0)

Register a deleting model event with the dispatcher.

Parameters
  • Closure|string $callback
  • int $priority

public static void fetched(Closure|string $callback)

Create a new native event for handling afterFetch().

Parameters
  • Closure|string $callback

public static void fetching(Closure|string $callback)

Create a new native event for handling beforeFetch().

Parameters
  • Closure|string $callback

public $this fill(array $attributes)

Fill the model with an array of attributes.

Parameters
  • array $attributes

public array fireEvent(string $event, array $params=array(), boolean $halt=false)

Fire an event and call the listeners.

Parameters
  • string $event - Event name
  • array $params - Event parameters
  • boolean $halt - Halt after first non-null result

public static void flushEventListeners()

Remove all of the event listeners for the model.

public array getAllowedExtensions()

Returns the allowable file extensions supported by this model.

public mixed getAttribute(string $key)

Get a plain attribute.

Parameters
  • string $key

public array getAttributes()

Get all of the current attributes on the model.

public string getBaseFileNameAttribute()

Returns the file name without the extension.

public static Illuminate\Cache\CacheManager getCacheManager()

Get the cache manager instance.

public October\Rain\Halcyon\Datasource getDatasource()

Get the datasource for the model.

public string getDatasourceName()

Get the current datasource name for the model.

public static October\Rain\Halcyon\DatasourceResolverInterface getDatasourceResolver()

Get the datasource resolver instance.

public array getDirty()

Get the attributes that have been changed since last sync.

public static Illuminate\Contracts\Events\Dispatcher getEventDispatcher()

Get the event dispatcher instance.

public void getFileNameParts($fileName=NULL)

Returns the base file name and extension. Applies a default extension, if none found.

Parameters
  • $fileName

public string getIdAttribute()

Helper for {{ page.id }} or {{ layout.id }} twig vars Returns a semi-unique string for this object.

public int getMaxNesting()

Returns the maximum directory nesting allowed by this template.

public array getMutatedAttributes()

Get the mutated attributes for a given instance.

public string getObjectTypeDirName()

Returns the directory name corresponding to the object type. For pages the directory name is "pages", for layouts - "layouts", etc.

public array getObservableEvents()

Get the observable event names.

public array getOriginal(string|null $key=NULL, mixed $default=NULL)

Get the model's original attribute values.

Parameters
  • string|null $key
  • mixed $default

public array getSettingsAttribute()

The settings is attribute contains everything that should be saved to the settings area.

public bool getWrapCode()

Returns true if the code section will be wrapped in PHP tags.

public bool hasGetMutator(string $key)

Determine if a get mutator exists for an attribute.

Parameters
  • string $key

public bool hasSetMutator(string $key)

Determine if a set mutator exists for an attribute.

Parameters
  • string $key

public static October\Rain\Halcyon\Collection hydrate(array $items, string|null $datasource=NULL)

Create a collection of models from plain arrays.

Parameters
  • array $items
  • string|null $datasource

public static void initCacheItem(array &$cached)

Initializes the object properties from the cached data. The extra data set here becomes available as attributes set on the model after fetch.

Parameters
  • array &$cached - The cached data array.

public bool isCompoundObject()

Returns true if this template supports code and settings sections.

public bool isDirty(array|string|null $attributes=NULL)

Determine if the model or given attribute(s) have been modified.

Parameters
  • array|string|null $attributes

public bool isFillable(string $key)

Determine if the given attribute may be mass assigned.

Parameters
  • string $key

public boolean isLoadedFromCache()

Returns true if the object was loaded from the cache.

public array jsonSerialize()

Convert the object into something JSON serializable.

public October\Rain\Halcyon\Collection newCollection(array $models=array())

Create a new Halcyon Collection instance.

Parameters
  • array $models

public static newFromBuilder(array $attributes=array(), string|null $datasource=NULL)

Create a new model instance that is existing.

Parameters
  • array $attributes
  • string|null $datasource

public static newInstance(array $attributes=array(), bool $exists=false)

Create a new instance of the given model.

Parameters
  • array $attributes
  • bool $exists

public October\Rain\Halcyon\Builder newQuery()

Get a new query builder for the object

public bool offsetExists(mixed $offset)

Determine if the given attribute exists.

Parameters
  • mixed $offset

public mixed offsetGet(mixed $offset)

Get the value for a given offset.

Parameters
  • mixed $offset

public void offsetSet(mixed $offset, mixed $value)

Set the value for a given offset.

Parameters
  • mixed $offset
  • mixed $value

public void offsetUnset(mixed $offset)

Unset the value for a given offset.

Parameters
  • mixed $offset

public static October\Rain\Halcyon\Model on(string|null $datasource=NULL)

Begin querying the model on a given datasource.

Parameters
  • string|null $datasource

public static October\Rain\Halcyon\Builder query()

Begin querying the model.

public void removeObservableEvents(array|mixed $observables)

Remove an observable event name.

Parameters
  • array|mixed $observables

public static October\Rain\Halcyon\Datasource resolveDatasource(string|null $datasource=NULL)

Resolve a datasource instance.

Parameters
  • string|null $datasource

public bool save(array $options=NULL)

Save the model to the datasource.

Parameters
  • array $options

public bool saveInternal(array $options=array())

Save the model to the database. Is used by {@link save()} and {@link forceSave()}.

Parameters
  • array $options

public static void saved(Closure|string $callback, int $priority=0)

Register a saved model event with the dispatcher.

Parameters
  • Closure|string $callback
  • int $priority

public static void saving(Closure|string $callback, int $priority=0)

Register a saving model event with the dispatcher.

Parameters
  • Closure|string $callback
  • int $priority

public $this setAttribute(string $key, mixed $value)

Set a given attribute on the model.

Parameters
  • string $key
  • mixed $value

public static void setCacheManager(Illuminate\Cache\CacheManager $cache)

Set the cache manager instance.

Parameters
  • Illuminate\Cache\CacheManager $cache

public $this setDatasource(string $name)

Set the datasource associated with the model.

Parameters
  • string $name

public static void setDatasourceResolver(October\Rain\Halcyon\Datasource\ResolverInterface $resolver)

Set the datasource resolver instance.

Parameters

public static void setEventDispatcher(Illuminate\Contracts\Events\Dispatcher $dispatcher)

Set the event dispatcher instance.

Parameters
  • Illuminate\Contracts\Events\Dispatcher $dispatcher

public void setFileNameAttribute(mixed $value)

File name should always contain an extension.

Parameters
  • mixed $value

public boolean setLoadedFromCache($value)

Returns true if the object was loaded from the cache.

Parameters
  • $value

public $this setObservableEvents(array $observables)

Set the observable event names.

Parameters
  • array $observables

public $this setRawAttributes(array $attributes, bool $sync=false)

Set the array of model attributes. No checking is done.

Parameters
  • array $attributes
  • bool $sync

public void setSettingsAttribute(mixed $value)

Filling the settings should merge it with attributes.

Parameters
  • mixed $value

public $this syncOriginal()

Sync the original attributes with the current.

public $this syncOriginalAttribute(string $attribute)

Sync a single original attribute with its current value.

Parameters
  • string $attribute

public array toArray()

Convert the model instance to an array.

public string toJson(int $options=0)

Convert the model instance to JSON.

Parameters
  • int $options

public self unbindEvent(string $event=NULL)

Destroys an event binding.

Parameters
  • string $event - Event to destroy

public static void unsetCacheManager()

Unset the cache manager for models.

public static void unsetDatasourceResolver()

Unset the datasource resolver for models.

public static void unsetEventDispatcher()

Unset the event dispatcher for models.

public bool|int update(array $attributes=array())

Update the model in the database.

Parameters
  • array $attributes

public static void updated(Closure|string $callback, int $priority=0)

Register an updated model event with the dispatcher.

Parameters
  • Closure|string $callback
  • int $priority

public static void updating(Closure|string $callback, int $priority=0)

Register an updating model event with the dispatcher.

Parameters
  • Closure|string $callback
  • int $priority

Show inherited public methods

Inherited public methods

Protected methods

protected static void boot()

The "booting" method of the model.

protected void bootIfNotBooted()

Check if the model needs to be booted and if so, do it.

protected void bootNicerEvents()

Bind some nicer events to this model, in the format of method overrides.

protected static void bootTraits()

Boot all of the bootable traits on the model.

protected array emitterEventSortEvents(string $eventName)

Sort the listeners for a given event by priority.

Parameters
  • string $eventName

protected array fillableFromArray(array $attributes)

Get the fillable attributes of a given array.

Parameters
  • array $attributes

protected void finishSave(array $options)

Finish processing on a successful save operation.

Parameters
  • array $options

protected mixed fireModelEvent(string $event, bool $halt=true)

Fire the given event for the model.

Parameters
  • string $event
  • bool $halt

protected array getArrayableAppends()

Get all of the appendable values that are arrayable.

protected mixed getAttributeFromArray(string $key)

Get an attribute from the $attributes array.

Parameters
  • string $key

protected mixed mutateAttribute(string $key, mixed $value)

Get the value of an attribute using its mutator.

Parameters
  • string $key
  • mixed $value

protected mixed mutateAttributeForArray(string $key, mixed $value)

Get the value of an attribute using its mutator for array conversion.

Parameters
  • string $key
  • mixed $value

protected bool originalIsNumericallyEquivalent(string $key)

Determine if the new and old values for a given key are numerically equivalent.

Parameters
  • string $key

protected void performDeleteOnModel()

Perform the actual delete query on this model instance.

protected bool performInsert(October\Rain\Halcyon\Builder $query, array $options=array())

Perform a model insert operation.

Parameters

protected bool performUpdate(October\Rain\Halcyon\Builder $query, array $options=array())

Perform a model update operation.

Parameters

protected static void registerModelEvent(string $event, Closure|string $callback, int $priority=0)

Register a model event with the dispatcher.

Parameters
  • string $event
  • Closure|string $callback
  • int $priority

Show inherited protected methods

Inherited protected methods

  • protected boolean extendableIsAccessible(mixed $class, string $propertyName) - defined in October\Rain\Extension\Extendable. Checks if a property is accessible, property equivalent of is_callable().
  • protected void extensionExtractMethods(string $extensionName, object $extensionObject) - defined in October\Rain\Extension\Extendable. Extracts the available methods from a behavior and adds it to the.