PHP code example of benjamin-rqt / data-watcher-bundle
1. Go to this page and download the library: Download benjamin-rqt/data-watcher-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/ */
benjamin-rqt / data-watcher-bundle example snippets
namespace App\DataWatcher;
use BenjaminRqt\DataWatcherBundle\Check\AbstractSqlCheck;
final class MyCheck extends AbstractSqlCheck
{
public function getName(): string { return 'my.sql.check'; }
public function getDescription(): string { return 'Detects X'; }
public function getSchedule(): string { return '0 9 * * 1-5'; } // Mon-Fri at 9:00 AM
protected function getSql(): string
{
return "SELECT id, name FROM my_table WHERE problem = 1";
}
}
use BenjaminRqt\DataWatcherBundle\Check\AbstractDoctrineCheck;
use Doctrine\ORM\Query;
final class MyDoctrineCheck extends AbstractDoctrineCheck
{
public function getName(): string { return 'my.doctrine.check'; }
public function getDescription(): string { return 'Detects Y via ORM'; }
public function getSchedule(): string { return '@daily'; }
protected function buildQuery(): Query
{
return $this->em->getRepository(User::class)
->createQueryBuilder('u')
->select('u.id')
->where('u.email LIKE :s')
->setParameter('s', '%admin%')
->getQuery();
}
}
use BenjaminRqt\DataWatcherBundle\Check\AbstractCallableCheck;
final class MyCallableCheck extends AbstractCallableCheck
{
public function __construct(private readonly MyCustomCallableHandler $callableHandler) {}
public function getName(): string { return 'my.callable.check'; }
public function getDescription(): string { return 'Detects Z via callable'; }
public function getSchedule(): string { return '@daily'; }
protected function getCallable(): ArrayCallableInterface
{
return $this->callableHandler;
}
}
use BenjaminRqt\DataWatcherBundle\Check\ArrayCallableInterface;
final class CallableHandler implements ArrayCallableInterface
{
public function __invoke(): array
{
return [
['id' => 42],
];
}
}
public function getMaxAnomalies(): int
{
return 5; // 1 by default, here at least 5 results are needed to send an alert
}
public function getRecipients(): array
{
return ['[email protected]']; // overrides global config
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.