Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazzap committed Nov 1, 2015
2 parents 95a31d4 + ad5cb41 commit 4530177
Show file tree
Hide file tree
Showing 50 changed files with 289 additions and 219 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"aura/html": "~2.4"
},
"require-dev": {
"phpunit/phpunit": "~4.4",
"phpunit/phpunit": "~4.8",
"mockery/mockery": "0.9.3",
"brain/monkey": "~1.1"
},
Expand Down
185 changes: 92 additions & 93 deletions composer.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions inc/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@ function engine(array $options = [], array $providers = [])

if (! function_exists('Foil\render')) {
/**
* @param string $path Full path or just name (requires folders option) for the template
* @param array $data Template context
* @param array $options Options for the engine
* @param string $path Full path or just name (requires folders option) for the template
* @param array $data Template context
* @param array $options Options for the engine
* @param array $providers
* @return string
*/
function render($path, array $data = [], array $options = [], array $providers = [])
{
$foil = Foil::boot($options, $providers);

return $foil->engine()->render($path, $data);
}
}
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.4/phpunit.xsd"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
bootstrap="./tests/boot.php"
colors="true"
convertErrorsToExceptions="true"
Expand Down
3 changes: 1 addition & 2 deletions src/Contracts/AliasAllowedTemplateInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
*/
interface AliasAllowedTemplateInterface extends TemplateInterface
{

/**
* @param \Foil\Template\Alias $alias
* @param \Foil\Template\Alias $alias
* @return \Foil\Contracts\AliasAllowedTemplateInterface
*/
public function alias(Alias $alias);
Expand Down
12 changes: 8 additions & 4 deletions src/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function registerFilter($filterName, callable $filter)
*
* @param string $functionName
* @param callable $function
* @param boolean $safe Can function output html?
* @param boolean $safe Can function output html?
* @return \Foil\Engine Itself for fluent interface
*/
public function registerFunction($functionName, callable $function, $safe = false)
Expand Down Expand Up @@ -287,13 +287,16 @@ public function renderSections($template, array $data = [], $class = null)
*/
private function doRender($path, array $data = [], $class = null)
{
if ($this->status() === self::STATUS_IDLE) {
$status = $this->status();
if ($status === self::STATUS_IDLE) {
$this->statusTransitions();
} elseif ($status & self::STATUS_IDLE) {
$this->status = self::STATUS_IN_LAYOUT;
}
$template = $this->stack()->factory($path, $this, $class);
$this->events->fire('f.template.render', $template, $data);
$output = trim($template->render($data));
$this->events->fire('f.template.renderered', $template, $output);
$this->events->fire('f.template.renderered', $template, $output, $this->status);

return $output;
}
Expand Down Expand Up @@ -326,7 +329,8 @@ private function statusTransitions()
$this->events->on('f.template.renderered', function () {
$this->stack()->pop();
if ($this->stack()->count() === 0) {
$this->status = self::STATUS_RENDERED;
$this->status = self::STATUS_RENDERED | self::STATUS_IDLE;
$this->events->fire('f.renderered', $this);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/AuraHtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function provideFunctions()
}

/**
* @param string $tag
* @param string $tag
* @return mixed
* @throws \Aura\Html\Exception\HelperNotFound
* @link https://github.com/auraphp/Aura.Html/blob/2.x/README-HELPERS.md
Expand Down
20 changes: 10 additions & 10 deletions src/Extensions/Links.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,37 +145,37 @@ public function asset($asset, $scheme = null)
private function setupHost(array $args, $which = 'host')
{
$checks = [
function(array $args, $which) {
function (array $args, $which) {
return ! isset($args[$which]) || is_null($args[$which]);
},
function(array $args, $which) {
function (array $args, $which) {
return empty($args[$which]);
},
function(array $args, $which) {
function (array $args, $which) {
return is_string($args[$which]) && strtolower($args[$which]) !== 'auto';
},
function(array $args, $which) {
function (array $args, $which) {
return $args[$which] === true || is_string($args[$which]);
}
},
];
$actions = [
function($var, $which) {
function ($var, $which) {
$this->$var = $which === 'host' ? false : null;
},
function($var) {
function ($var) {
$this->$var = false;
},
function($var, $which, array $args) {
function ($var, $which, array $args) {
$parse = parse_url($args[$which]);
$host = isset($parse['host']) ? $parse['host'] : $parse['path'];
$this->$var = $this->clean($host);
},
function($var) {
function ($var) {
$this->$var = $this->clean(filter_input(INPUT_SERVER, 'SERVER_NAME'));
},
];

foreach($checks as $i => $check) {
foreach ($checks as $i => $check) {
if ($check($args, $which)) {
$args = [
$which === 'assets_host' ? 'assetsHost' : 'host',
Expand Down
6 changes: 6 additions & 0 deletions src/Extensions/Sections.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ public function __construct(Factory $factory, Events $events)
*/
public function setup(array $args = [])
{
$this->events->on('f.renderered', function () {
$this->stack = new SplStack();
$this->names = new SplStack();
$this->factory->flush();
});

return;
}

Expand Down
9 changes: 7 additions & 2 deletions src/Section/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public function __construct(ArrayAccess $sections, $defaultMode = null, $contrac
/**
* Factory a section instance (if it was not already factored) and return it.
*
* @param string $name Section name
* @param int|bool $mode Section mode, one of the mode const
* @param string $name Section name
* @param int|bool $mode Section mode, one of the mode const
* @param string $className Full qualified section class name
* @return \Foil\Contracts\SectionInterface
* @throws InvalidArgumentException
Expand Down Expand Up @@ -100,4 +100,9 @@ public function getClass($class)

return $class;
}

public function flush()
{
$this->sections = new \ArrayObject();
}
}
5 changes: 2 additions & 3 deletions src/Template/Alias.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
final class Alias
{

const REGEX = '#^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$#';

/**
Expand Down Expand Up @@ -49,8 +48,8 @@ public function __toString()
*/
private function validate($alias)
{
if ( ! is_string($alias) || ! preg_match(self::REGEX, $alias)) {
if (! is_string($alias) || ! preg_match(self::REGEX, $alias)) {
throw new InvalidArgumentException('Alias must be a valid variable name.');
}
}
}
}
2 changes: 1 addition & 1 deletion src/Template/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function __construct(
/**
* Factory and/or returns template objects.
*
* @param string $path Full path to template file
* @param string $path Full path to template file
* @param \Foil\Engine $engine
* @param string $className A custom template class name
* @return \Foil\Contracts\TemplateInterface
Expand Down
8 changes: 4 additions & 4 deletions tests/_files/bar/second.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php $this->layout('main', ['foo' => 'Bar!']) ?>

<?php $this->section('one') ?>
World <?= $this->foo ?>
World <?= $this->foo ?>
<?php $this->stop() ?>

<?php $this->section('two') ?>
I Win
I Win
<?php $this->replace() ?>

Buffalo Bill
Buffalo Bill

<?php $this->section('three') ?>
MAN
MAN
<?php
$this->stop();
18 changes: 9 additions & 9 deletions tests/_files/foo/blocks.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php $this->block('spaceless') ?>
<?php $this->block('wrap', '<div>', '</div>') ?>
<?php $this->block('spaceless') ?>
<ul>
<?php $this->block('repeat', 3) ?>
<li>a</li>
<?php $this->endblock('repeat'); ?>
</ul>
<?php $this->endblock('spaceless') ?>
<?php $this->endblock('wrap') ?>
<?php $this->block('wrap', '<div>', '</div>') ?>
<?php $this->block('spaceless') ?>
<ul>
<?php $this->block('repeat', 3) ?>
<li>a</li>
<?php $this->endblock('repeat'); ?>
</ul>
<?php $this->endblock('spaceless') ?>
<?php $this->endblock('wrap') ?>
<?php $this->endblock('spaceless') ?>
8 changes: 4 additions & 4 deletions tests/_files/foo/main.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php $this->section('one') ?>
Hello <?= $this->foo.' ' ?>
Hello <?= $this->foo.' ' ?>
<?php $this->stop() ?>

Alone
Alone

<?php $this->section('two') ?>
NO
NO
<?php $this->stop() ?>

<?php $this->section('three') ?>
YES
YES
<?php
$this->stop();
10 changes: 8 additions & 2 deletions tests/_files/stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

class Value
{

public $value;

public function __construct($value)
Expand All @@ -14,22 +15,25 @@ public function __construct($value)

class ToArray extends Value
{

public function toArray()
{
return ['toarray' => (array) $this->value];
return ['toarray' => (array)$this->value];
}
}

class AsArray extends Value
{

public function asArray()
{
return ['asarray' => (array) $this->value];
return ['asarray' => (array)$this->value];
}
}

class Json implements JsonSerializable
{

public function jsonSerialize()
{
return '<b>I am JSON</b>';
Expand All @@ -38,10 +42,12 @@ public function jsonSerialize()

class Target extends Value
{

}

class Transformer
{

public function transform($object)
{
return is_object($object) ? ['transformed' => get_object_vars($object)] : false;
Expand Down
Loading

0 comments on commit 4530177

Please sign in to comment.