public function send($mailTemplate, $recipient, $tag, array $args) { $subject = $this->mailLoader->getSubject($mailTemplate); $message = Swift_Message::newInstance()->setSubject($subject)->setFrom($this->sourceMail)->setTo($recipient); $message->setBody($this->tpl->render($mailTemplate, $args), 'text/html'); $this->mailer->send($message); $this->log->info('Sent mail message of type \'' . $mailTemplate . '\': ' . $tag); }
public function prepare() { if (headers_sent()) { return $this; } $this->setProtocol($this->sc); $this->Logger->info("STATUS: {$this->sc}"); $this->prepareResponse(); return $this; }
/** * Queue the actual HTTP transfer through \seekat\API\Deferred and return the promise * * @param string $method The HTTP request method * @param mixed $args The HTTP query string parameters * @param mixed $body Thee HTTP message's body * @param array $headers The request's additional HTTP headers * @return ExtendedPromiseInterface */ private function __xfer(string $method, $args = null, $body = null, array $headers = null) : ExtendedPromiseInterface { if (isset($this->__data)) { $this->__log->debug(__FUNCTION__ . "({$method}) -> resolve", ["url" => (string) $this->__url, "args" => $args, "body" => $body, "headers" => $headers]); return resolve($this); } $url = $this->__url->mod(["query" => new QueryString($args)]); $request = new Request($method, $url, (array) $headers + $this->__headers, $body = is_array($body) ? json_encode($body) : (is_resource($body) ? new Body($body) : (is_scalar($body) ? (new Body())->append($body) : $body))); $this->__log->info(__FUNCTION__ . "({$method}) -> request", ["url" => (string) $this->__url, "args" => $this->__url->query, "body" => $body, "headers" => $headers]); return (new Call($this, $this->__client, $request))->promise(); }
/** * Checks for new versions of Terminus once per week and saves to cache * * @return [void] */ private function checkForUpdate() { $cache_data = $this->cache->get_data('latest_release', array('decode_array' => true)); if (!$cache_data || (int) $cache_data['check_date'] < (int) strtotime('-7 days')) { $current_version = $this->checkCurrentVersion(); } else { $current_version = $cache_data['version']; } if (version_compare($cache_data['version'], TERMINUS_VERSION, '>')) { $this->logger->info('An update to Terminus is available. Please update to {version}.', array('version' => $cache_data['version'])); } }
/** * @param int $type */ private function signalHandler($type) { if (in_array($type, [SIGHUP, SIGTERM, SIGINT])) { $this->isRunning = false; } else { if ($type === SIGCHLD) { $childrenExited = $this->processManager->processChildExited(); foreach ($childrenExited as $pid => $returnCode) { if ($returnCode !== 0) { $this->handleWorkerError(); $this->onWorkerFinished($pid, true); } else { $this->onWorkerFinished($pid, false); } if ($this->isRunning) { $this->onWorkerAvailable(); } } } else { $this->logger->info(sprintf('Unknown signal %d', $type)); } } }
/** * {@inheritdoc} */ public function flushExpired() { $this->Logger->info('Handled automatically.'); return true; }
/** * Receive request and create a Response. * * This is the core method implementing basic parts of JSKOS API. * The method handles HTTP request method, request headers and * [query modifiers](https://gbv.github.io/jskos-api/#query-modifiers), * passes valid GET and HEAD requests to the served Service and wraps * the result as Response. * * @return Response */ public function response() { $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET'; $params = $_GET; if ($method == 'OPTIONS') { $this->logger->info("Received OPTIONS request"); return $this->optionsResponse(); } # get query modifier: callback if (isset($params['callback'])) { $callback = $params['callback']; if (!preg_match('/^[$A-Z_][0-9A-Z_$.]*$/i', $callback)) { unset($callback); } unset($params['callback']); } $language = $this->extractRequestLanguage($params); # TODO: extract more query modifiers # TODO: header: Allow/Authentication $error = null; # conflicting parameters if (isset($params['uri']) and isset($params['search'])) { $error = new Error('422', 'request_error', 'Conflicting request parameters uri & search'); } if (!$error and ($method == 'GET' or $method == 'HEAD')) { $this->logger->info("Received {$method} request", $params); $answer = $this->queryService($params); if ($answer instanceof Page) { // TODO: if unique $response = $this->basicResponse(200, $answer); // TODO: Add Link header with next/last/first $response->headers['X-Total-Count'] = $answer->totalCount; if ($method == 'HEAD') { $response->emptyBody = true; } } elseif ($answer instanceof Error) { $error = $answer; } } elseif (!$error) { $error = new Error(405, '???', 'Method not allowed'); } if (isset($error)) { $this->logger->warning($error->message, ['error' => $error]); $response = $this->basicResponse($error->code, $error); } if (isset($callback)) { $response->callback = $callback; } return $response; }