Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 3c699bf

Browse files
committed
Merge branch 'develop'
2 parents 55752bb + 50a1828 commit 3c699bf

8 files changed

Lines changed: 244 additions & 238 deletions

File tree

README.md

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,10 @@ Slim Views only officially support the following views listed below.
1414

1515
#### using [Composer](http://getcomposer.org/)
1616

17-
Create a composer.json file in your project root:
18-
19-
```json
20-
{
21-
"require": {
22-
"slim/views": "0.1.*"
23-
}
24-
}
25-
```
26-
27-
Then run the following composer command:
17+
Install in your project by running the following composer command:
2818

2919
```bash
30-
$ php composer.phar install
20+
$ php composer require slim/views
3121
```
3222

3323
## Smarty

Smarty.php

Lines changed: 124 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,124 @@
1-
<?php
2-
/**
3-
* Slim - a micro PHP 5 framework
4-
*
5-
* @author Josh Lockhart
6-
* @author Andrew Smith
7-
* @link http://www.slimframework.com
8-
* @copyright 2013 Josh Lockhart
9-
* @version 0.1.2
10-
* @package SlimViews
11-
*
12-
* MIT LICENSE
13-
*
14-
* Permission is hereby granted, free of charge, to any person obtaining
15-
* a copy of this software and associated documentation files (the
16-
* "Software"), to deal in the Software without restriction, including
17-
* without limitation the rights to use, copy, modify, merge, publish,
18-
* distribute, sublicense, and/or sell copies of the Software, and to
19-
* permit persons to whom the Software is furnished to do so, subject to
20-
* the following conditions:
21-
*
22-
* The above copyright notice and this permission notice shall be
23-
* included in all copies or substantial portions of the Software.
24-
*
25-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26-
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27-
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28-
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29-
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30-
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31-
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32-
*/
33-
namespace Slim\Views;
34-
35-
/**
36-
* SmartyView
37-
*
38-
* The SmartyView is a custom View class that renders templates using the Smarty
39-
* template language (http://www.smarty.net).
40-
*
41-
* Two fields that you, the developer, will need to change are:
42-
* - parserDirectory
43-
* - parserCompileDirectory
44-
* - parserCacheDirectory
45-
*
46-
* @package Slim
47-
* @author Jose da Silva <http://josedasilva.net>
48-
*/
49-
class Smarty extends \Slim\View
50-
{
51-
/**
52-
* @var string The path to the Smarty code directory WITHOUT the trailing slash
53-
*/
54-
public $parserDirectory = null;
55-
56-
/**
57-
* @var string The path to the Smarty compiled templates folder WITHOUT the trailing slash
58-
*/
59-
public $parserCompileDirectory = null;
60-
61-
/**
62-
* @var string The path to the Smarty cache folder WITHOUT the trailing slash
63-
*/
64-
public $parserCacheDirectory = null;
65-
66-
/**
67-
* @var SmartyExtensions The Smarty extensions directory you want to load plugins from
68-
*/
69-
public $parserExtensions = array();
70-
71-
/**
72-
* @var parserInstance persistent instance of the Parser object.
73-
*/
74-
private $parserInstance = null;
75-
76-
/**
77-
* Render Template
78-
*
79-
* This method will output the rendered template content
80-
*
81-
* @param string $template The path to the template, relative to the templates directory.
82-
* @param null $data
83-
* @return string
84-
*/
85-
public function render($template, $data = null)
86-
{
87-
$parser = $this->getInstance();
88-
$parser->assign($this->all());
89-
90-
return $parser->fetch($template, $data);
91-
}
92-
93-
/**
94-
* Creates new Smarty object instance if it doesn't already exist, and returns it.
95-
*
96-
* @throws \RuntimeException If Smarty lib directory does not exist
97-
* @return \Smarty Instance
98-
*/
99-
public function getInstance()
100-
{
101-
if (! ($this->parserInstance instanceof \Smarty)) {
102-
if (!class_exists('\Smarty')) {
103-
if (!is_dir($this->parserDirectory)) {
104-
throw new \RuntimeException('Cannot set the Smarty lib directory : ' . $this->parserDirectory . '. Directory does not exist.');
105-
}
106-
require_once $this->parserDirectory . '/Smarty.class.php';
107-
}
108-
109-
$this->parserInstance = new \Smarty();
110-
$this->parserInstance->template_dir = $this->getTemplatesDirectory();
111-
if ($this->parserExtensions) {
112-
$this->parserInstance->addPluginsDir($this->parserExtensions);
113-
}
114-
if ($this->parserCompileDirectory) {
115-
$this->parserInstance->compile_dir = $this->parserCompileDirectory;
116-
}
117-
if ($this->parserCacheDirectory) {
118-
$this->parserInstance->cache_dir = $this->parserCacheDirectory;
119-
}
120-
}
121-
122-
return $this->parserInstance;
123-
}
124-
}
1+
<?php
2+
/**
3+
* Slim - a micro PHP 5 framework
4+
*
5+
* @author Josh Lockhart
6+
* @author Andrew Smith
7+
* @link http://www.slimframework.com
8+
* @copyright 2013 Josh Lockhart
9+
* @version 0.1.3
10+
* @package SlimViews
11+
*
12+
* MIT LICENSE
13+
*
14+
* Permission is hereby granted, free of charge, to any person obtaining
15+
* a copy of this software and associated documentation files (the
16+
* "Software"), to deal in the Software without restriction, including
17+
* without limitation the rights to use, copy, modify, merge, publish,
18+
* distribute, sublicense, and/or sell copies of the Software, and to
19+
* permit persons to whom the Software is furnished to do so, subject to
20+
* the following conditions:
21+
*
22+
* The above copyright notice and this permission notice shall be
23+
* included in all copies or substantial portions of the Software.
24+
*
25+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32+
*/
33+
namespace Slim\Views;
34+
35+
/**
36+
* SmartyView
37+
*
38+
* The SmartyView is a custom View class that renders templates using the Smarty
39+
* template language (http://www.smarty.net).
40+
*
41+
* Two fields that you, the developer, will need to change are:
42+
* - parserDirectory
43+
* - parserCompileDirectory
44+
* - parserCacheDirectory
45+
*
46+
* @package Slim
47+
* @author Jose da Silva <http://josedasilva.net>
48+
*/
49+
class Smarty extends \Slim\View
50+
{
51+
/**
52+
* @var string The path to the Smarty code directory WITHOUT the trailing slash
53+
*/
54+
public $parserDirectory = null;
55+
56+
/**
57+
* @var string The path to the Smarty compiled templates folder WITHOUT the trailing slash
58+
*/
59+
public $parserCompileDirectory = null;
60+
61+
/**
62+
* @var string The path to the Smarty cache folder WITHOUT the trailing slash
63+
*/
64+
public $parserCacheDirectory = null;
65+
66+
/**
67+
* @var SmartyExtensions The Smarty extensions directory you want to load plugins from
68+
*/
69+
public $parserExtensions = array();
70+
71+
/**
72+
* @var parserInstance persistent instance of the Parser object.
73+
*/
74+
private $parserInstance = null;
75+
76+
/**
77+
* Render Template
78+
*
79+
* This method will output the rendered template content
80+
*
81+
* @param string $template The path to the template, relative to the templates directory.
82+
* @param null $data
83+
* @return string
84+
*/
85+
public function render($template, $data = null)
86+
{
87+
$parser = $this->getInstance();
88+
$parser->assign($this->all());
89+
90+
return $parser->fetch($template, $data);
91+
}
92+
93+
/**
94+
* Creates new Smarty object instance if it doesn't already exist, and returns it.
95+
*
96+
* @throws \RuntimeException If Smarty lib directory does not exist
97+
* @return \Smarty Instance
98+
*/
99+
public function getInstance()
100+
{
101+
if (!($this->parserInstance instanceof \Smarty)) {
102+
if (!class_exists('\Smarty')) {
103+
if (!is_dir($this->parserDirectory)) {
104+
throw new \RuntimeException('Cannot set the Smarty lib directory : ' . $this->parserDirectory . '. Directory does not exist.');
105+
}
106+
require_once $this->parserDirectory . '/Smarty.class.php';
107+
}
108+
109+
$this->parserInstance = new \Smarty();
110+
$this->parserInstance->template_dir = $this->getTemplatesDirectory();
111+
if ($this->parserExtensions) {
112+
$this->parserInstance->addPluginsDir($this->parserExtensions);
113+
}
114+
if ($this->parserCompileDirectory) {
115+
$this->parserInstance->compile_dir = $this->parserCompileDirectory;
116+
}
117+
if ($this->parserCacheDirectory) {
118+
$this->parserInstance->cache_dir = $this->parserCacheDirectory;
119+
}
120+
}
121+
122+
return $this->parserInstance;
123+
}
124+
}

