Example #1
0
<?php

#compile
$this->runtimeVariable('permission', '${permission}');
/**
 * @var string                          $permission
 * @var \Spiral\Security\GuardInterface $guard
 */
$guard = spiral(\Spiral\Security\GuardInterface::class);
if ($guard->allows($permission)) {
    ob_start();
    ?>
${context}<?php 
    echo ob_get_clean();
}
Example #2
0
 /**
  * @return \Spiral\Vault\Vault
  */
 function vault()
 {
     return spiral(\Spiral\Vault\Vault::class);
 }
Example #3
0
<?php

$__cacheKey__ = !empty('${key}') ? '${key}' : md5(__FILE__ . '.' . __LINE__);
/**
 * @var \Spiral\Cache\StoreInterface $__cacheStore__
 */
$__cacheStore__ = spiral(\Spiral\Cache\StoreInterface::class);
if ($__cacheStore__->has($__cacheKey__)) {
    echo $__cacheStore__->get($__cacheKey__);
} else {
    ob_start();
    ?>
${context}<?php 
    echo $__cached__ = ob_get_clean();
    $__cacheStore__->set($__cacheKey__, $__cached__, (int) '${lifetime|60}');
}
Example #4
0
 /**
  * Return a URL safe version of a string.
  *
  * @param string $string
  * @param string $separator
  * @return string
  */
 public static function slug($string, $separator = '-')
 {
     return spiral(SlugifyInterface::class)->slugify($string, $separator);
 }
Example #5
0
<dark:extends path="vault:layouts/root"/>

<define:brand>
    <a href="/" class="brand-logo">
        <img src="@{basePath}resources/images/spiral.svg" alt="Spiral">
    </a>
</define:brand>

<!--Following resources block can be redefined on a project basis-->
<define:resources>
    <block:resources/>
</define:resources>

<!--You can replace this block to render project specific actor-->
<define:user-block>
    <a href="#" class="user-link">
        <?php 
echo get_class(spiral(\Spiral\Security\ActorInterface::class));
?>
    </a>
    <a href="#" class="user-logout hide">[[Log Out]]</a>
</define:user-block>
Example #6
0
<!DOCTYPE html>
<yield:functions/>
<html>
<head>
    <block:head>
        <title>${title}</title>
        <script>
            window.csrfToken = "<?php 
echo spiral('request')->getAttribute('csrfToken');
?>
";
        </script>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <block:resources/>
        <!--[STYLES]-->
    </block:head>
</head>
<body>
<yield:body/>
<!--[SCRIPTS]-->
</body>
</html>
Example #7
0
 /**
  * Create uri for route and parameters.
  *
  * @param string $route
  * @param array  $parameters
  * @return \Psr\Http\Message\UriInterface
  */
 function uri($route, $parameters = [])
 {
     if (!is_array($parameters) && !$parameters instanceof Traversable) {
         $parameters = array_slice(func_get_args(), 1);
     }
     return spiral(RouterInterface::class)->uri($route, $parameters);
 }
/**
 * Test adapter.
 *
 * It emulates the behaviour of the CLI and collects the output to be tested.
 * It tests both the normal and the golfed versions of the function.
 *
 * @param string $input    the input string
 * @param string $expected the expected output
 */
function testSpiral($input, $expected)
{
    //
    // Convert the input string to a list of command line arguments
    $matches = [];
    if (!preg_match('/(\\d+)([durl])(c?)(\\d+)/', $input, $matches)) {
        it('does not work for invalid input', TRUE);
        return;
    }
    // This statement is not really needed
    $matches[0] = __FILE__;
    //
    // Test the detailed version of the function
    ob_start();
    spiral($matches);
    $actual = rtrim(ob_get_clean());
    it(sprintf('works for input: %s (detailed version)', $input), $expected == $actual);
    // Uncomment the next line to visually inspect the output when a test fails
    //echo($actual);
    //
    // Test the golfed version of the function
    ob_start();
    s($matches);
    $actual = rtrim(ob_get_clean());
    it(sprintf('works for input: %s (golfed version)', $input), $expected == $actual);
    // Uncomment the next line to visually inspect the output when a test fails
    //echo($actual);
}