Download the PHP package tfhinc/ci-newton without Composer
On this page you can find all versions of the php package tfhinc/ci-newton. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tfhinc/ci-newton
More information about tfhinc/ci-newton
Files in tfhinc/ci-newton
Package ci-newton
Short Description Simply Observe - Newton allows you to Subscribe and Listen for Event Broadcasts in the Codeigniter framework.
License MIT
Homepage https://github.com/TFHInc/ci-newton
Informations about the package ci-newton
Newton
Simply Observe - Newton allows you to Subscribe and Listen for Event Broadcasts in the Codeigniter framework.
Installation
Run the post install publish-files
command to publish the config, helper and library class files to the appropriate CI directories:
Loading the Library
There are a few available options for loading the Newton library:
Using the newton()
helper function
The Newton helper function will resolve the Newton class via the CI instance. It will either load the class or return the existing class instance:
Using the Newton Class
The Newton class can be instantiated via namespace:
Using the Newton CI Library
The Newton class can be loaded like any other CI library:
Class Structure
The Newton library allows for Listener
classes to subscribe to Event
class broadcasts. This helps decouple your business logic into single purpose Listener
classes that can be invoked en masse by the broadcast of an Event
.
Event Classes
The Event
class defines the properties that a given event will require and receive where there is a broadcast. The Event
class does not contain any business logic - think of it as a blueprint of required data for a given event.
application/events/UserCreatedEvent.php
Listener Classes
The Listener
class contains the business logic that will be performed when a subscribed Event
is broadcast. The Listener
class will receive an instance of the Event
class, which includes the event properties for usage in your business logic:
Note that the Listener
class must extend the TFHInc/Newton/NewtonListener
abstract class.
application/listeners/SendAdminEmailListener.php
application/listeners/UpdateUserStatsListener.php
Subscriptions
You can subscribe Listener
classes to the Event
classes. This means when the Event
is broadcast the subscribed Listener
classes wil be invoked via reflection. There are two ways to subscribe Listeners
to Events
:
Via Configuration File
Via Subscribe Method
Broadcasting Events
An Event
can be broadcast via the broadcast()
method using the Newton library or newton()
helper function:
In this example the UserCreatedEvent
class will be instantiated and in turn,
instantiate the subscribed classes SendAdminEmailListener
and UpdateUserStatsListener
.
Contributing
Feel free to create a GitHub issue or send a pull request with any bug fixes. Please see the GutHub issue tracker for isses that require help.
Acknowledgements
- Colin Rafuse
- All Contributors
License
The MIT License (MIT). Please see License File for more information.