PHP code example of mabe / backup-bundle

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

    

mabe / backup-bundle example snippets



// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Mabe\BackupBundle\MabeBackupBundle(),
        );

        // ...
    }

    // ...
}

// .../App/Backup/Saver.php

use Mabe\BackupBundle\Saver\SaverInterface;

class Saver implements SaverInterface
{
    public function save($json, $filename)
    {
        file_put_contents('/your/directory/'.$filename, $json);
    }
}


// src/AppBundle/Listener/BackupListener.php

namespace AppBundle\Listener;

use Mabe\BackupBundle\Event\BackupEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class BackupListener implements EventSubscriberInterface
{

    public function preBackup(BackupEvent $event)
    {
        $object = $event->getObject();
        $job = $event->getActiveJob();
        if($object instanceof User) {
            if (!$object->isEnabled()) {
                // You can skip object backup if your conditions are not met
                $event->setSerialize(false);
            }
        }
    }

    public function postBackup(BackupEvent $event)
    {
        // do something
    }

    public function backupFinished(BackupEvent $event)
    {
        // send mail, etc..
    }

    public static function getSubscribedEvents()
    {
        return array(
            BackupEvent::PRE_BACKUP => 'preBackup',
            BackupEvent::POST_BACKUP => 'postBackup',
            BackupEvent::BACKUP_FINISHED => 'backupFinished'
        );
    }
}