Added vendor/ directory for Composer's installed files
This commit is contained in:
181
vendor/slim/views/README.md
vendored
Executable file
181
vendor/slim/views/README.md
vendored
Executable file
@ -0,0 +1,181 @@
|
||||
# Slim Views
|
||||
|
||||
This repository contains custom View classes for the template frameworks listed below.
|
||||
You can use any of these custom View classes by either requiring the appropriate class in your
|
||||
Slim Framework bootstrap file and initialize your Slim application using an instance of
|
||||
the selected View class or using Composer (the recommended way).
|
||||
|
||||
Slim Views only officially support the following views listed below.
|
||||
|
||||
- Smarty
|
||||
- Twig
|
||||
|
||||
## How to Install
|
||||
|
||||
#### using [Composer](http://getcomposer.org/)
|
||||
|
||||
Install in your project by running the following composer command:
|
||||
|
||||
```bash
|
||||
$ php composer require slim/views
|
||||
```
|
||||
|
||||
## Smarty
|
||||
|
||||
### How to use
|
||||
|
||||
```php
|
||||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
$app = new \Slim\Slim(array(
|
||||
'view' => new \Slim\Views\Smarty()
|
||||
));
|
||||
```
|
||||
|
||||
To use Smarty options do the following:
|
||||
|
||||
```php
|
||||
$view = $app->view();
|
||||
$view->parserDirectory = dirname(__FILE__) . 'smarty';
|
||||
$view->parserCompileDirectory = dirname(__FILE__) . '/compiled';
|
||||
$view->parserCacheDirectory = dirname(__FILE__) . '/cache';
|
||||
```
|
||||
|
||||
## Twig
|
||||
|
||||
### How to use
|
||||
|
||||
```php
|
||||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
$app = new \Slim\Slim(array(
|
||||
'view' => new \Slim\Views\Twig()
|
||||
));
|
||||
```
|
||||
|
||||
To use Twig options do the following:
|
||||
|
||||
```php
|
||||
$view = $app->view();
|
||||
$view->parserOptions = array(
|
||||
'debug' => true,
|
||||
'cache' => dirname(__FILE__) . '/cache'
|
||||
);
|
||||
```
|
||||
|
||||
In addition to all of this we also have a few helper functions which are included for both view parsers.
|
||||
In order to start using these you can add them to their respective view parser as stated below:
|
||||
|
||||
#### Twig
|
||||
|
||||
```php
|
||||
$view->parserExtensions = array(
|
||||
new \Slim\Views\TwigExtension(),
|
||||
);
|
||||
```
|
||||
|
||||
#### Smarty
|
||||
|
||||
```php
|
||||
$view->parserExtensions = array(
|
||||
dirname(__FILE__) . '/vendor/slim/views/Slim/Views/SmartyPlugins',
|
||||
);
|
||||
```
|
||||
|
||||
These helpers are listed below.
|
||||
|
||||
- urlFor
|
||||
- siteUrl
|
||||
- baseUrl
|
||||
- currentUrl
|
||||
|
||||
#### urlFor
|
||||
|
||||
__Twig__
|
||||
|
||||
Inside your Twig template you would write:
|
||||
|
||||
{{ urlFor('hello', {"name": "Josh", "age": "19"}) }}
|
||||
|
||||
You can easily pass variables that are objects or arrays by doing:
|
||||
|
||||
<a href="{{ urlFor('hello', {"name": person.name, "age": person.age}) }}">Hello {{ name }}</a>
|
||||
|
||||
If you need to specify the appname for the getInstance method in the urlFor functions, set it as the third parameter of the function
|
||||
in your template:
|
||||
|
||||
<a href="{{ urlFor('hello', {"name": person.name, "age": person.age}, 'admin') }}">Hello {{ name }}</a>
|
||||
|
||||
__Smarty__
|
||||
|
||||
Inside your Smarty template you would write:
|
||||
|
||||
{urlFor name="hello" options="name.Josh|age.26"}
|
||||
|
||||
or with the new array syntax:
|
||||
|
||||
{urlFor name="hello" options=["name" => "Josh", "age" => "26"]}
|
||||
|
||||
You can easily pass variables that are arrays as normal or using the (.):
|
||||
|
||||
<a href="{urlFor name="hello" options="name.{$person.name}|age.{$person.age}"}">Hello {$name}</a>
|
||||
|
||||
If you need to specify the appname for the getInstance method in the urlFor functions, set the appname parameter in your function:
|
||||
|
||||
<a href="{urlFor name="hello" appname="admin" options="name.{$person.name}|age.{$person.age}"}">Hello {$name}</a>
|
||||
|
||||
#### siteUrl
|
||||
|
||||
__Twig__
|
||||
|
||||
Inside your Twig template you would write:
|
||||
|
||||
{{ siteUrl('/about/me') }}
|
||||
|
||||
__Smarty__
|
||||
|
||||
Inside your Smarty template you would write:
|
||||
|
||||
{siteUrl url='/about/me'}
|
||||
|
||||
|
||||
#### baseUrl
|
||||
|
||||
__Twig__
|
||||
|
||||
Inside your Twig template you would write:
|
||||
|
||||
{{ baseUrl() }}
|
||||
|
||||
__Smarty__
|
||||
|
||||
Inside your Smarty template you would write:
|
||||
|
||||
{baseUrl}
|
||||
|
||||
|
||||
#### currentUrl
|
||||
|
||||
__Twig__
|
||||
|
||||
Inside your Twig template you would write:
|
||||
|
||||
{{ currentUrl() }}
|
||||
|
||||
__Smarty__
|
||||
|
||||
Inside your Smarty template you would write:
|
||||
|
||||
{currentUrl}
|
||||
|
||||
## Authors
|
||||
|
||||
[Josh Lockhart](https://github.com/codeguy)
|
||||
|
||||
[Andrew Smith](https://github.com/silentworks)
|
||||
|
||||
## License
|
||||
|
||||
MIT Public License
|
124
vendor/slim/views/Smarty.php
vendored
Executable file
124
vendor/slim/views/Smarty.php
vendored
Executable file
@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/**
|
||||
* Slim - a micro PHP 5 framework
|
||||
*
|
||||
* @author Josh Lockhart
|
||||
* @author Andrew Smith
|
||||
* @link http://www.slimframework.com
|
||||
* @copyright 2013 Josh Lockhart
|
||||
* @version 0.1.3
|
||||
* @package SlimViews
|
||||
*
|
||||
* MIT LICENSE
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
namespace Slim\Views;
|
||||
|
||||
/**
|
||||
* SmartyView
|
||||
*
|
||||
* The SmartyView is a custom View class that renders templates using the Smarty
|
||||
* template language (http://www.smarty.net).
|
||||
*
|
||||
* Two fields that you, the developer, will need to change are:
|
||||
* - parserDirectory
|
||||
* - parserCompileDirectory
|
||||
* - parserCacheDirectory
|
||||
*
|
||||
* @package Slim
|
||||
* @author Jose da Silva <http://josedasilva.net>
|
||||
*/
|
||||
class Smarty extends \Slim\View
|
||||
{
|
||||
/**
|
||||
* @var string The path to the Smarty code directory WITHOUT the trailing slash
|
||||
*/
|
||||
public $parserDirectory = null;
|
||||
|
||||
/**
|
||||
* @var string The path to the Smarty compiled templates folder WITHOUT the trailing slash
|
||||
*/
|
||||
public $parserCompileDirectory = null;
|
||||
|
||||
/**
|
||||
* @var string The path to the Smarty cache folder WITHOUT the trailing slash
|
||||
*/
|
||||
public $parserCacheDirectory = null;
|
||||
|
||||
/**
|
||||
* @var SmartyExtensions The Smarty extensions directory you want to load plugins from
|
||||
*/
|
||||
public $parserExtensions = array();
|
||||
|
||||
/**
|
||||
* @var parserInstance persistent instance of the Parser object.
|
||||
*/
|
||||
private $parserInstance = null;
|
||||
|
||||
/**
|
||||
* Render Template
|
||||
*
|
||||
* This method will output the rendered template content
|
||||
*
|
||||
* @param string $template The path to the template, relative to the templates directory.
|
||||
* @param null $data
|
||||
* @return string
|
||||
*/
|
||||
public function render($template, $data = null)
|
||||
{
|
||||
$parser = $this->getInstance();
|
||||
$parser->assign($this->all());
|
||||
|
||||
return $parser->fetch($template, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new Smarty object instance if it doesn't already exist, and returns it.
|
||||
*
|
||||
* @throws \RuntimeException If Smarty lib directory does not exist
|
||||
* @return \Smarty Instance
|
||||
*/
|
||||
public function getInstance()
|
||||
{
|
||||
if (!($this->parserInstance instanceof \Smarty)) {
|
||||
if (!class_exists('\Smarty')) {
|
||||
if (!is_dir($this->parserDirectory)) {
|
||||
throw new \RuntimeException('Cannot set the Smarty lib directory : ' . $this->parserDirectory . '. Directory does not exist.');
|
||||
}
|
||||
require_once $this->parserDirectory . '/Smarty.class.php';
|
||||
}
|
||||
|
||||
$this->parserInstance = new \Smarty();
|
||||
$this->parserInstance->template_dir = $this->getTemplatesDirectory();
|
||||
if ($this->parserExtensions) {
|
||||
$this->parserInstance->addPluginsDir($this->parserExtensions);
|
||||
}
|
||||
if ($this->parserCompileDirectory) {
|
||||
$this->parserInstance->compile_dir = $this->parserCompileDirectory;
|
||||
}
|
||||
if ($this->parserCacheDirectory) {
|
||||
$this->parserInstance->cache_dir = $this->parserCacheDirectory;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->parserInstance;
|
||||
}
|
||||
}
|
26
vendor/slim/views/SmartyPlugins/function.baseUrl.php
vendored
Executable file
26
vendor/slim/views/SmartyPlugins/function.baseUrl.php
vendored
Executable file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/*
|
||||
* Smarty plugin
|
||||
* -------------------------------------------------------------
|
||||
* File: function.baseUrl.php
|
||||
* Type: function
|
||||
* Name: baseUrl
|
||||
* Purpose: outputs url for a function with the defined name method
|
||||
* version 0.1.3
|
||||
* package SlimViews
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
function smarty_function_baseUrl($params, $template)
|
||||
{
|
||||
$withUri = isset($params['withUri']) ? $params['withUri'] : true;
|
||||
$appName = isset($params['appname']) ? $params['appname'] : 'default';
|
||||
|
||||
$req = \Slim\Slim::getInstance($appName)->request();
|
||||
$uri = $req->getUrl();
|
||||
|
||||
if ($withUri) {
|
||||
$uri .= $req->getRootUri();
|
||||
}
|
||||
|
||||
return $uri;
|
||||
}
|
31
vendor/slim/views/SmartyPlugins/function.currentUrl.php
vendored
Executable file
31
vendor/slim/views/SmartyPlugins/function.currentUrl.php
vendored
Executable file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/*
|
||||
* Smarty plugin
|
||||
* -------------------------------------------------------------
|
||||
* File: function.currentUrl.php
|
||||
* Type: function
|
||||
* Name: currentUrl
|
||||
* Purpose: outputs url for a function with the defined name method
|
||||
* version 0.1.3
|
||||
* package SlimViews
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
function smarty_function_currentUrl($params, $template)
|
||||
{
|
||||
$appName = isset($params['appname']) ? $params['appname'] : 'default';
|
||||
$withQueryString = isset($params['queryString']) ? $params['queryString'] : true;
|
||||
|
||||
$app = \Slim\Slim::getInstance($appName);
|
||||
$req = $app->request();
|
||||
$uri = $req->getUrl() . $req->getPath();
|
||||
|
||||
if ($withQueryString) {
|
||||
$env = $app->environment();
|
||||
|
||||
if ($env['QUERY_STRING']) {
|
||||
$uri .= '?' . $env['QUERY_STRING'];
|
||||
}
|
||||
}
|
||||
|
||||
return $uri;
|
||||
}
|
27
vendor/slim/views/SmartyPlugins/function.siteUrl.php
vendored
Executable file
27
vendor/slim/views/SmartyPlugins/function.siteUrl.php
vendored
Executable file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/*
|
||||
* Smarty plugin
|
||||
* -------------------------------------------------------------
|
||||
* File: function.siteUrl.php
|
||||
* Type: function
|
||||
* Name: siteUrl
|
||||
* Purpose: outputs url for a function with the defined name method
|
||||
* version 0.1.3
|
||||
* package SlimViews
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
function smarty_function_siteUrl($params, $template)
|
||||
{
|
||||
$withUri = isset($params['withUri']) ? $params['withUri'] : true;
|
||||
$appName = isset($params['appname']) ? $params['appname'] : 'default';
|
||||
$url = isset($params['url']) ? $params['url'] : '';
|
||||
|
||||
$req = \Slim\Slim::getInstance($appName)->request();
|
||||
$uri = $req->getUrl();
|
||||
|
||||
if ($withUri) {
|
||||
$uri .= $req->getRootUri();
|
||||
}
|
||||
|
||||
return $uri . '/' . ltrim($url, '/');
|
||||
}
|
42
vendor/slim/views/SmartyPlugins/function.urlFor.php
vendored
Executable file
42
vendor/slim/views/SmartyPlugins/function.urlFor.php
vendored
Executable file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
* -------------------------------------------------------------
|
||||
* File: function.urlFor.php
|
||||
* Type: function
|
||||
* Name: urlFor
|
||||
* Purpose: outputs url for a function with the defined name method
|
||||
* @version 0.1.3
|
||||
* @package SlimViews
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
function smarty_function_urlFor($params, $template)
|
||||
{
|
||||
$name = isset($params['name']) ? $params['name'] : '';
|
||||
$appName = isset($params['appname']) ? $params['appname'] : 'default';
|
||||
|
||||
$url = \Slim\Slim::getInstance($appName)->urlFor($name);
|
||||
|
||||
if (isset($params['options'])) {
|
||||
switch (gettype($params['options'])) {
|
||||
case 'array':
|
||||
$opts = $params['options'];
|
||||
break;
|
||||
|
||||
case 'string':
|
||||
$options = explode('|', $params['options']);
|
||||
foreach ($options as $option) {
|
||||
list($key, $value) = explode('.', $option);
|
||||
$opts[$key] = $value;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new \Exception('Options parameter is of unknown type, provide either string or array');
|
||||
}
|
||||
|
||||
$url = \Slim\Slim::getInstance($appName)->urlFor($name, $opts);
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
153
vendor/slim/views/Twig.php
vendored
Executable file
153
vendor/slim/views/Twig.php
vendored
Executable file
@ -0,0 +1,153 @@
|
||||
<?php
|
||||
/**
|
||||
* Slim - a micro PHP 5 framework
|
||||
*
|
||||
* @author Josh Lockhart
|
||||
* @author Andrew Smith
|
||||
* @link http://www.slimframework.com
|
||||
* @copyright 2013 Josh Lockhart
|
||||
* @version 0.1.3
|
||||
* @package SlimViews
|
||||
*
|
||||
* MIT LICENSE
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
namespace Slim\Views;
|
||||
|
||||
/**
|
||||
* Twig view
|
||||
*
|
||||
* The Twig view is a custom View class that renders templates using the Twig
|
||||
* template language (http://www.twig-project.org/).
|
||||
*
|
||||
* Two fields that you, the developer, will need to change are:
|
||||
* - parserDirectory
|
||||
* - parserOptions
|
||||
*/
|
||||
class Twig extends \Slim\View
|
||||
{
|
||||
/**
|
||||
* @var string The path to the Twig code directory WITHOUT the trailing slash
|
||||
*/
|
||||
public $parserDirectory = null;
|
||||
|
||||
/**
|
||||
* DEPRECATION WARNING! This method will be removed in the next major point release
|
||||
*
|
||||
* @var array Paths to directories to attempt to load Twig template from
|
||||
*/
|
||||
public $twigTemplateDirs = array();
|
||||
|
||||
/**
|
||||
* @var array The options for the Twig environment, see
|
||||
* http://www.twig-project.org/book/03-Twig-for-Developers
|
||||
*/
|
||||
public $parserOptions = array();
|
||||
|
||||
/**
|
||||
* @var TwigExtension The Twig extensions you want to load
|
||||
*/
|
||||
public $parserExtensions = array();
|
||||
|
||||
/**
|
||||
* @var TwigEnvironment The Twig environment for rendering templates.
|
||||
*/
|
||||
private $parserInstance = null;
|
||||
|
||||
/**
|
||||
* Render Twig Template
|
||||
*
|
||||
* This method will output the rendered template content
|
||||
*
|
||||
* @param string $template The path to the Twig template, relative to the Twig templates directory.
|
||||
* @param null $data
|
||||
* @return string
|
||||
*/
|
||||
public function render($template, $data = null)
|
||||
{
|
||||
$env = $this->getInstance();
|
||||
$parser = $env->loadTemplate($template);
|
||||
|
||||
$data = array_merge($this->all(), (array) $data);
|
||||
|
||||
return $parser->render($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* DEPRECATION WARNING! This method will be removed in the next major point release
|
||||
*
|
||||
* Use getInstance method instead
|
||||
*/
|
||||
public function getEnvironment()
|
||||
{
|
||||
return $this->getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new TwigEnvironment if it doesn't already exist, and returns it.
|
||||
*
|
||||
* @return \Twig_Environment
|
||||
*/
|
||||
public function getInstance()
|
||||
{
|
||||
if (!$this->parserInstance) {
|
||||
/**
|
||||
* Check if Twig_Autoloader class exists
|
||||
* otherwise include it.
|
||||
*/
|
||||
if (!class_exists('\Twig_Autoloader')) {
|
||||
require_once $this->parserDirectory . '/Autoloader.php';
|
||||
}
|
||||
|
||||
\Twig_Autoloader::register();
|
||||
$loader = new \Twig_Loader_Filesystem($this->getTemplateDirs());
|
||||
$this->parserInstance = new \Twig_Environment(
|
||||
$loader,
|
||||
$this->parserOptions
|
||||
);
|
||||
|
||||
foreach ($this->parserExtensions as $ext) {
|
||||
$extension = is_object($ext) ? $ext : new $ext;
|
||||
$this->parserInstance->addExtension($extension);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->parserInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* DEPRECATION WARNING! This method will be removed in the next major point release
|
||||
*
|
||||
* Get a list of template directories
|
||||
*
|
||||
* Returns an array of templates defined by self::$twigTemplateDirs, falls
|
||||
* back to Slim\View's built-in getTemplatesDirectory method.
|
||||
*
|
||||
* @return array
|
||||
**/
|
||||
private function getTemplateDirs()
|
||||
{
|
||||
if (empty($this->twigTemplateDirs)) {
|
||||
return array($this->getTemplatesDirectory());
|
||||
}
|
||||
return $this->twigTemplateDirs;
|
||||
}
|
||||
}
|
91
vendor/slim/views/TwigExtension.php
vendored
Executable file
91
vendor/slim/views/TwigExtension.php
vendored
Executable file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* Slim - a micro PHP 5 framework
|
||||
*
|
||||
* @author Josh Lockhart
|
||||
* @author Andrew Smith
|
||||
* @link http://www.slimframework.com
|
||||
* @copyright 2013 Josh Lockhart
|
||||
* @version 0.1.3
|
||||
* @package SlimViews
|
||||
*
|
||||
* MIT LICENSE
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
namespace Slim\Views;
|
||||
|
||||
use Slim\Slim;
|
||||
|
||||
class TwigExtension extends \Twig_Extension
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
return 'slim';
|
||||
}
|
||||
|
||||
public function getFunctions()
|
||||
{
|
||||
return array(
|
||||
new \Twig_SimpleFunction('urlFor', array($this, 'urlFor')),
|
||||
new \Twig_SimpleFunction('baseUrl', array($this, 'base')),
|
||||
new \Twig_SimpleFunction('siteUrl', array($this, 'site')),
|
||||
new \Twig_SimpleFunction('currentUrl', array($this, 'currentUrl')),
|
||||
);
|
||||
}
|
||||
|
||||
public function urlFor($name, $params = array(), $appName = 'default')
|
||||
{
|
||||
return Slim::getInstance($appName)->urlFor($name, $params);
|
||||
}
|
||||
|
||||
public function site($url, $withUri = true, $appName = 'default')
|
||||
{
|
||||
return $this->base($withUri, $appName) . '/' . ltrim($url, '/');
|
||||
}
|
||||
|
||||
public function base($withUri = true, $appName = 'default')
|
||||
{
|
||||
$req = Slim::getInstance($appName)->request();
|
||||
$uri = $req->getUrl();
|
||||
|
||||
if ($withUri) {
|
||||
$uri .= $req->getRootUri();
|
||||
}
|
||||
return $uri;
|
||||
}
|
||||
|
||||
public function currentUrl($withQueryString = true, $appName = 'default')
|
||||
{
|
||||
$app = Slim::getInstance($appName);
|
||||
$req = $app->request();
|
||||
$uri = $req->getUrl() . $req->getPath();
|
||||
|
||||
if ($withQueryString) {
|
||||
$env = $app->environment();
|
||||
|
||||
if ($env['QUERY_STRING']) {
|
||||
$uri .= '?' . $env['QUERY_STRING'];
|
||||
}
|
||||
}
|
||||
|
||||
return $uri;
|
||||
}
|
||||
}
|
33
vendor/slim/views/composer.json
vendored
Executable file
33
vendor/slim/views/composer.json
vendored
Executable file
@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "slim/views",
|
||||
"type": "library",
|
||||
"description": "Smarty and Twig View Parser package for the Slim Framework",
|
||||
"keywords": ["templating", "extensions", "slimphp"],
|
||||
"homepage": "http://github.com/codeguy/Slim-Views",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Josh Lockhart",
|
||||
"email": "info@joshlockhart.com",
|
||||
"homepage": "http://www.joshlockhart.com/"
|
||||
},
|
||||
{
|
||||
"name": "Andrew Smith",
|
||||
"email": "a.smith@silentworks.co.uk",
|
||||
"homepage": "http://thoughts.silentworks.co.uk/"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"slim/slim": ">=2.4.0",
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"suggest": {
|
||||
"smarty/smarty": "Smarty templating system",
|
||||
"twig/twig": "Twig templating system"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Slim\\Views\\": "./"
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user