Xpressengine\Plugin\Composer\ComposerFileWriter::set PHP Méthode

set() public méthode

set data
public set ( string $key, mixed $value ) : void
$key string data field key
$value mixed data value
Résultat void
    public function set($key, $value)
    {
        array_set($this->data, $key, $value);
    }

Usage Example

 /**
  * reserveInstall
  *
  * @param ComposerFileWriter $writer
  * @param int                $timeLimit
  */
 protected function reserveOperation(ComposerFileWriter $writer, $timeLimit, $callback = null)
 {
     set_time_limit($timeLimit);
     ignore_user_abort(true);
     ini_set('allow_url_fopen', '1');
     $memoryInBytes = function ($value) {
         $unit = strtolower(substr($value, -1, 1));
         $value = (int) $value;
         switch ($unit) {
             case 'g':
                 $value *= 1024;
                 // no break (cumulative multiplier)
             // no break (cumulative multiplier)
             case 'm':
                 $value *= 1024;
                 // no break (cumulative multiplier)
             // no break (cumulative multiplier)
             case 'k':
                 $value *= 1024;
         }
         return $value;
     };
     $memoryLimit = trim(ini_get('memory_limit'));
     // Increase memory_limit if it is lower than 1GB
     if ($memoryLimit != -1 && $memoryInBytes($memoryLimit) < 1024 * 1024 * 1024) {
         ini_set('memory_limit', '1G');
     }
     /** @var \Illuminate\Foundation\Application $app */
     app()->terminating(function () use($writer, $callback) {
         $pid = getmypid();
         Log::info("[plugin operation] start running composer run [pid={$pid}]");
         // call `composer install` command programmatically
         $vendorName = PluginHandler::PLUGIN_VENDOR_NAME;
         $input = new ArrayInput(['command' => 'update', "--prefer-lowest", "--with-dependencies", '--working-dir' => base_path(), 'packages' => ["{$vendorName}/*"]]);
         $output = new BufferedOutput();
         $application = new Application();
         $application->setAutoExit(false);
         // prevent `$application->run` method from exitting the script
         if (!defined('__XE_PLUGIN_MODE__')) {
             define('__XE_PLUGIN_MODE__', true);
         }
         $code = $application->run($input, $output);
         $outputText = $output->fetch();
         file_put_contents(storage_path('logs/plugin.log'), $outputText);
         if (is_callable($callback)) {
             $callback($code);
         }
         $writer->load();
         if ($code !== 0) {
             $writer->set('xpressengine-plugin.operation.status', ComposerFileWriter::STATUS_FAILED);
         } else {
             $writer->set('xpressengine-plugin.operation.status', ComposerFileWriter::STATUS_SUCCESSED);
         }
         $writer->write();
         Log::info("[plugin operation] plugin operation finished. [exit code: {$code}, memory usage: " . memory_get_usage() . "]");
     });
 }