Git Product home page Git Product logo

events's Introduction

CommonPHP Event Management Library

The CommonPHP Event Management Library offers a powerful and flexible system to handle event-driven programming within PHP applications. It provides mechanisms for event registration, de-registration, triggering, and dynamic hook management.

Features

  • Event Registration & Deregistration: Easily register and deregister events within your application.
  • Dynamic Hook Management: Attach and manage callbacks (hooks) to events with support for priority ordering.
  • Event Triggering: Trigger events dynamically, executing all attached hooks in priority order.
  • Exception Handling: Robust exception handling for event-related operations, ensuring clear error reporting and resolution.
  • Service Manager Integration: Seamlessly integrates with the CommonPHP Service Management framework for dependency management.

Installation

Use Composer to install the Event Management Library into your project:

composer require comphp/events

Basic Usage

To get started with the CommonPHP Event Management Library, please refer to the example provided in the examples/general-usage.php file within the library. This example demonstrates how to set up the EventManager, register events, attach hooks with callbacks, and trigger events within your application.

The example covers essential functionalities such as event registration, hook management, and event triggering, showcasing the library's integration with the CommonPHP Service Management framework for comprehensive event-driven programming.

// Sample snippet from examples/general-usage.php

require '../vendor/autoload.php';

use CommonPHP\Events\EventManager;
use CommonPHP\Events\ServiceProviders\EventManagerServiceProvider;
use CommonPHP\ServiceManagement\ServiceManager;

// Simulating the ServiceManager setup
$serviceManager = new ServiceManager();
$serviceManager->providers->registerProvider(EventManagerServiceProvider::class);

// Setting up the EventManager and registering it with the ServiceManager
$eventManager = $serviceManager->get(EventManager::class);

// Example usage of EventManager within a DemoClass
class DemoClass {
    // Implementation details...
}

// For full example, please refer to examples/general-usage.php

For a complete and runnable example, including event deregistration and exception handling, please refer to the provided file. This will give you a practical understanding of how to integrate and utilize the event management capabilities in your projects.

Advanced Usage

The library also supports advanced features like event de-registration, priority-based hook execution, and exception handling for robust event management. For more detailed examples, refer to the /examples directory.

Contributing

Contributions to the CommonPHP Event Management Library are welcome. Please refer to the contributing guidelines for more information on how to submit pull requests, report issues, or request features.

License

This library is open-sourced software licensed under the MIT license.

events's People

Contributors

tlmcclatchey avatar

Stargazers

 avatar

events's Issues

Events in the global namespace

Events could be available globally, not just on the class level; or it could be on both?

For instance, having a $database->onConnect(...) event caller is handy and segregates the event from something like $configuration->onLoad(...).

Perhaps a better way to do this would be to have $events->on('database.connect', ...) and $events->on('config.load', ...)?

The benefit to this is that you could potentially check if an event exists without having to reference the target class. This would allow for further decoupling so that, in the event of a database, you could use $events->hasEvent('database.connect') and, if that returns false, you could use $events->hasNamespace('database') to see if there are even any events in that namespace.

The issue with this, however, is that it could cause naming collisions if two libraries decide on using the same namespace. This would require extra checks to ensure that parameters exist and match.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.