Exemple #1
0
 /**
  * @param Url $base
  * @return array
  */
 private function assembleActions(Url $base)
 {
     $actions = [];
     foreach ($this->app->actions->getAllActions() as $id => $action) {
         $actions[] = ['caption' => $action->caption(), 'description' => $this->app->parser->shorten($action->description()), 'link' => ['href' => $base->appended($id)->toString()]];
     }
     return $actions;
 }
Exemple #2
0
 protected function before()
 {
     $this->renderers = new RendererRegistry();
     $this->links = new LinkRegistry();
     $this->actions = new ActionRegistry();
     $this->renderer = new ObjectRenderer($this->renderers, new TypeFactory(), new LinkPrinter(Url::fromString('baser/url'), $this->links, $this->actions, new WebCommentParser()));
 }
Exemple #3
0
 private function createLinks($object, $classes = '')
 {
     return array_map(function (Link $link) use($object, $classes) {
         $action = $this->actions->getAction($link->actionId());
         $url = $this->baseUrl->appended($link->actionId())->withParameters(new Map($link->parameters($object)));
         $attributes = ['class' => $classes, 'href' => $url];
         if ($link->confirm() !== null) {
             $attributes['onclick'] = "return confirm('{$link->confirm()}');";
         }
         $description = $action->description();
         if (!is_null($description)) {
             $attributes['title'] = str_replace('"', "'", strip_tags($this->parser->shorten($description)));
         }
         return new Element('a', $attributes, [$action->caption()]);
     }, $this->links->getLinks($object));
 }
 protected function before()
 {
     $this->links = new LinkRegistry();
     $this->actions = new ActionRegistry();
     $printer = new LinkPrinter(Url::fromString('http://example.com/base'), $this->links, $this->actions, new WebCommentParser());
     $this->renderer = new IdentifierRenderer($printer);
 }
 function __construct()
 {
     $this->headers = new Map();
     $this->arguments = new Map();
     $this->target = new Path();
     $this->context = Url::fromString('http://example.com');
 }
Exemple #6
0
 /**
  * @param WebRequest $request
  * @return Url
  */
 private function getAbsoluteTarget(WebRequest $request)
 {
     $target = $this->getTarget();
     if ($target->isAbsolute()) {
         return $target;
     }
     return Url::fromString($request->getContext() . '/' . $target);
 }
 protected function before()
 {
     $this->renderers = new RendererRegistry();
     $this->types = new TypeFactory();
     $this->links = new LinkRegistry();
     $this->actions = new ActionRegistry();
     $parser = new WebCommentParser();
     $this->printer = new LinkPrinter(Url::fromString('http://example.com/base'), $this->links, $this->actions, $parser);
     $this->tableRenderer = new TableRenderer($this->renderers, $this->printer);
 }
Exemple #8
0
 public function before()
 {
     $this->calendar = Mockster::of(Calendar::class);
     $this->store = new EventStore();
     $this->uid = new FakeUidGenerator();
     $this->baseUrl = Url::fromString('http://example.com/ucdi');
     $this->givenNowIs('now');
     Mockster::stub($this->calendar->insertEvent(Arg::any(), Arg::any(), Arg::any(), Arg::any(), Arg::any()))->will()->call(function ($args) {
         return 'Event-' . $args['summary'];
     });
 }
Exemple #9
0
 public function handleScheduleBrick(ScheduleBrick $command)
 {
     if (!isset($this->goalOfTask[$command->getTask()])) {
         throw new \Exception("Task [{$command->getTask()}] does not exist.");
     }
     if ($command->getStart() < $this->now) {
         throw new \Exception('Cannot schedule brick in the past');
     }
     $brickId = $this->uid->generate('Brick');
     $events = [new BrickScheduled($brickId, $command->getTask(), $command->getDescription(), $command->getStart(), $command->getDuration())];
     if ($this->settings->calendarId) {
         $eventId = $this->calendar->insertEvent($this->settings->calendarId, $command->getDescription(), $command->getStart(), $command->getStart()->add($command->getDuration()), 'Show goal: ' . $this->base->appended('ShowGoalOfBrick')->withParameter('brick', $brickId) . "\n" . 'Mark as laid: ' . $this->base->appended('MarkBrickLaid')->withParameter('brick', $brickId));
         $events[] = new CalendarEventInserted($brickId, $this->settings->calendarId, $eventId);
     }
     return $events;
 }
 private function makeRequest($parameters = [])
 {
     return new WebRequest(Url::fromString('http://example.com/base'), new Path(), null, new Map($parameters));
 }
Exemple #11
0
 protected function assembleAction(ActionLink $action)
 {
     $representer = $this->registry->getActionRepresenter($action->getClass());
     $target = Url::fromString($representer->getResourceUrl())->withParameter('action', $action->getClass())->withParameter('args', $action->getArguments());
     return ['caption' => $representer->render(), 'link' => ['href' => $target->toString(), 'onclick' => $representer->requiresConfirmation() ? "return confirm('" . $representer->requiresConfirmation() . "');" : 'return true;']];
 }
