<?php

$serializer = new SuperClosure\Serializer();
return ['initialize' => $serializer->serialize(function ($authority) {
    $user = Auth::guest() ? new App\User() : $authority->getCurrentUser();
    if ($user->hasRole('admin')) {
        $authority->allow('manage', 'App\\User');
    } else {
        //nothing
    }
})];
Exemple #2
0
<?php

$serializer = new SuperClosure\Serializer();
return array('assetUrl' => env('APP_ASSET_URL', '/'), 'themeDefault' => 'default', 'layoutDefault' => 'default', 'themeDir' => 'themes', 'containerDir' => array('layout' => 'layouts', 'asset' => 'assets', 'partial' => 'partials', 'widget' => 'widgets', 'view' => 'views'), 'namespaces' => array('widget' => 'App\\Widgets'), 'events' => array('before' => $serializer->serialize(function ($theme) {
    //$theme->setTitle('Something in global.');
}), 'asset' => $serializer->serialize(function ($asset) {
    // Preparing asset you need to serve after.
    $asset->cook('backbone', function ($asset) {
        $asset->add('backbone', '//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min.js');
        $asset->add('underscorejs', '//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js');
    });
    // To use cook 'backbone' you can fire with 'serve' method.
    // Theme::asset()->serve('backbone');
})), 'engines' => array('twig' => array('allows' => array('Auth', 'Cache', 'Config', 'Cookie', 'Form', 'HTML', 'Input', 'Lang', 'Paginator', 'Str', 'Theme', 'URL', 'Validator'), 'hooks' => $serializer->serialize(function ($twig) {
    // Example add funciton name "demo".
    /*$function = new Twig_SimpleFunction('example', function()
    		        {
    		            $args = func_get_args();
    
    		            return "Example" . print_r($args, true);
    		        });
    
    		        $twig->addFunction($function);*/
    return $twig;
}))));
Exemple #3
0
 /**
  * Pack job so that it can be send.
  *
  * @param Job $job The job to serialize.
  *
  * @return string JSON string.
  */
 protected function serialize(Job $job)
 {
     $return = [];
     if ($job->isCallable()) {
         $return['type'] = Job::TYPE_CALLABLE;
         $serializer = new \SuperClosure\Serializer();
         $return['route'] = $serializer->serialize($job->route);
     } else {
         $return['type'] = Job::TYPE_REGULAR;
         $return['route'] = $job->route;
     }
     $return['data'] = $job->data;
     return $this->serializeMessage($return);
 }
 /**
  * @param \Closure $callback The callback.
  *
  * @return array
  */
 private function serializeCallback(\Closure $callback)
 {
     $serializer = new \SuperClosure\Serializer();
     $serialized = $serializer->serialize($callback);
     return [$serializer, $serialized];
 }
<?php

