PHP code example of anexia / zf2-monitoring

1. Go to this page and download the library: Download anexia/zf2-monitoring 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/ */

    

anexia / zf2-monitoring example snippets



// new service class /module/Application/Service/UpCheckService.php
namespace Application\Service;

use Anexia\Monitoring\Service\UpCheckServiceInterface;

class UpCheckService implements UpCheckServiceInterface
{
    /**
     * {@inheritdoc}
     */
    public function check(&$errors = array())
    {
        // add db check/validation here
        /**
         * e.g.:
         *
         * if ($success) {
         *     return true;
         * } else {
         *     $errors[] = 'Database failure: something went wrong!';
         *     return false;
         * } 
         */
    }
}


// new service's factory class /module/Application/Service/UpCheckServiceFactory.php
namespace Application\Service;

use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
 * Class UpCheckServiceFactory
 * @package Application\Service
 */
class UpCheckServiceFactory implements FactoryInterface
{
    /**
     * (non-PHPdoc)
     * @see \Zend\ServiceManager\FactoryInterface::createService()
     */
    public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $upCheckService = new UpCheckService();
        return $upCheckService;
    }
}


// in module/Application/config/module.config.php
return array(
    'service_manager' => array(
        'factories' => array(
            'Anexia\Monitoring\Service\UpCheck' => 'Application\Service\UpCheckServiceFactory',
        )
    )
);

return array(
    'modules' => array(
        'Anexia\Monitoring'
    )
);

return array(
    'ANX_MONITORING_ACCESS_TOKEN' => '<custom_monitoring_token>'
);

return array(
    'db' => array(
        'host' => '<host>', // e.g. localhost
        'username' => '<username>',
        'password' => '<password>',
        'database' => '<database>',
        'driver' => '<driver>', // e.g. 'mysql',
        'dns' => 'mysql:dbname=<database>;host=<host>'
    )
);

ERROR