PHP code example of lbausch / build-metadata-laravel

1. Go to this page and download the library: Download lbausch/build-metadata-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/ */

    

lbausch / build-metadata-laravel example snippets




// deploy.php

namespace Deployer;

adata:deploy');

after('artisan:config:cache', 'buildmetadata:clear');

// ...



// app/Providers/ViewServiceProvider.php

namespace App\Providers;

use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
use Lbausch\BuildMetadataLaravel\BuildMetadataManager;

class ViewServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot(BuildMetadataManager $manager)
    {
        $metadata = $manager->getMetadata();

        View::composer('*', function ($view) use ($metadata) {
            $view->with('BUILD_REF', $metadata->get('BUILD_REF', 'n/a'));
        });
    }
}



// app/Providers/AppServiceProvider.php

namespace App\Providers;

use Carbon\Carbon;
use Illuminate\Support\ServiceProvider;
use Lbausch\BuildMetadataLaravel\BuildMetadataManager;
use Lbausch\BuildMetadataLaravel\Metadata;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        BuildMetadataManager::beforeCaching(function (Metadata $metadata): Metadata {
            // Convert build date to a Carbon instance
            $build_date = $metadata->get('BUILD_DATE');

            $metadata->set('BUILD_DATE', Carbon::createFromTimestampUTC($build_date));

            return $metadata;
        });
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }
}



// app/Providers/EventServiceProvider.php

namespace App\Providers;

use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;

class EventServiceProvider extends ServiceProvider
{
    /**
     * Register any events for your application.
     *
     * @return void
     */
    public function boot()
    {
        Event::listen(function(\Lbausch\BuildMetadataLaravel\Events\CachingBuildMetadata $event) {
            //
        });
    }
}
bash
php artisan vendor:publish --provider=Lbausch\\BuildMetadataLaravel\\ServiceProvider
bash
php artisan buildmetadata:clear


// app/Providers/EventServiceProvider.php

namespace App\Providers;

use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;

class EventServiceProvider extends ServiceProvider
{
    /**
     * Register any events for your application.
     *
     * @return void
     */
    public function boot()
    {
        Event::listen(function(\Lbausch\BuildMetadataLaravel\Events\CachedBuildMetadata $event) {
            $build_metadata = $event->build_metadata;
        });
    }