SmartyPlugins/function.baseUrl.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
<?php
2-
/*
3-
* Smarty plugin
4-
* -------------------------------------------------------------
5-
* File: function.baseUrl.php
6-
* Type: function
7-
* Name: baseUrl
8-
* Purpose: outputs url for a function with the defined name method
9-
* version 0.1.2
10-
* package SlimViews
11-
* -------------------------------------------------------------
12-
*/
13-
function smarty_function_baseUrl($params, $template)
14-
{
15-
$withUri = isset($params['withUri']) ? $params['withUri'] : true;
16-
$appName = isset($params['appname']) ? $params['appname'] : 'default';
17-
18-
$req = \Slim\Slim::getInstance($appName)->request();
19-
$uri = $req->getUrl();
20-
21-
if ($withUri) {
22-
$uri .= $req->getRootUri();
23-
}
24-
25-
return $uri;
26-
}
1+
<?php
2+
/*
3+
* Smarty plugin
4+
* -------------------------------------------------------------
5+
* File: function.baseUrl.php
6+
* Type: function
7+
* Name: baseUrl
8+
* Purpose: outputs url for a function with the defined name method
9+
* version 0.1.3
10+
* package SlimViews
11+
* -------------------------------------------------------------
12+
*/
13+
function smarty_function_baseUrl($params, $template)
14+
{
15+
$withUri = isset($params['withUri']) ? $params['withUri'] : true;
16+
$appName = isset($params['appname']) ? $params['appname'] : 'default';
17+
18+
$req = \Slim\Slim::getInstance($appName)->request();
19+
$uri = $req->getUrl();
20+
21+
if ($withUri) {
22+
$uri .= $req->getRootUri();
23+
}
24+
25+
return $uri;
26+
}

