Beispiel #1
0
 /**
  * Assert redirect to another controllers
  *
  * @param string $module
  * @param string $controller
  * @param array $params
  * @param int $code
  * @return void
  */
 protected function assertRedirect($module, $controller, $params = array(), $code = 302)
 {
     $url = Router::getUrl($module, $controller, $params);
     $exception = Response::getException();
     $this->assertInstanceOf('\\Bluz\\Application\\Exception\\RedirectException', $exception);
     $this->assertEquals($exception->getCode(), $code);
     $this->assertEquals($exception->getMessage(), $url);
 }
Beispiel #2
0
 /**
  * Test Router Url for custom controller route
  *
  * @dataProvider providerForCustomRoutes
  * @param string $url
  * @param string $module
  * @param string $controller
  * @param array $params
  */
 public function testRouterUrlWithCustomControllerRoute($url, $module, $controller, $params = [])
 {
     $this->assertEquals($url, Router::getUrl($module, $controller, $params));
 }
Beispiel #3
0
<?php

/**
 * Bluz Framework Component
 *
 * @copyright Bluz PHP Team
 * @link https://github.com/bluzphp/framework
 */
/**
 * @namespace
 */
namespace Bluz\Application\Helper;

use Bluz\Application\Application;
use Bluz\Proxy\Router;
return function ($module = 'index', $controller = 'index', $params = array()) {
    $url = Router::getUrl($module, $controller, $params);
    $this->redirect($url);
};
Beispiel #4
0
 /**
  * Get Url
  *
  * @param  array $params
  * @return string
  */
 public function getUrl($params)
 {
     // prepare params
     $params = $this->getParams($params);
     // retrieve URL
     return Router::getUrl($this->getModule(), $this->getController(), $params);
 }
Beispiel #5
0
 /**
  * Method POST
  *
  * @return array|false
  * @throws BadRequestException
  * @throws NotImplementedException
  */
 public function methodPost()
 {
     if (!empty($this->primary)) {
         // POST + ID is incorrect behaviour
         throw new NotImplementedException();
     }
     try {
         $result = $this->createOne($this->data);
         if (!$result) {
             // system can't create record with this data
             throw new BadRequestException();
         }
         if (is_array($result)) {
             $result = join('-', array_values($result));
         }
     } catch (ValidatorException $e) {
         Response::setStatusCode(400);
         return ['errors' => $e->getErrors()];
     }
     Response::setStatusCode(201);
     Response::setHeader('Location', Router::getUrl(Request::getModule(), Request::getController()) . '/' . $result);
     return false;
     // disable view
 }
Beispiel #6
0
<?php

/**
 * @author   Anton Shevchuk
 * @created  22.10.12 18:40
 */
namespace Application;

use Bluz\Proxy\Router;
return function () {
    /**
     * @var Bootstrap $this
     */
    ?>
    <a href="<?php 
    echo Router::getUrl('facebook', 'auth');
    ?>
" class="btn fa fa-facebook-square fa-2x"></a>
    <?php 
};
Beispiel #7
0
<?php

namespace Application;

use Bluz\Proxy\Router;
return function () {
    /**
     * @var Bootstrap $this
     */
    ?>
        <a href="<?php 
    echo Router::getUrl('google', 'auth');
    ?>
" class="btn fa fa-google-plus-square fa-2x"></a>
    <?php 
};
Beispiel #8
0
 * @param  bool   $checkAccess
 * @return null|string
 * @throws ViewException
 */
return function ($module, $controller, $params = [], $checkAccess = false) {
    /**
     * @var View $this
     */
    try {
        if ($checkAccess) {
            try {
                $controllerInstance = new Controller($module, $controller);
                $controllerInstance->checkPrivilege();
            } catch (ForbiddenException $e) {
                return null;
            }
        }
    } catch (\Exception $e) {
        throw new ViewException('Url View Helper: ' . $e->getMessage());
    }
    if (null === $module) {
        $module = Request::getModule();
    }
    if (null === $controller) {
        $controller = Request::getController();
    }
    if (null === $params) {
        $params = Request::getParams();
    }
    return Router::getUrl($module, $controller, $params);
};
Beispiel #9
0
 /**
  * Redirect to controller
  *
  * @param  string      $module
  * @param  string      $controller
  * @param  array       $params
  * @return void
  */
 public static function redirectTo($module = 'index', $controller = 'index', $params = [])
 {
     $url = Router::getUrl($module, $controller, $params);
     self::redirect($url);
 }
Beispiel #10
0
 * @accept JSON
 * @method POST
 *
 * @param  \Bluz\Crud\Table $crud
 * @param  mixed $primary
 * @param  array $data
 * @return void|array
 * @throws BadRequestException
 * @throws NotImplementedException
 */
return function ($crud, $primary, $data) {
    if (!empty($primary)) {
        // POST + ID is incorrect behaviour
        throw new NotImplementedException();
    }
    try {
        $result = $crud->createOne($data);
        if (!$result) {
            // system can't create record with this data
            throw new BadRequestException();
        }
        if (is_array($result)) {
            $result = join('-', array_values($result));
        }
    } catch (ValidatorException $e) {
        Response::setStatusCode(400);
        return ['errors' => $e->getErrors()];
    }
    Response::setStatusCode(201);
    Response::setHeader('Location', Router::getUrl(Request::getModule(), Request::getController()) . '/' . $result);
};
Beispiel #11
0
 /**
  * Denied access
  * @param ForbiddenException $exception
  * @return \Bluz\Controller\Controller|null
  */
 public function forbidden(ForbiddenException $exception)
 {
     if (AuthProxy::getIdentity()) {
         $message = Translator::translate("You don't have permissions to access this page");
     } else {
         $message = Translator::translate("You don't have permissions, please sign in");
     }
     // for AJAX and API calls (over JSON)
     $jsonOrApi = Request::isXmlHttpRequest() || Request::getAccept([Request::TYPE_HTML, Request::TYPE_JSON]) == Request::TYPE_JSON;
     // for guest, for requests
     if (!AuthProxy::getIdentity() && !$jsonOrApi) {
         // save URL to session and redirect make sense if presentation is null
         Session::set('rollback', Request::getUri()->__toString());
         // add error notice
         Messages::addError($message);
         // redirect to Sign In page
         $url = Router::getUrl('users', 'signin');
         return $this->redirect($url);
     } else {
         return $this->error(new ForbiddenException($message, 403, $exception));
     }
 }
Beispiel #12
0
">
                    <i class="fa fa-eye fa-fw"></i>
                    <strong><?php 
    echo $active;
    ?>
</strong>
                    <small><?php 
    echo __('Active Users');
    ?>
</small>
                    </a>
                </li>
                <li class="divider"></li>
                <li>
                    <a href="<?php 
    echo Router::getUrl('users', 'profile', ['id' => $last['id']]);
    ?>
">
                    <i class="fa fa-user fa-fw"></i>
                    <strong><?php 
    echo $last['login'];
    ?>
</strong>
                    <small><?php 
    echo __('Last Registers');
    ?>
</small>
                    </a>
                </li>
            </ul>
        </div>
Beispiel #13
0
<?php

/**
 * @author   Anton Shevchuk
 * @created  22.10.12 18:40
 */
namespace Application;

use Bluz\Proxy\Router;
return function () {
    /**
     * @var Bootstrap $this
     */
    ?>
    <a href="<?php 
    echo Router::getUrl('twitter', 'auth');
    ?>
" class="btn fa fa-twitter-square fa-2x"></a>
    <?php 
};