示例#1
0
 /**
  * Run the stored sequence of actions
  *
  * 
  * 
  * @param Filter $filter A filter to select actions from the saved sequence to
  *		be run (default: `null`)
  * @param bool $force Whether or not to force actions executed in previous runs
  *		to be executed again in this run (default: `false`)
  *
  * @return Result[] The responses generated by each action that was executed in
  *		this run, in the order executed
  *
  * @see BatchManager::preprocessAction() preprocessAction()
  * @see BatchManager::postprocessResult() postprocessResult()
  */
 public function run(Filter $filter = null, $force = false)
 {
     $id = md5(time());
     $environment = array();
     $sandbox = new Sandbox($id, $this->sequence, $filter, $force, $environment);
     foreach ($this->sequence as $action) {
         if ($filter === null || $filter->filter($action)) {
             try {
                 $result = $this->preprocessAction($action)->run($environment, $id, $force);
                 $sandbox->addResult($this->postprocessResults($result));
             } catch (Action_Exception $e) {
                 throw new BatchManager_Exception(($force ? 'Forced run' : 'Run') . " (ID {$id})" . (empty($tags) ? '' : ' with tags [' . implode(', ', $tags) . ']') . ' failed to complete: ' . $e->getMessage() . ' (Action_Exception ' . $e->getCode() . '), sandbox contents: ' . var_export($sandbox, true), BatchManager_Exception::ACTION_FAILED);
             }
         }
     }
     return $sandbox->getResults();
 }
示例#2
0
 /**
  * Install an updated version of a cabin
  *
  * If we get to this point:
  *
  * 1. We know the signature is signed by the supplier.
  * 2. The hash was checked into Keyggdrasil, which
  *    was independently vouched for by our peers.
  *
  * @param UpdateInfo $info
  * @param UpdateFile $file
  * @throws CouldNotUpdate
  */
 protected function install(UpdateInfo $info, UpdateFile $file)
 {
     if (!$file->hashMatches($info->getChecksum())) {
         throw new CouldNotUpdate(\__('Checksum mismatched'));
     }
     $path = $file->getPath();
     $this->log('Begin Cabin updater', LogLevel::DEBUG, ['path' => $path, 'supplier' => $info->getSupplierName(), 'name' => $info->getPackageName()]);
     $updater = new \Phar($path, \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::KEY_AS_FILENAME);
     $updater->setAlias($this->pharAlias);
     $ns = $this->makeNamespace($info->getSupplierName(), $info->getPackageName());
     // We need to do this while we're replacing files.
     $this->bringCabinDown($ns);
     $oldMetadata = \Airship\loadJSON(ROOT . '/Cabin/' . $ns . '/manifest.json');
     // Overwrite files
     $updater->extractTo(ROOT . '/Cabin/' . $ns, null, true);
     // Run the update trigger.
     Sandbox::safeInclude('phar://' . $this->pharAlias . '/update_trigger.php', $oldMetadata);
     // Free up the updater alias
     $garbageAlias = Base64UrlSafe::encode(\random_bytes(33)) . '.phar';
     $updater->setAlias($garbageAlias);
     unset($updater);
     // Now bring it back up.
     $this->bringCabinBackUp($ns);
     // Make sure we update the version info. in the DB cache:
     $this->updateDBRecord('Cabin', $info);
     $this->log('Conclude Cabin updater', LogLevel::DEBUG, ['path' => $path, 'supplier' => $info->getSupplierName(), 'name' => $info->getPackageName()]);
     self::$continuumLogger->store(LogLevel::INFO, 'Cabin update installed', $this->getLogContext($info, $file));
 }
