PHP code example of w3c / lifecycle-events-bundle

1. Go to this page and download the library: Download w3c/lifecycle-events-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

w3c / lifecycle-events-bundle example snippets

 bash
$ php composer.phar 
 php

// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new W3C\LifecycleEventsBundle\W3CLifecycleEventsBundle(),
    );
}
 php

use W3C\LifecycleEventsBundle\Annotation as On;
 php

/**
 * @param mixed $entity the entity being created
 */
public function __construct($entity)
 php

/**
 * @param mixed $entity the entity being deleted
 * @param array $identifier identifier of the entity being deleted
 */
public function __construct($entity, $identifier)
 php

/**
 * @param object $entity the entity being modified
 * @param array $propertiesChangeSet list of changes to properties
 * @param array $collectionsChangeSet list of changes to collections
 */
public function __construct($entity, array $propertiesChangeSet = null, array $collectionsChangeSet = null)
 php

/**
 * @param object $entity entity being modified
 * @param string $property property being modified
 * @param array $oldValue property's old value
 * @param array $newValue property's new value
 */
public function __construct($entity, $property, $oldValue = null, $newValue = null)
 php

/**
 * @param object $entity entity being modified
 * @param string $property collection being modified
 * @param array $deletedElements elements being deleted from the collection
 * @param array $insertedElements elements being inserted to the collection
 */
public function __construct($entity, $property, $deletedElements = null, $insertedElements = null)
 php

$dispatcher = $this->container->get("w3c_lifecycle_events.dispatcher");
$dispatcher->setAutoDispatch(false);
 php

use W3C\LifecycleEventsBundle\Services\LifecycleEventsDispatcher;
public function testAction(LifecycleEventsDispatcher $dispatcher)
{
    [...]
    $dispatcher->setAutoDispatch(false);
    [...]
}
 php

$dispatcher->dispatchEvents(); // manually dispatch all events