Ejemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function getProtocolSchemeForUrl($url)
 {
     // Set the default result.
     $result = $this->getDefaultProtocolScheme();
     // Lazy compile the patterns.
     if (is_null($this->compiledProtocolSchemeMap)) {
         // Retrieve raw patterns from subclass.
         $this->compiledProtocolSchemeMap = $this->getRawProtocolSchemeMap();
         // Compile all wildcard patterns into regular expressions.
         foreach ($this->compiledProtocolSchemeMap as $index => $entry) {
             $this->compiledProtocolSchemeMap[$index]['compiled-pattern'] = isset($entry['regex']) && $entry['regex'] ? $entry['pattern'] : UrlUtilities::compileWildcardUrl(trim($entry['pattern'], '/'));
         }
     }
     // Now look for the match to the given URL.
     foreach ($this->compiledProtocolSchemeMap as $entry) {
         if (preg_match($entry['compiled-pattern'], $url)) {
             $result = $entry['protocol'];
         }
     }
     return $result;
 }
 /**
  * Shortcut method to get the submission URL for the form.
  *
  * @param string $formUrl
  *
  * @return string
  */
 public function getSubmitUrl($formUrl = null)
 {
     $submitUrl = $this->getFormsModule()->getRouteUrl('form', $this->getFormKey());
     return is_null($formUrl) ? $submitUrl : UrlUtilities::generateLinkWithReturnUrl($submitUrl, $formUrl, 'form-url');
 }
Ejemplo n.º 3
0
 /**
  * Jump to a particular step within the given form.  This may fail if the step does not exist (out of range) or if
  * a form rule prevents the user from jumping to the specified step (e.g. a previous step has not been completed,
  * or an intervening step is marked one-way).
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  *
  * @throws \OutOfBoundsException
  */
 public function jumpController(Request $request)
 {
     LoggerRegistry::debug('FormsModule::jumpController()');
     // Get the form details.
     $formKey = $request->attributes->get('slug');
     $form = $this->registry()->getForm($formKey, $request);
     // Get the step being requested in the jump
     $jumpStep = intval($request->query->get('step', $this->registry()->getCurrentStep($formKey)));
     // Validation
     if ($jumpStep < 0 || $jumpStep >= $form->getStepsCount()) {
         throw new \OutOfBoundsException(sprintf('FormsModule cannot jump to step %d in form "%s": out of range', $jumpStep, $formKey));
     }
     if (!in_array($jumpStep, $this->registry()->getAvailableSteps($formKey))) {
         throw new \OutOfBoundsException(sprintf('FormsModule cannot jump to step %d in form "%s": step not available', $jumpStep, $formKey));
     }
     // Update progress and redirect back to the form URL.
     $this->registry()->setCurrentStep($formKey, $jumpStep);
     return new RedirectResponse(UrlUtilities::getReturnUrl($request, 'form-url'));
 }
Ejemplo n.º 4
0
 /**
  * Render the <base> element and some useful <link> elements.
  *
  * @param \Sitegear\View\ViewInterface $view
  * @param \Symfony\Component\HttpFoundation\Request $request
  */
 public function baseLinksComponent(ViewInterface $view, Request $request)
 {
     LoggerRegistry::debug('ContentModule::baseLinksComponent()');
     $view['base-url'] = UrlUtilities::absoluteUrl('/', $request);
     // TODO Canonicalise me
     $view['canonical-url'] = $request->getUri();
     $view['favicon-url'] = UrlUtilities::absoluteUrl('/favicon.ico', $request);
 }
Ejemplo n.º 5
0
 /**
  * Utilise AddTrolleyItemFormBuilder to create the 'add trolley item' form.
  *
  * @param string $moduleName
  * @param string $type
  * @param integer $id
  * @param string $formUrl
  *
  * @return \Sitegear\Form\FormInterface
  */
 public function buildAddTrolleyItemForm($moduleName, $type, $id, $formUrl)
 {
     LoggerRegistry::debug('CustomerModule::buildAddTrolleyItemForm({moduleName}, {type}, {id}, {formUrl})', array('moduleName' => TypeUtilities::describe($moduleName), 'type' => TypeUtilities::describe($type), 'id' => TypeUtilities::describe($id), 'formUrl' => TypeUtilities::describe($formUrl)));
     $submitUrl = $this->getRouteUrl('add-trolley-item');
     $submitUrl = UrlUtilities::generateLinkWithReturnUrl($submitUrl, $formUrl, 'form-url');
     $formBuilder = new AddTrolleyItemFormBuilder($this->getEngine()->forms(), $this->config('add-trolley-item.form-key'));
     $form = $formBuilder->buildForm(array('module-name' => $moduleName, 'type' => $type, 'id' => $id, 'submit-url' => $submitUrl, 'labels' => array('quantity-field' => $this->config('add-trolley-item.quantity-field'), 'no-value-option' => $this->config('add-trolley-item.no-value-option'), 'value-format' => $this->config('add-trolley-item.value-format'))));
     return $form;
 }
