Trigger a POST request
@param array $resource Mailjet Resource/Action pair
@param array $args     Request arguments
@return Response
347324
public function post($resource, array $args = [], array $options = [])
    {
        if (!empty($options)) {
            $this->setOptions($options, $resource);
        }
        $result = $this->_call('POST', $resource[0], $resource[1], $args);

        if (!empty($this->changed)) {
            $this->setSettings();
        }
        return $result;
    }
693053
public function update( array $args ) {

		if ( self::$ran ) {
			return new NullLog();
		}

		if ( $this->is_cron() || $this->is_cli() ) {
			$this->register_event_listener();
		}

		return new NullLog();
	}
375461
public function run(array $args, $method='get'){
      $method = strtolower($method);
      $append_echoed_text = Options::get('core.route.append_echoed_text',true);
      static::trigger('start', $this, $args, $method);

      // Call direct befores
      if ( $this->befores ) {
        // Reverse befores order
        foreach (array_reverse($this->befores) as $mw) {
          static::trigger('before', $this, $mw);
          Event::trigger('core.route.before', $this, $mw);
          ob_start();
          $mw_result  = call_user_func($mw);
          $raw_echoed = ob_get_clean();
          if ($append_echoed_text) Response::add($raw_echoed);
          if ( false  === $mw_result ) {
            return [''];
          } else {
            Response::add($mw_result);
          }
        }
      }

      $callback = (is_array($this->callback) && isset($this->callback[$method]))
                  ? $this->callback[$method]
                  : $this->callback;

      if (is_callable($callback) || is_a($callback, "View") ) {
        Response::type( Options::get('core.route.response_default_type', Response::TYPE_HTML) );

        ob_start();
        if (is_a($callback, "View")) {
          // Get the rendered view
          $view_results = (string)$callback;
        } else {
          $view_results = call_user_func_array($callback, $args);
        }
        $raw_echoed   = ob_get_clean();

        if ($append_echoed_text) Response::add($raw_echoed);
        Response::add($view_results);
      }

      // Apply afters
      if ( $this->afters ) {
        foreach ($this->afters as $mw) {
          static::trigger('after', $this, $mw);
          Event::trigger('core.route.after', $this, $mw);
          ob_start();
          $mw_result  = call_user_func($mw);
          $raw_echoed = ob_get_clean();
          if ($append_echoed_text) Response::add($raw_echoed);
          if ( false  === $mw_result ) {
            return [''];
          } else {
            Response::add($mw_result);
          }
        }
      }

      static::trigger('end', $this, $args, $method);
      Event::trigger('core.route.end', $this);

      return [Filter::with('core.route.response', Response::body())];
     }
148463
public function execute(array $args, array $options = [])
    {
        if (!isset($args[0])) {
            throw new \InvalidArgumentException('arg action must be input');
        }
        $action = explode('::', $args[0]);
        if (!class_exists($action[0])) {
            throw new \InvalidArgumentException('action not not found!');
        }

        ProcessManage::rmTask($action);
    }
667618
public function trigger($event, $args = array())
	{
		if (!($event instanceof Event))
		{
			if (isset($this->events[$event]))
			{
				$event = $this->events[$event];
			}
			else
			{
				$event = new Event($event);
			}
		}

		// If a listener group was specified
		// lazy load the listeners.
		if ($group = $event->getGroup())
		{
			$this->addListeners($group);
		}

		// Attach any incoming aruments
		foreach ((array) $args as $name => $arg)
		{
			$event->addArgument($name, $arg);
		}

		// Are there any listeners for this event?
		if (isset($this->listeners[$event->getName()]))
		{
			foreach ($this->listeners[$event->getName()] as $listener)
			{
				// Call the event listener
				if ($listener instanceof Closure)
				{
					$response = call_user_func($listener, $event);
				}
				else
				{
					$response = call_user_func(array($listener, $event->getName()), $event);
				}

				// Attach response
				if (!is_null($response))
				{
					$event->addResponse($response);
				}

				// Is propagation stopped?
				if ($event->isStopped())
				{
					break;
				}
			}
		}

		return $event->getResponse();
	}
