Exemplo n.º 1
0
 /**
  * Test email validation.
  */
 public function testEmail()
 {
     $request = new Request();
     $request->setContainer($this->container);
     $rule = new ZMEmailRule('email', 'not valid');
     $this->assertNotNull($rule);
     $this->assertTrue($rule->validate($request, array('email' => '*****@*****.**')));
     $this->assertTrue($rule->validate($request, array('email' => '*****@*****.**')));
     $this->assertTrue($rule->validate($request, array('email' => '*****@*****.**')));
     $this->assertFalse($rule->validate($request, array('email' => 'foobar.net')));
 }
Exemplo n.º 2
0
 /**
  * Process a HTTP request.
  *
  * <p>Supported request methods are <code>GET</code> and <code>POST</code>.</p>
  * <p><strong>This method should not be overridded!</strong>.</p>
  *
  * @param ZenMagick\Http\Request request The request to process.
  * @return View A <code>View</code> instance or <code>null</code>.
  */
 public function processAction(Request $request)
 {
     // ensure a usable id is set
     $this->requestId = null != $this->requestId ? $this->requestId : $request->getRequestId();
     $settingsService = $this->container->get('settingsService');
     // default is no view to allow the controller to generate content
     $view = null;
     // form validation (only if not already error view from session validation...)
     $formData = $this->getFormData($request);
     if (null == $view && null != $formData && $this->isFormSubmit($request)) {
         // move to function
         if (null != ($view = $this->validateFormData($request, $formData))) {
             $this->get('logger')->debug('validation failed for : ' . $formData . '; returning: ' . $view);
         }
     }
     if (null == $view) {
         $method = $request->getMethod();
         switch ($method) {
             case 'GET':
                 $view = $this->processGet($request);
                 break;
             case 'POST':
                 $view = $this->processPost($request);
                 break;
             default:
                 //return call_user_func_array($target, $margs);
                 if (method_exists($this, $method) || in_array($method, $this->getAttachedMethods())) {
                     // (re-)check on method level if mapping exists
                     $methodRequestId = $request->getRequestId() . '#' . $method;
                     $view = $this->{$method}($request);
                     break;
                 }
                 throw new ZMException('unsupported method: ' . $method);
         }
     }
     if ($view instanceof Response) {
         return $view;
     }
     if (null != $view) {
         $this->initViewVars($view, $request, $formData);
         if (!$view->isValid()) {
             $this->get('logger')->warn('invalid view: ' . $view->getTemplate() . ', expected: ' . $view->getViewFilename());
             $view = $this->findView($settingsService->get('zenmagick.mvc.request.missingPage'));
             $this->initViewVars($view, $request, $formData);
         }
         $this->view = $view;
     }
     if ($request->isXmlHttpRequest()) {
         $view->setLayout('');
         $view->setContentType('text/plain');
     }
     return $view;
 }
 /**
  * {@inheritDoc}
  *
  * @todo move to request
  */
 public function isValidSession(Request $request, Session $session)
 {
     $valid = true;
     if ($this->enabled && $request->isSecure()) {
         $sslSessionId = $request->server->get('SSL_SESSION_ID');
         if (null == ($sessionSslSessionId = $session->get(self::SESSION_SSL_SESSION_ID_KEY))) {
             $session->set(self::SESSION_SSL_SESSION_ID_KEY, $sslSessionId);
         } else {
             $valid = $sslSessionId == $sessionSslSessionId;
         }
     }
     return $valid;
 }
Exemplo n.º 4
0
 /**
  * {@inheritDoc}
  */
 public function isValidSession(Request $request, Session $session)
 {
     $valid = true;
     if ($this->enabled) {
         $ip = $request->getClientIp();
         if (null == ($sessionIP = $session->get(self::SESSION_IP_KEY))) {
             $session->set(self::SESSION_IP_KEY, $ip);
         } else {
             $valid = $ip == $sessionIP;
         }
     }
     return $valid;
 }
