PHP Classes

File: example/example.php

Recommend this page to a friend!
  Classes of Kacper Rowinski   PHP iNotify Extension Class   example/example.php   Download  
File: example/example.php
Role: Example script
Content type: text/plain
Description: Class source
Class: PHP iNotify Extension Class
Get notifications of when directory files change
Author: By
Last change: - php 7.4
- symfony 4,5,6 support
- docker iamge updated
- replaced travis with github workflow
- code reformat to psr12
- tests and little refactor
- readme update
Date: 13 days ago
Size: 1,041 bytes
 

Contents

Class file image Download
<?php

declare(strict_types=1);

use
Inotify\InotifyConsumerFactory;
use
Inotify\InotifyEvent;
use
Inotify\InotifyEventCodeEnum;
use
Inotify\WatchedResourceCollection;
use
Symfony\Component\EventDispatcher\EventSubscriberInterface;

include
__DIR__ . '/../vendor/autoload.php';

(new
InotifyConsumerFactory())
    ->
registerSubscriber(
        new class implements
EventSubscriberInterface {
            public static function
getSubscribedEvents(): array
            {
                return [
InotifyEvent::class => 'onInotifyEvent'];
            }

            public function
onInotifyEvent(InotifyEvent $event): void
           
{
                echo
$event;
            }
        }
    )->
consume(
       
WatchedResourceCollection::createSingle(
           
sys_get_temp_dir(),
           
// sys_get_temp_dir() . '/test.log',
            //InotifyEventCodeEnum::ON_CREATE()->getValue() | InotifyEventCodeEnum::ON_DELETE()->getValue(),
           
InotifyEventCodeEnum::ON_ALL_EVENTS()->getValue(),
           
'test'
       
)
    );