SmartyPlugins/function.siteUrl.php

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
<?php
2-
/*
3-
* Smarty plugin
4-
* -------------------------------------------------------------
5-
* File: function.siteUrl.php
6-
* Type: function
7-
* Name: siteUrl
8-
* Purpose: outputs url for a function with the defined name method
9-
* version 0.1.2
10-
* package SlimViews
11-
* -------------------------------------------------------------
12-
*/
13-
function smarty_function_siteUrl($params, $template)
14-
{
15-
$withUri = isset($params['withUri']) ? $params['withUri'] : true;
16-
$appName = isset($params['appname']) ? $params['appname'] : 'default';
17-
$url = isset($params['url']) ? $params['url'] : '';
18-
19-
$req = \Slim\Slim::getInstance($appName)->request();
20-
$uri = $req->getUrl();
21-
22-
if ($withUri) {
23-
$uri .= $req->getRootUri();
24-
}
25-
26-
return $uri . '/' . ltrim($url, '/');
27-
}
1+
<?php
2+
/*
3+
* Smarty plugin
4+
* -------------------------------------------------------------
5+
* File: function.siteUrl.php
6+
* Type: function
7+
* Name: siteUrl
8+
* Purpose: outputs url for a function with the defined name method
9+
* version 0.1.3
10+
* package SlimViews
11+
* -------------------------------------------------------------
12+
*/
13+
function smarty_function_siteUrl($params, $template)
14+
{
15+
$withUri = isset($params['withUri']) ? $params['withUri'] : true;
16+
$appName = isset($params['appname']) ? $params['appname'] : 'default';
17+
$url = isset($params['url']) ? $params['url'] : '';
18+
19+
$req = \Slim\Slim::getInstance($appName)->request();
20+
$uri = $req->getUrl();
21+
22+
if ($withUri) {
23+
$uri .= $req->getRootUri();
24+
}
25+
26+
return $uri . '/' . ltrim($url, '/');
27+
}

0 commit comments

Comments
 (0)