$serializer = new SuperClosure\Serializer();
return ['initialize' => $serializer->serialize(function ($authority) {
    // Action aliases. For example:
    //
    // $authority->addAlias('moderate', ['read', 'update', 'delete']);
    //
    // See the wiki of AuthorityController for details:
    // https://github.com/efficiently/authority-controller/wiki/Action-aliases
    //
    // Define abilities for the passed in user here. For example:
    //
    //  $user = Auth::guest() ? new User : $authority->getCurrentUser();
    //  if ($user->hasRole('admin')) {
    //      $authority->allow('manage', 'all');
    //  } else {
    //      $authority->allow('read', 'all');
    //  }
    //
    // The first argument to `allow` is the action you are giving the user
    // permission to do.
    // If you pass 'manage' it will apply to every action. Other common actions
    // here are 'read', 'create', 'update' and 'destroy'.
    //
    // The second argument is the resource the user can perform the action on.
    // If you pass 'all' it will apply to every resource. Otherwise pass a Eloquent
    // class name of the resource.
    //
    // The third argument is an optional anonymous function (Closure) to further filter the
    // objects.
<?php

$serializer = new SuperClosure\Serializer();
return ['Auth' => ['User' => ['bid' => $serializer->serialize(function ($self) {
    return $self->hasOne('Cms\\Modules\\Bidding\\Models\\Bid');
})]]];
Exemple #7
0
$dbh = new PDO('sqlite::memory:');
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
/*
 * Setup a test-fixture, having two jobs, first one is a system-cmd (date), second one is a Closure
 * (which is saved to pdo-database).
 */
$dbh->exec("\nCREATE TABLE IF NOT EXISTS `{$dbhJobbiesTableName}`\n(`name` VARCHAR(255) NOT NULL ,\n `command` TEXT NOT NULL ,\n `schedule` VARCHAR(255) NOT NULL ,\n `mailer` VARCHAR(255) NULL DEFAULT 'sendmail' ,\n `maxRuntime` INT UNSIGNED NULL ,\n `smtpHost` VARCHAR(255) NULL ,\n `smtpPort` SMALLINT UNSIGNED NULL ,\n `smtpUsername` VARCHAR(255) NULL ,\n `smtpPassword` VARCHAR(255) NULL ,\n `smtpSender` VARCHAR(255) NULL DEFAULT 'jobby@localhost' ,\n `smtpSenderName` VARCHAR(255) NULL DEFAULT 'Jobby' ,\n `smtpSecurity` VARCHAR(20) NULL ,\n `runAs` VARCHAR(255) NULL ,\n `environment` TEXT NULL ,\n `runOnHost` VARCHAR(255) NULL ,\n `output` VARCHAR(255) NULL ,\n `dateFormat` VARCHAR(100) NULL DEFAULT 'Y-m-d H:i:s' ,\n `enabled` BOOLEAN NULL DEFAULT TRUE ,\n `haltDir` VARCHAR(255) NULL , `debug` BOOLEAN NULL DEFAULT FALSE ,\n PRIMARY KEY (`name`)\n)\n");
$insertCronJobConfiguration = $dbh->prepare("\nINSERT INTO `{$dbhJobbiesTableName}`\n (`name`,`command`,`schedule`,`output`)\n VALUES\n (:name,:command,:schedule,:output)\n");
// First demo-job - print "date" to logs/command-pdo.log.
$insertCronJobConfiguration->execute(['CommandExample', 'date', '* * * * *', 'logs/command-pdo.log']);
// Second demo-job - a Closure which does some php::echo(). The Closure is saved to PDO-backend, too.
$secondJobFn = function () {
    echo "I'm a function (" . date('Y-m-d H:i:s') . ')!' . PHP_EOL;
    return true;
};
$serializer = new SuperClosure\Serializer();
$secondJobFnSerialized = $serializer->serialize($secondJobFn);
$insertCronJobConfiguration->execute(['ClosureExample', $secondJobFnSerialized, '* * * * *', 'logs/closure-pdo.log']);
/*
 * Examples are now set up, and saved to PDO-backend.
 *
 * Now, fetch all jobbies from PDO-backend and run them.
 */
$jobbiesStmt = $dbh->query("SELECT * FROM `{$dbhJobbiesTableName}`");
$jobbies = $jobbiesStmt->fetchAll(PDO::FETCH_ASSOC);
$jobby = new \Jobby\Jobby();
foreach ($jobbies as $job) {
    // Filter out each value, which is not set (for example, "maxRuntime" is not defined in the job).
    $job = array_filter($job);
    try {
        $job['closure'] = $serializer->unserialize($job['command']);
<?php

$serializer = new SuperClosure\Serializer();
return ['initialize' => $serializer->serialize(function ($authority) {
    $user = Auth::guest() ? new App\User() : $authority->getCurrentUser();
    //$authority->allow('manage', 'all');
    if ($user->isMemberOf('System Administrators')) {
        $authority->allow('manage', 'App\\Workflow');
    } else {
        //nothing
    }
})];