99689
public function controller($route, ...$args) {
		// Sanitize the call
		$route = preg_replace('/[^a-zA-Z0-9_\/]/', '', (string)$route);

		// Keep the original trigger
		$trigger = $route;

		// Trigger the pre events
		$result = $this->registry->get('event')->trigger('controller/' . $trigger . '/before', array(&$route, &$args));

		// Make sure its only the last event that returns an output if required.
		if ($result != null && !$result instanceof Exception) {
			$output = $result;
		} else {
			$action = new Action($route);
			$output = $action->execute($this->registry, $args);
		}

		// Trigger the post events
		$result = $this->registry->get('event')->trigger('controller/' . $trigger . '/after', array(&$route, &$args, &$output));

		if ($result && !$result instanceof Exception) {
			$output = $result;
		}

		if (!$output instanceof Exception) {
			return $output;
		}
	}
736193
public function trigger($event, $target = null, $argv = [])
    {
        if (!$event instanceof Event) {
            $event = new Event($event, $target, $argv);
        } else {
            $event->setTarget($target);
            $event->setParams($argv);
        }

        $allListeners = [];
        if (isset($this->listeners[$event->getName()])) {
            ksort($this->listeners[$event->getName()]);
            $allListeners = array_values($this->listeners[$event->getName()]);
        }

        $result = null;
        foreach ($allListeners as $listeners) {
            foreach ($listeners as $listener) {
                $result = call_user_func($listener, $event);
                if ($event->isPropagationStopped()) {
                    break 2;
                }
            }
        }

        return $result;
    }
461765
public function postAction( $resource )
	{
		$response = $this->createAdmin( $resource )->post( $this->getPsrRequest(), new Response() );
		return $this->setPsrResponse( $response );
	}
661899
public static function trigger(string $name, ?array $args = null)
  {
    if (!isset(self::$events[$name])) return false;

    foreach (self::$events[$name] as $event => $callback) {
      if (is_callable($callback)) {
        return call_user_func_array($callback, isset($args) ? $args : []);
      }
      else if (is_array($callback)) {
        (new Events)->triggerGroup($callback, $args);
      }
      else if (is_string($callback)) {
        $call = new $callback;
        return call_user_func_array([$call, 'persist'], $args ?? []);
      }
    }
  }
815873
public function update(Request $request, Response $response, array $args)
    {
        $validator = $this->createValidator();

        $rawData = $request->request->all();

        $result = $validator->run($rawData);

        if ($result->isValid()) {
            $fields = $result->getValidated();
            $data = array_intersect_key($rawData, array_flip($fields));

            $entity = $this->em->getRepository($this->entityClass)->find($args['id']);

            $this->updateEntity($entity, $data);

            $this->em->flush();

            return new RedirectResponse($request->getUri());
        }

        $response = $this->updateAction($request, $response, $args);

        return $response;
    }
926193
public static function request(
        $arg_endpoint,
        $arg_method,
        array $arg_data = array(),
        array $arg_headers = array()
    ) {
        $return = array();
        $headers = array(
            'Accept: application/json',
            'DUE-API-KEY: '.Due::getApiKey(),
            'DUE-PLATFORM-ID: '.Due::getPlatformId(),
        );
        if($arg_method == APIRequests::METHOD_PUT){
            $headers[]= 'Content-Type: application/x-www-form-urlencoded; charset=utf-8';
        }
        $headers = array_merge($headers, $arg_headers);
        $full_url = Due::getRootPath().$arg_endpoint;

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $full_url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $arg_method);
        curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        if(!empty($arg_data)){
            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($arg_data));
        }
        $response = curl_exec($ch);
        $err = curl_error($ch);

        if (!$err) {
            $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
            $headers = substr($response, 0, $header_size);
            $body = substr($response, $header_size);
            $return['headers'] = self::headersToArray($headers);
            $return['body'] = json_decode($body, true);
            if(!empty($return['body']['errors'][0])){
                $api_error = $return['body']['errors'][0];
                $message = (empty($api_error['message']) ? '' : $api_error['message']);
                $code = (empty($api_error['code']) ? 0 : $api_error['code']);
                throw new \Exception($message,$code);
            }
        }else{
            throw new \Exception($err);
        }

        return $return;
    }
