You are here

Php.php in DRD Agent 4.0.x

Same filename and directory in other branches
  1. 8.3 src/Agent/Action/Php.php

File

src/Agent/Action/Php.php
View source
<?php

namespace Drupal\drd_agent\Agent\Action;

use Exception;

/**
 * Provides a 'Php' code.
 */
class Php extends Base {

  /**
   * {@inheritdoc}
   */
  public function execute() {
    $args = $this
      ->getArguments();
    try {
      if (!empty($args['php'])) {
        $filename = 'temporary://drd_agent_php.inc';
        file_put_contents($filename, $args['php']);

        /** @noinspection PhpIncludeInspection */
        require_once $filename;
        unlink($filename);
      }
    } catch (Exception $ex) {
      $this->messenger
        ->addMessage(t('Error while executing PHP: :msg', [
        ':msg' => $ex
          ->getMessage(),
      ]), 'error');
    }
    return [];
  }

}

Classes

Namesort descending Description
Php Provides a 'Php' code.