Exemple #12
0
 /**
  * @param ActionPanel $value
  * @return mixed
  */
 public function render($value)
 {
     $heading = $this->actions->getAction($value->getActionId())->caption();
     return (string) (new Panel($heading, $this->getContent($value)))->setMaxHeight($value->getMaxHeight())->setRightHeading([new Element('a', ['href' => $this->baseUrl->appended($value->getActionId())->withParameters(Map::toCollections($value->getParameters()))], [new Element('span', ['class' => 'glyphicon glyphicon-circle-arrow-right'])])])->render($this->renderers);
 }
Exemple #13
0
 protected function determineContext($server)
 {
     $scheme = "http" . (!empty($server['HTTPS']) ? "s" : "");
     if (isset($server['HTTP_HOST'])) {
         $host = $server['HTTP_HOST'];
     } else {
         $host = $server['SERVER_NAME'] . ($server['SERVER_PORT'] != 80 ? ':' . $server['SERVER_PORT'] : '');
     }
     list($context, ) = $this->splitContextAndTarget($server);
     return Url::fromString($scheme . "://" . $host . rtrim($context, '/'));
 }
 /**
  * @return Url
  */
 public function getResourceUrl()
 {
     return Url::fromString('execute');
 }
Exemple #15
0
 private function wrapAsset(Element $element, $attributeName)
 {
     $attribute = $element->getAttribute($attributeName);
     if (!$attribute) {
         return;
     }
     $url = Url::fromString($attribute->getValue());
     if ($url->isAbsolute()) {
         return;
     }
     $path = $url->getPath();
     $path->insertAll($this->path->slice(0, -1), 0);
     $url->setPath($path);
     $element->setAttribute($attributeName, $url->toString());
 }
Exemple #16
0
 public function before()
 {
     $this->request = new WebRequest(Url::fromString('http://example.com/base'), Path::fromString(''), 'get', new Map(), new Liste(['null']));
     $this->factory = WebDelivery::init();
 }
Exemple #17
0
 private function wrapTarget($target, $name, $next, WebRequest $request)
 {
     $targetUrl = Url::fromString($target);
     if ($targetUrl->isAbsolute()) {
         $context = $request->getContext()->toString();
         $target = ltrim(substr($target, strlen($context)), '/');
     }
     $model = '<a href="' . $target . '"/>';
     $wrapped = $this->wrap($name, $model, $next, $request);
     $wrappedTarget = Url::fromString(substr($wrapped, 9, -3));
     foreach ($request->getArguments() as $key => $value) {
         if ($key != Wrapper::$PREFIX . $name) {
             $wrappedTarget->getParameters()->set($key, $value);
         }
     }
     return $wrappedTarget->toString();
 }
 /**
  * @param null|string|Url $url
  */
 public function setResourceUrl($url)
 {
     if (is_string($url)) {
         $url = Url::fromString($url);
     }
     $this->resourceUrl = $url;
 }
Exemple #19
0
}
if (isset($_GET['code'])) {
    $client->authenticate($_GET['code']);
    $_SESSION['token'] = $client->getAccessToken();
    header('Location: ' . ($_SESSION['targetUrl'] ?: '/'));
    exit;
}
if (isset($_SESSION['token'])) {
    $client->setAccessToken($_SESSION['token']);
}
$redirectToAuthUrl = function () use($client) {
    $_SESSION['targetUrl'] = (string) Url::fromString($_SERVER['REQUEST_URI'])->withParameters(Collection::toCollections($_REQUEST));
    $authUrl = $client->createAuthUrl();
    header('Location: ' . $authUrl);
    exit;
};
if (!$client->getAccessToken()) {
    $redirectToAuthUrl();
}
$cal = new Google_Service_Calendar($client);
$info = new Google_Service_Oauth2($client);
try {
    $userId = $info->userinfo->get()->email;
    $userDir = __DIR__ . '/user/' . $userId;
    $settingsStore = new SettingsStore($userDir);
    $calendar = new GoogleCalendar($cal, $settingsStore->read()->calendarId);
    (new Bootstrapper($userDir, $userId, Url::fromString(dirname($baseUrl)), $calendar, $settingsStore))->runWebApp();
} catch (Google_Auth_Exception $e) {
    unset($_SESSION['token']);
    $redirectToAuthUrl();
}
Exemple #20
0
 private function whenIRenderTheMenu()
 {
     $this->rendered = (string) $this->menu->render(new WebRequest(Url::fromString('http://example.com/base'), new Path()));
 }
 public function givenTheContextIs($string)
 {
     $this->environment->context = Url::fromString($string);
 }
Exemple #22
0
 public function givenTheContextIs($string)
 {
     $this->request->setContext(Url::fromString($string));
 }
Exemple #23
0
 public function whenICreateTheResponse()
 {
     $request = new WebRequest(Url::fromString('curir'), new Path(), null, null, new Liste($this->formats));
     $this->response = $this->responder->createResponse($request);
 }