103282
final protected function post($resource, $fields)
    {
        // Initilize the request as post
        $this->init('post', $resource);

        // Is an object
        if (!is_array($fields)) {
            $fields = $this->fragment($fields);
        }

        // Setting the fields to request
        $body = $this->request->getBody();
        foreach ($fields as $key => $value) {
            $body->setField($key, (string) $value);
        }

        // Make the request using guzzle
        return $this->call();
    }
82128
public function triggerEvent($event, $args = [])
    {
        /** @var \Windwalker\Event\Dispatcher $dispatcher */
        $dispatcher = $this->container->get('dispatcher');

        $dispatcher->triggerEvent($event, $args);

        return $event;
    }
949357
protected function triggerParamsMergeEvent($event, $argv = array(), $callback = null)
    {
        $eventRet = $this->triggerEvent($event, $argv, $callback);
        foreach ($eventRet as $event) {
            if (is_array($event) || $event instanceof Traversable) {
                $argv = array_merge_recursive($argv, $event);
            }
        }

        return $argv;
    }
202652
public function makeApiRequest($resource, array $params = array(), $method = 'GET')
    {

        $uri = $this->requestUri . '/' . ltrim($resource, '/');

        if ($this->hasValidToken()) {
            $params['oauth_token'] = $this->token;
        } else {
            $params['client_id'] = $this->clientId;
            $params['client_secret'] = $this->clientSecret;
        }

        // apply a dated "version"
        $params['v'] = $this->dateVerified->format('Ymd');

        switch ($method) {
            case 'GET':
                $response = json_decode($this->httpClient->get($uri, $params));
                break;
            case 'POST':
                $response = json_decode($this->httpClient->post($uri, $params));
                break;
            default:
                throw new \RuntimeException('Currently only HTTP methods "GET" and "POST" are supported.');
        }

        //TODO check headers for api request limit

        if (isset($response->meta)) {

            if (isset($response->meta->code)
                && $response->meta->code != 200
            ) {
                //TODO handle case
            }

            if (isset($response->meta->notifications)
                && is_array($response->meta->notifications)
                && count($response->meta->notifications)
            ) {

                //TODO handle notifications

            }

        }

        return $response->response;

    }
488117
public function post($resource, $body = null, $params = [])
    {
        return $this->send($this->prepare('POST', $resource, $body, $params));
    }
1142906
public static function run($args=null){
      if (PHP_SAPI != 'cli') return false;
      if($args) {
        $_args = $args;
        static::$file = basename(isset($_SERVER['PHP_SELF'])?$_SERVER['PHP_SELF']:__FILE__);
       } else {
        $_args = $_SERVER['argv'];
        static::$file = basename(array_shift($_args));
      }
      foreach($_args as $e) if(strpos($e,'-')===0) {
        $h = explode('=',$e);
        static::$options[ltrim(current($h),'-')] = isset($h[1])?$h[1]:true;
      } else {
        static::$arguments[] = $e;
      }

      if(isset(static::$arguments[0])){
        $command = array_shift(static::$arguments);
        if (empty(static::$commands[$command]))
          return static::triggerError("Unknown command [".$command."].");
        $cmd = static::$commands[$command];
        $pars_vector = [];
        foreach ($cmd[0] as $_idx => $segment) {
          if ($segment[0]==':'){
            // Extract paramenter
            if (isset(static::$arguments[$_idx])){
               $pars_vector[] = static::$arguments[$_idx];
            } else return static::triggerError("Command [".$command."] needs more parameters");
          } else {
            // Match command
            if (empty(static::$arguments[$_idx]) || $segment!=static::$arguments[$_idx])
              return static::triggerError("Command [".$command."] is incomplete.");
          }
        }
        $returns = call_user_func_array($cmd[1], $pars_vector);
        echo is_scalar($returns) ? "$returns" : json_encode($returns, JSON_PRETTY_PRINT);
        return true;
      } else {
        static::help();
        return false;
      }
    }