Exemple #1
0
 /**
  * Run closure remotely or locally
  *
  * @param $closure
  *
  * @throws \Exception
  *
  * @return mixed
  */
 public function run(\Closure $closure)
 {
     try {
         $closure = new SerializableClosure($closure);
         if (!$this->communicator->isConnected()) {
             $this->communicator->connect();
         }
         $serialize = base64_encode(serialize($closure));
         $output = $this->communicator->run(sprintf('php -r \'%s $c=unserialize(base64_decode("%s")); echo %s($c());\'', $this->getClosureUnserializerAsString(), $serialize, $this->stringifier->getSerializeFunctionName()));
         return $this->stringifier->toObject($output);
     } catch (\RuntimeException $e) {
         throw new ExecutorException('An error occurs when execution php on target host with the following message: ' . $e->getMessage());
     } catch (\Exception $e) {
         // todo Manage exception
         throw $e;
     }
 }
Exemple #2
0
 /**
  * @test
  */
 public function getSerializeFunctionNameShouldReturnNativeSerializerFunctionName()
 {
     $this->assertEquals('var_export', $this->stringifier->getSerializeFunctionName());
 }
Exemple #3
0
 /**
  * @test
  */
 public function getSerializeFunctionNameShouldReturnNativeSerializerFunctionName()
 {
     $this->assertEquals('json_encode', $this->stringifier->getSerializeFunctionName());
 }