Initial commit: apps.supersam24.ru
This commit is contained in:
commit
e955e1da36
6566 files changed
+1271095
No files matched your search
+20
@@ -0,0 +1,20 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.3
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
- 7.0
|
||||
- hhvm
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- php: 7.0
|
||||
|
||||
install:
|
||||
- composer install
|
||||
|
||||
script:
|
||||
- php bin/phpspec run -f pretty
|
||||
- php ./bin/phpunit tests
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
<h3 align="center">
|
||||
<a href="https://github.com/umpirsky">
|
||||
<img src="https://farm2.staticflickr.com/1709/25098526884_ae4d50465f_o_d.png" />
|
||||
</a>
|
||||
</h3>
|
||||
<p align="center">
|
||||
<a href="https://github.com/umpirsky/Symfony-Upgrade-Fixer">symfony upgrade fixer</a> •
|
||||
<a href="https://github.com/umpirsky/Twig-Gettext-Extractor">twig gettext extractor</a> •
|
||||
<a href="https://github.com/umpirsky/wisdom">wisdom</a> •
|
||||
<a href="https://github.com/umpirsky/centipede">centipede</a> •
|
||||
<a href="https://github.com/umpirsky/PermissionsHandler">permissions handler</a> •
|
||||
<a href="https://github.com/umpirsky/Extraload">extraload</a> •
|
||||
<a href="https://github.com/umpirsky/Gravatar">gravatar</a> •
|
||||
<a href="https://github.com/umpirsky/locurro">locurro</a> •
|
||||
<a href="https://github.com/umpirsky/country-list">country list</a> •
|
||||
<a href="https://github.com/umpirsky/Transliterator">transliterator</a>
|
||||
</p>
|
||||
|
||||
# Twig PHP Function [](https://travis-ci.org/umpirsky/twig-php-function)
|
||||
|
||||
Call (almost) any PHP function from your Twig templates.
|
||||
|
||||
## Usage
|
||||
|
||||
After [registering](http://twig.sensiolabs.org/doc/advanced.html#creating-an-extension) `PhpFunctionExtension` call PHP functions from your templates like this:
|
||||
|
||||
```twig
|
||||
Hi, I am unique: {{ uniqid() }}.
|
||||
|
||||
And {{ floor(7.7) }} is floor of 7.7.
|
||||
```
|
||||
|
||||
## Extend
|
||||
|
||||
You can control allowed PHP functions by adding new ones like this:
|
||||
|
||||
```php
|
||||
$extension = new Umpirsky\Twig\Extension\PhpFunctionExtension();
|
||||
$extension->allowFunction('hash_hmac');
|
||||
```
|
||||
|
||||
or restrict what functions are allowed like this:
|
||||
|
||||
```php
|
||||
$extension = new Umpirsky\Twig\Extension\PhpFunctionExtension(['floor', 'ceil']);
|
||||
|
||||
```
|
||||
|
||||
If you think that some function should be allowed/not allowed, feel free to [raise issue](https://github.com/umpirsky/twig-php-function/issues/new) or submit a pull request.
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "umpirsky/twig-php-function",
|
||||
"type": "library",
|
||||
"description": "Call (almost) any PHP function from your Twig templates.",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Saša Stamenković",
|
||||
"email": "umpirsky@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.3",
|
||||
"twig/twig": "~1.12"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpspec/phpspec": "~2.0",
|
||||
"phpunit/phpunit": "~4.4"
|
||||
},
|
||||
"config": {
|
||||
"bin-dir": "bin"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": { "Umpirsky\\": "src/" }
|
||||
}
|
||||
}
|
||||
+1245
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
require __DIR__.'/../vendor/autoload.php';
|
||||
|
||||
$loader = new Twig_Loader_Array(array(
|
||||
'uniqid' => 'Hi, I am unique: {{ php_uniqid() }}.',
|
||||
'floor' => 'And {{ php_floor(7.7) }} is floor of 7.7.',
|
||||
));
|
||||
|
||||
$twig = new Twig_Environment($loader);
|
||||
$twig->addExtension(new Umpirsky\Twig\Extension\PhpFunctionExtension());
|
||||
|
||||
echo $twig->render('uniqid') . PHP_EOL;
|
||||
echo $twig->render('floor') . PHP_EOL;
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace spec\Umpirsky\Twig\Extension;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class PhpFunctionExtensionSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('Umpirsky\Twig\Extension\PhpFunctionExtension');
|
||||
}
|
||||
|
||||
function it_is_a_Twig_extension()
|
||||
{
|
||||
$this->shouldHaveType('Twig_Extension');
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Umpirsky\Twig\Extension;
|
||||
|
||||
use Twig_Extension;
|
||||
use Twig_SimpleFunction;
|
||||
use BadFunctionCallException;
|
||||
|
||||
class PhpFunctionExtension extends Twig_Extension
|
||||
{
|
||||
private $functions = array(
|
||||
'uniqid',
|
||||
'floor',
|
||||
'ceil',
|
||||
'addslashes',
|
||||
'chr',
|
||||
'chunk_split',
|
||||
'convert_uudecode',
|
||||
'crc32',
|
||||
'crypt',
|
||||
'hex2bin',
|
||||
'md5',
|
||||
'sha1',
|
||||
'strpos',
|
||||
'strrpos',
|
||||
'ucwords',
|
||||
'wordwrap',
|
||||
'gettype',
|
||||
);
|
||||
|
||||
public function __construct(array $functions = array())
|
||||
{
|
||||
if ($functions) {
|
||||
$this->allowFunctions($functions);
|
||||
}
|
||||
}
|
||||
|
||||
public function getFunctions()
|
||||
{
|
||||
$twigFunctions = array();
|
||||
|
||||
foreach ($this->functions as $function) {
|
||||
$twigFunctions[] = new Twig_SimpleFunction($function, $function);
|
||||
}
|
||||
|
||||
return $twigFunctions;
|
||||
}
|
||||
|
||||
public function allowFunction($function)
|
||||
{
|
||||
$this->functions[] = $function;
|
||||
}
|
||||
|
||||
public function allowFunctions(array $functions)
|
||||
{
|
||||
$this->functions = $functions;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'php_function';
|
||||
}
|
||||
}
|
||||
Vendored
+38
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
class PhpFunctionExtensionTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $twig;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$loader = new Twig_Loader_Array(array(
|
||||
'md5' => '{{ md5("umpirsky") }} is md5 of umpirsky.',
|
||||
'floor' => '{{ floor(7.7) }} is floor of 7.7.',
|
||||
'ceil' => '{{ ceil(6.7) }} is ceil of 6.7.',
|
||||
));
|
||||
|
||||
$this->twig = new Twig_Environment($loader);
|
||||
$this->twig->addExtension(new Umpirsky\Twig\Extension\PhpFunctionExtension());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider renderProvider
|
||||
*/
|
||||
public function testRenderedOutput($key, $expected)
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->twig->render($key),
|
||||
$expected
|
||||
);
|
||||
}
|
||||
|
||||
public function renderProvider()
|
||||
{
|
||||
return array(
|
||||
array('md5', 'f0d0a45e43690965bd6689a2ae3c8943 is md5 of umpirsky.'),
|
||||
array('floor', '7 is floor of 7.7.'),
|
||||
array('ceil', '7 is ceil of 6.7.'),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user