示例#3
0
 /**
  * We just need to replace the Phar
  *
  * If we get to this point:
  *
  * 1. We know the signature is signed by the supplier.
  * 2. The hash was checked into Keyggdrasil, which
  *    was independently vouched for by our peers.
  *
  * @param UpdateInfo $info
  * @param UpdateFile $file
  * @throws CouldNotUpdate
  */
 protected function install(UpdateInfo $info, UpdateFile $file)
 {
     if (!$file->hashMatches($info->getChecksum())) {
         throw new CouldNotUpdate(\__('Checksum mismatched'));
     }
     // Create a backup of the old Gadget:
     \rename($this->filePath, $this->filePath . '.backup');
     \rename($file->getPath(), $this->filePath);
     $this->log('Begin install process', LogLevel::DEBUG, ['path' => $file->getPath(), 'hash' => $file->getHash(), 'version' => $file->getVersion(), 'size' => $file->getSize()]);
     // Get metadata from the old version of this Gadget:
     $oldAlias = Base64UrlSafe::encode(\random_bytes(48)) . '.phar';
     $oldGadget = new \Phar($this->filePath, \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::KEY_AS_FILENAME);
     $oldGadget->setAlias($oldAlias);
     $oldMetadata = $oldGadget->getMetadata();
     unset($oldGadget);
     unset($oldAlias);
     // Let's open the update package:
     $newGadget = new \Phar($this->filePath, \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::KEY_AS_FILENAME, $this->pharAlias);
     $newGadget->setAlias($this->pharAlias);
     $metaData = $newGadget->getMetadata();
     // We need to do this while we're replacing files.
     $this->bringSiteDown();
     Sandbox::safeRequire('phar://' . $this->pharAlias . '/update_trigger.php', $oldMetadata);
     // Free up the updater alias
     $garbageAlias = Base64UrlSafe::encode(\random_bytes(48)) . '.phar';
     $newGadget->setAlias($garbageAlias);
     unset($newGadget);
     // Now bring it back up.
     $this->bringSiteBackUp();
     // Make sure we update the version info. in the DB cache:
     $this->updateDBRecord('Gadget', $info);
     if ($metaData) {
         $this->updateJSON($info, $metaData);
     }
     self::$continuumLogger->store(LogLevel::INFO, 'Gadget update installed', $this->getLogContext($info, $file));
 }
示例#4
0
文件: main.php 项目: andrew-ayers/php
<?php

include_once 'actor.php';
include_once 'sandbox.php';
$sandbox = new Sandbox();
$sandbox->run();
$best = $sandbox->get_best_fit(1);
print print_r($best[0], true) . "\n";
for ($i = 0; $i <= 100; $i++) {
    $problem = $i;
    $solution = sqrt($problem);
    $answer = $best[0]->evaluate($problem);
    echo "The square root of {$problem} equals {$solution}...I calculate it to be {$answer}.\n";
}
$code = $best[0]->get_code();
$end = strpos($code, '!');
echo "My code is: " . substr($code, 0, $end) . "\n";
示例#5
0
 /**
  * Gadget install process.
  *
  * 1. Move .phar to the appropriate location.
  * 2. If this gadget is for a particular cabin, add it to that cabin's
  *    gadgets.json file.
  * 3. Run the update triggers (install hooks and incremental upgrades).
  * 4. Clear the cache files.
  *
  * @param InstallFile $fileInfo
  * @return bool
  */
 public function install(InstallFile $fileInfo) : bool
 {
     $supplier = $this->supplier->getName();
     $fileName = $supplier . '.' . $this->package . '.phar';
     $metadata = $this->getMetadata($fileInfo);
     // Move .phar file to its destination.
     if (!empty($metadata['cabin'])) {
         $gadgetConfigFile = ROOT . '/Cabin/' . $metadata['cabin'] . '/config/gadgets.json';
         // Cabin-specific gadget
         $cabin = ROOT . '/Cabin/' . $metadata['cabin'] . '/Gadgets';
         if (!\is_dir($cabin)) {
             $this->log('Could not install; cabin "' . $metadata['cabin'] . '" is not installed.', LogLevel::ERROR);
             return false;
         }
         $filePath = $cabin . '/' . $supplier . '/' . $fileName;
         if (!\is_dir($cabin . '/' . $supplier)) {
             \mkdir($cabin . '/' . $supplier, 0775);
         }
     } else {
         $gadgetConfigFile = ROOT . '/config/gadgets.json';
         // Universal gadget. (Probably affects the Engine.)
         $filePath = ROOT . '/Gadgets/' . $supplier . '/' . $fileName;
         if (!\is_dir(ROOT . '/Gadgets/' . $supplier)) {
             \mkdir(ROOT . '/Gadgets/' . $supplier, 0775);
         }
     }
     $gadgetConfig = \Airship\loadJSON($gadgetConfigFile);
     $gadgetConfig[] = [['supplier' => $supplier, 'name' => $this->package, 'version' => $metadata['version'] ?? null, 'path' => $filePath, 'enabled' => true]];
     \Airship\saveJSON($gadgetConfigFile, $gadgetConfig);
     \rename($fileInfo->getPath(), $filePath);
     // If cabin-specific, add to the cabin's gadget.json
     if ($metadata['cabin']) {
         $this->addToCabin($metadata['cabin']);
     }
     // Run the update hooks:
     $alias = 'gadget.' . $fileName;
     $phar = new \Phar($filePath, \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::KEY_AS_FILENAME);
     $phar->setAlias($alias);
     // Run the update trigger.
     if (\file_exists('phar://' . $alias . '/update_trigger.php')) {
         Sandbox::safeRequire('phar://' . $alias . '/update_trigger.php');
     }
     self::$continuumLogger->store(LogLevel::INFO, 'Install successful', $this->getLogContext($fileInfo));
     // Finally, clear the cache files:
     return $this->clearCache();
 }
