Beispiel #1
0
 /**
  * @param SiteState $siteState
  * @param string    $slug
  */
 public function __construct(SiteState $siteState, $slug)
 {
     $this->id = \Undine\Functions\generate_uuid();
     $this->siteState = $siteState;
     $this->siteState = $siteState;
     $this->slug = $slug;
 }
Beispiel #2
0
 /**
  * @param string $name
  * @param string $email
  */
 public function __construct($name, $email)
 {
     $this->id = \Undine\Functions\generate_uuid();
     $this->name = $name;
     $this->email = $email;
     $this->sites = new ArrayCollection();
     $this->createdAt = new \DateTime();
 }
Beispiel #3
0
 /**
  * @param string $email
  * @param string $password
  */
 public function __construct($name, $email, $password)
 {
     $this->id = \Undine\Functions\generate_uuid();
     $this->name = $name;
     $this->email = $email;
     $this->password = $password;
     $this->createdAt = new \DateTime();
 }
Beispiel #4
0
 /**
  * @param UriInterface $url
  * @param SiteState    $siteState
  * @param User         $user
  * @param string       $privateKey
  * @param string       $publicKey
  */
 public function __construct(UriInterface $url, SiteState $siteState, User $user, $privateKey, $publicKey)
 {
     $this->id = \Undine\Functions\generate_uuid();
     $this->url = $url;
     $this->siteState = $siteState;
     $this->user = $user;
     $this->privateKey = $privateKey;
     $this->publicKey = $publicKey;
     $this->ftpCredentials = new FtpCredentials();
     $this->httpCredentials = new HttpCredentials();
     $this->createdAt = new \DateTime();
 }
 public function __invoke(RequestInterface $request, array $options)
 {
     $fn = $this->nextHandler;
     if (!isset($options['oxygen_site']) || !$options['oxygen_site'] instanceof Site) {
         throw new \RuntimeException(sprintf('The option "oxygen_site" is expected to contain an instance of %s.', Site::class));
     }
     if (!isset($options['oxygen_action']) || !$options['oxygen_action'] instanceof ActionInterface) {
         throw new \RuntimeException(sprintf('The option "oxygen_action" is expected to contain an instance of %s.', ActionInterface::class));
     }
     $transferInfo = $previousCallable = null;
     if (isset($options['on_stats'])) {
         $previousCallable = $options['on_stats'];
     }
     $options['on_stats'] = function (TransferStats $stats) use(&$transferInfo, $previousCallable) {
         $transferInfo = new TransferInfo($stats->getHandlerStats());
         if ($previousCallable) {
             /* @var callable $previousCallable */
             $previousCallable($stats);
         }
     };
     /** @var Site $site */
     $site = $options['oxygen_site'];
     /** @var ActionInterface $action */
     $action = $options['oxygen_action'];
     $options['request_id'] = $requestId = \Undine\Functions\generate_uuid();
     // Kind of like str_rot8, for hexadecimal strings.
     $responseId = strtr($requestId, 'abcdef0123456789', '23456789abcdef01');
     $expiresAt = time() + 86400;
     $userName = '';
     $stateParameters = $this->stateTracker->getParameters($site);
     $requestData = ['oxygenRequestId' => $requestId, 'requestExpiresAt' => $expiresAt, 'publicKey' => $site->getPublicKey(), 'signature' => \Undine\Functions\openssl_sign_data($site->getPrivateKey(), sprintf('%s|%d', $requestId, $expiresAt)), 'handshakeKey' => $this->handshakeKeyName, 'handshakeSignature' => \Undine\Functions\openssl_sign_data($this->handshakeKeyValue, $this->getUrlSlug($site->getUrl())), 'version' => $this->moduleVersion, 'baseUrl' => (string) $site->getUrl(), 'actionName' => $action->getName(), 'actionParameters' => $action->getParameters(), 'userName' => $userName, 'userId' => $site->getUser()->getId(), 'stateParameters' => $stateParameters];
     $oxygenRequest = $request->withHeader('accept', 'text/html,application/json,application/oxygen')->withBody(\GuzzleHttp\Psr7\stream_for(json_encode($requestData)));
     if ($site->hasHttpCredentials()) {
         $oxygenRequest = $oxygenRequest->withHeader('Authorization', 'Basic ' . base64_encode(sprintf('%s:%s', $site->getHttpCredentials()->getUsername(), $site->getHttpCredentials()->getPassword())));
     }
     return $fn($oxygenRequest, $options)->then(function (ResponseInterface $response) use($site, $request, $options, &$transferInfo, $responseId, $action) {
         $responseData = $this->extractData($responseId, $request, $options, $response, $transferInfo);
         try {
             $reaction = $this->createReaction($action, $responseData);
         } catch (ExceptionInterface $e) {
             throw new ResponseException(ResponseException::ACTION_RESULT_MALFORMED, $request, $options, $response, $transferInfo, $e);
         }
         try {
             $this->stateTracker->setResult($site, $responseData['stateResult']);
         } catch (\Exception $e) {
             throw new ResponseException(ResponseException::STATE_MALFORMED, $request, $options, $response, $transferInfo, $e);
         }
         return $reaction;
     }, function (RequestException $e) use($options, &$transferInfo) {
         throw new NetworkException($e->getHandlerContext()['errno'], $e->getRequest(), $options, $e->getResponse(), $transferInfo);
     })->otherwise(function (\Exception $exception) use($site) {
         $this->stateTracker->setException($site, $exception);
         throw $exception;
     });
 }
Beispiel #6
0
 public function __construct()
 {
     $this->id = \Undine\Functions\generate_uuid();
     $this->siteExtensions = new ArrayCollection();
     $this->siteUpdates = new ArrayCollection();
 }