PHP code example of napp / xray-laravel

1. Go to this page and download the library: Download napp/xray-laravel 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/ */

    

napp / xray-laravel example snippets


protected $middleware = [
    \Napp\Xray\Middleware\RequestTracing::class, // here

    \App\Http\Middleware\TrustProxies::class,
    \App\Http\Middleware\CheckForMaintenanceMode::class,
    // ...
];

'providers' => [
    /*
     * Laravel Framework Service Providers...
     */
    Napp\Xray\XrayServiceProvider::class, // here

    Illuminate\Auth\AuthServiceProvider::class,
    Illuminate\Broadcasting\BroadcastServiceProvider::class,
    // ...
];

'aliases' => [
    // ...
    'Xray' => \Napp\Xray\Facades\Xray::class,
],

Xray::addSegment('MyCustomLogic');

// run your code

Xray::endSegment('MyCustomLogic');

use Napp\Xray\Facades\Xray;

class XMLParser
{
    public function handle($file)
    {
        // adding some metadata to the segment
        Xray::addSegment('XMLParser', null, [
            'file' => $file->name()
        ]);
        $this->parse($file);
        Xray::endSegment('XMLParser');
    }
    
    private function parse($xml): array 
    {
        Xray::addSegment('XMLParser parse');
        $output = $this->getAttributeList();
        // some more code
        Xray::endSegment('XMLParser parse');

        return $output;
    }
    
    private function getAttributeList(): array 
    {
        Xray::addSegment('XMLParser getAttributeList');
        // your code
        Xray::endSegment('XMLParser getAttributeList');

        return [];
    }
}

use Symfony\Component\HttpFoundation\Request;
use Napp\Xray\Facades\Xray;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        Xray::addRequestFilterCallback(function(Request $request) {
            /* some conditions */
            return true;
        });
    }
}

# config/xray.php
...
 'submitter' => \Napp\Xray\Submission\DaemonSegmentSubmitter::class,
...
console
php artisan vendor:publish --tag=xray-config