示例#6
0
} elseif (isset($_SERVER['REQUEST_URI'])) {
    $request = $_SERVER['REQUEST_URI'];
}
if (strpos($request, '?') !== false) {
    $file = rtrim(DOCUMENT_ROOT, DIRECTORY_SEPARATOR) . substr($request, 0, strpos($request, '?'));
} else {
    $file = rtrim(DOCUMENT_ROOT, DIRECTORY_SEPARATOR) . $request;
}
// check configuration
if (!isset($c)) {
    $c = array();
}
// run Sandbox
try {
    // create Sandbox
    $parsing = new Sandbox($c);
    // parse file
    $parsing->parse($file);
    // output
    $parsing->flush();
} catch (Exception $e) {
    // something went wrong
    // check current error level
    if (!defined('IS_PRODUCTION_INSTANCE')) {
        // print out debug message
        echo '<h1>' . $e->getMessage() . '</h1>';
        echo '<p>in <strong>' . $e->getFile() . '</strong> at line <strong>' . $e->getLine() . '</strong>, code <strong>' . $e->getCode() . '</strong>.</p>';
        echo '<pre>' . $e->getTraceAsString() . '</pre>';
    }
    // TODO: else: send server error (what number? must check.)
    die;
 function testRecurringGtdSepaDebitSale()
 {
     $init = $this->testInitRecurringGtdSepaDebitSale();
     $charged = Sandbox::charge_depit_sale($this->channelToken, $init->unique_id);
     $this->assertEqual($charged->unique_id, $init->unique_id);
     $this->assertEqual($charged->status, 'approved');
     $this->assertTrue($charged->isApproved());
     $data = $this->fixture('recurring_gtd_sepa_debit_sale.json');
     $data['reference_id'] = $init->unique_id;
     $data['currency'] = 'USD';
     try {
         $trx = Transaction::recurring_gtd_sepa_debit_sale($this->channelToken, $data);
         $this->assertNull($trx->error, "error %s , uid: {$trx->unique_id}, error:" . $trx->error);
         $this->assertPattern('/^[0-9a-f]{32}$/', $trx->unique_id);
         $this->assertTrue($trx->isApproved(), 'isApproved() %s');
         $this->assertEqual($trx->transaction_type, 'recurring_gtd_sepa_debit_sale');
         $this->assertEqual($trx->amount, $data['amount']);
         $this->assertEqual($trx->currency, $data['currency']);
         $this->assertNull(@$trx->redirect_url);
         $this->assertFalse($trx->shouldRedirect());
     } catch (\Exception $e) {
         print_r($e->errors);
         throw $e;
     }
 }
 /**
  * Sandbox Plugin constructor
  *
  * Construstor method, please do not overwrite this method in your plugin class!
  * To run your stuff at instantiation please use the init method.
  * {@see SandboxPlugin::init()}
  *
  * @param Sandbox $sandbox    Sandbox object instance
  * @param string  $pluginpath Absolute path where plugin class is located
  *
  * @access public
  * @since 0.1
  **/
 public final function __construct(Sandbox $sandbox, $pluginpath)
 {
     // interfaces to API
     $this->path = rtrim($pluginpath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
     $this->sandbox = $sandbox;
     $this->content = $sandbox->content;
     $this->pm = $sandbox->pm;
     $this->cache = $sandbox->cache;
     // plugin config from user configuration (done in bootstrap)
     $config = $this->sandbox->getConfig();
     $classname = get_class($this);
     if (isset($config[$classname])) {
         $this->config = $config[$classname];
     }
     unset($config);
     unset($classname);
     $this->init();
 }
示例#9
0
 /**
  * @test
  */
 public function getWsHostShouldReturnTheConstantValue()
 {
     $env = new Sandbox();
     $this->assertEquals(Sandbox::WS_HOST, $env->getWsHost());
 }