function smarty_function_action_attributes($params, &$view)
{
    $availableMethods = array('get', 'post', 'put', 'delete');
    $methodsParams = array_intersect($availableMethods, array_keys($params));
    $method = reset($methodsParams);
    if (empty($method)) {
        return;
    }
    $assign = '';
    if (isset($params['assign'])) {
        $assign = $params['assign'];
        unset($params['assign']);
    }
    $pattern = $params[$method];
    unset($params[$method]);
    $resource = Route::resource($pattern, $params);
    $prefix = App::getLinkPrefix($params);
    $result = ' data-method="' . $method . '"';
    $result .= ' data-resource="' . $prefix . ltrim($resource, '/') . '"';
    list($preg, $map) = Url::preg($pattern);
    $result .= ' data-params="' . http_build_query(array_diff_key($params, array_flip($map))) . '"';
    $result .= ' ';
    if ($assign) {
        $view->assign($assign, $result);
        $link = '';
    }
    return $result;
}
Пример #2
0
function smarty_block_iflocation($params, $content, &$view, &$repeat)
{
    if (empty($content) || empty($params['get'])) {
        return '';
    }
    $pattern = Url::trim($params['get']);
    $needed = Url::resource($pattern, $params);
    if (empty($needed)) {
        return '';
    }
    $resource = Url::trim(\Pina\Core::resource());
    if (strpos($resource, $needed) === 0) {
        return $content;
    }
    return '';
}
Пример #3
0
function smarty_block_iflocation($params, $content, &$view, &$repeat)
{
    if (empty($content) || empty($params['get'])) {
        return '';
    }
    $pattern = Url::trim($params['get']);
    $needed = Route::resource($pattern, $params);
    if (empty($needed)) {
        return '';
    }
    $resource = Url::trim(\Pina\Core::resource());
    if (strpos($resource, $needed) !== 0) {
        return '';
    }
    list($preg, $map) = Url::preg($params['get']);
    $data = \Pina\Core::getRequestData();
    unset($params['get']);
    $params = array_diff_key($params, array_flip($map));
    unset($data['get']);
    if (array_diff_assoc($data, $params) || array_diff_assoc($params, $data)) {
        return '';
    }
    return $content;
}
Пример #4
0
 /**
  * @dataProvider resourceProvider
  */
 public function testResoute($pattern, $parsed, $expected)
 {
     $this->assertEquals($expected, Url::resource($pattern, $parsed));
 }