Ejemplo n.º 6
0
 public function testWildcardUrlToRegex()
 {
     $this->assertEquals(1, preg_match(UrlUtilities::compileWildcardUrl('?'), '/'));
     $this->assertEquals(0, preg_match(UrlUtilities::compileWildcardUrl('?'), '/foo'));
     $this->assertEquals(1, preg_match(UrlUtilities::compileWildcardUrl('??'), '/'));
     $this->assertEquals(0, preg_match(UrlUtilities::compileWildcardUrl('??'), '/foo'));
     $this->assertEquals(1, preg_match(UrlUtilities::compileWildcardUrl('???'), '/'));
     $this->assertEquals(1, preg_match(UrlUtilities::compileWildcardUrl('???'), '/foo'));
     $this->assertEquals(1, preg_match(UrlUtilities::compileWildcardUrl('????'), '/'));
     $this->assertEquals(1, preg_match(UrlUtilities::compileWildcardUrl('????'), '/foo'));
     $this->assertEquals(1, preg_match(UrlUtilities::compileWildcardUrl('/root*'), '/root'));
     $this->assertEquals(1, preg_match(UrlUtilities::compileWildcardUrl('/root*'), '/root/'));
     $this->assertEquals(1, preg_match(UrlUtilities::compileWildcardUrl('/root*'), '/root/foo'));
     $this->assertEquals(1, preg_match(UrlUtilities::compileWildcardUrl('/root*'), '/root/foo/bar'));
     $this->assertEquals(1, preg_match(UrlUtilities::compileWildcardUrl('/root*'), '/root-with-suffix'));
     $this->assertEquals(0, preg_match(UrlUtilities::compileWildcardUrl('/root*'), '/'));
     $this->assertEquals(0, preg_match(UrlUtilities::compileWildcardUrl('/root*'), '/foo'));
     $this->assertEquals(0, preg_match(UrlUtilities::compileWildcardUrl('/root*'), '/foo/bar'));
     $this->assertEquals(1, preg_match(UrlUtilities::compileWildcardUrl('/'), '/'));
     $this->assertEquals(0, preg_match(UrlUtilities::compileWildcardUrl('/'), '/foo/bar'));
     $this->assertEquals(1, preg_match(UrlUtilities::compileWildcardUrl('/foo/bar'), '/foo/bar'));
     $this->assertEquals(0, preg_match(UrlUtilities::compileWildcardUrl('/foo/bar'), '/'));
     $this->assertEquals(1, preg_match(UrlUtilities::compileWildcardUrl('!'), '/'));
     $this->assertEquals(1, preg_match(UrlUtilities::compileWildcardUrl('!'), '/foo'));
     $this->assertEquals(1, preg_match(UrlUtilities::compileWildcardUrl('!'), '/foo/bar'));
     $this->assertEquals(1, preg_match(UrlUtilities::compileWildcardUrl('/root!'), '/root'));
     $this->assertEquals(1, preg_match(UrlUtilities::compileWildcardUrl('/root!'), '/root/'));
     $this->assertEquals(1, preg_match(UrlUtilities::compileWildcardUrl('/root!'), '/root/foo'));
     $this->assertEquals(1, preg_match(UrlUtilities::compileWildcardUrl('/root!'), '/root/foo/bar'));
     $this->assertEquals(0, preg_match(UrlUtilities::compileWildcardUrl('/root!'), '/'));
     $this->assertEquals(0, preg_match(UrlUtilities::compileWildcardUrl('/root!'), '/foo'));
     $this->assertEquals(0, preg_match(UrlUtilities::compileWildcardUrl('/root!'), '/foo/bar'));
 }
Ejemplo n.º 7
0
 /**
  * Get the URL for a login or logout link according to the specified key.
  *
  * @param string $key Either 'login' or 'logout'.
  * @param Request $request The request providing the URL to return to, after completing the action.
  *
  * @return string Generated URL.
  */
 public function getAuthenticationLinkUrl($key, Request $request)
 {
     return UrlUtilities::generateLinkWithReturnUrl($this->getRouteUrl($key), $request->getUri());
 }