Exemplo n.º 5
0
 /**
  * Process a HTTP request.
  *
  * <p>This implementation will delegate request handling based on the method parameter in
  * the request. If no method is found, the default <em>parent</em> <code>process()</code> implementation
  * will be called.</p>
  *
  * <p>Also, if the passed method is not found, the controller will try to resolve the method by appending the
  * configured <em>ajaxFormat</em> string. So, if, for example, the method is <code>getCountries</code> and <em>ajaxFormat</em> is
  * <code>JSON</code>, the controller will first look for <code>getCountries</code> and then for <code>getCountriesJSON</code>.</p>
  *
  * @return View A <code>View</code> instance or <code>null</code>.
  */
 public function processAction(Request $request)
 {
     $method = $sacsMethod = $request->getParameter('method');
     if (!method_exists($this, $method)) {
         $method = $method . 'JSON';
     }
     $sacsManager = $this->container->get('sacsManager');
     // check access on controller level
     $sacsManager->authorize($request, $request->getRequestId(), $this->getUser());
     // (re-)check on method level if mapping exists
     $methodRequestId = $request->getRequestId() . '#' . $sacsMethod;
     if ($sacsManager->hasMappingForRequestId($methodRequestId)) {
         $sacsManager->authorize($request, $methodRequestId, $this->getUser());
     }
     if (method_exists($this, $method) || in_array($method, $this->getAttachedMethods())) {
         $this->{$method}($request);
         return null;
     }
     return parent::processAction($request);
 }
Exemplo n.º 6
0
<?php

// @todo using filesystem ACLs is recommended, but what should we do by default?
//umask(0002); // This will let the permissions be 0775
umask(00);
// This will let the permissions be 0777
use ZenMagick\Http\Request;
$loader = (require_once __DIR__ . '/../app/bootstrap.php.cache');
/*
$loader = new \Symfony\Component\ClassLoader\ApcClassLoader('zm', $loader);
$loader->register(true);
*/
require_once __DIR__ . '/../app/AppKernel.php';
//require_once __DIR__.'/../app/AppCache.php';
// @todo remove context from here altogether!
$context = 'storefront';
if (0 === strpos($_SERVER['REQUEST_URI'], '/admin')) {
    $context = 'admin';
}
$kernel = new AppKernel('prod', false, $context);
$kernel->loadClassCache();
//$kernel = new AppCache($kernel);
Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
Exemplo n.º 7
0
 /**
  * Set the request.
  *
  * @param ZenMagick\Http\Request request The request.
  */
 public function setRequest(Request $request)
 {
     $this->request = $request;
     $this->languageId = $request->getSession()->getLanguageId();
 }
Exemplo n.º 8
0
 /**
  * Show.
  */
 public function showAction($cID, Request $request, Session $session)
 {
     $coupon = $this->container->get('couponService')->getCouponForId($request->getParameter('cID'), $session->getLanguageId());
     return new ModelAndView(null, array('coupon' => $coupon));
 }
 /**
  * Check if this request needs validation at all.
  *
  * <p>This default implementation will validate <em>POST</em> requests only.
  */
 protected function qualifies(Request $request)
 {
     return 'POST' == $request->getMethod();
 }
Exemplo n.º 10
0
 /**
  * Update cart.
  * @todo: edit cart attributes
  */
 public function updateAction(Request $request)
 {
     $flashBag = $request->getSession()->getFlashBag();
     $shoppingCart = $this->get('shoppingCart');
     $productIds = (array) $request->request->get('products_id');
     $quantities = (array) $request->request->get('cart_quantity');
     foreach ($productIds as $ii => $productId) {
         $shoppingCart->updateProduct($productId, $quantities[$ii]);
     }
     $this->container->get('event_dispatcher')->dispatch('cart_update', new GenericEvent($this, array('request' => $request, 'shoppingCart' => $shoppingCart, 'productIds' => $productIds)));
     $flashBag->success($this->get('translator')->trans('Product(s) added to cart'));
     // TODO: add support for redirect back to origin
     return new ModelAndView('success', array('shoppingCart' => $shoppingCart));
 }
Exemplo n.º 11
0
 /**
  * {@inheritDoc}
  */
 public function populate(Request $request)
 {
     Beans::setAll($this, $request->getParameterMap(), null);
 }