Skip to content

Commit

Permalink
Cleanup: typos, doc block, CS
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazzap committed Jan 25, 2015
1 parent 1802e79 commit cd555bb
Show file tree
Hide file tree
Showing 23 changed files with 97 additions and 70 deletions.
2 changes: 1 addition & 1 deletion docs/DATA/ARRAIZATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ To use transformers you need to pass to `arraize()` an associative array where
- keys are the fully-qualified class names of the objects to be transformed
- values are the tranformers to apply

Tranformers (the array values) can be passed in 3 ways:
Transformers (the array values) can be passed in 3 ways:

- as callbacks that receive the object and have to return an array
- as object instances, that don't need to implement any interface or extend any class, they just need a method `transform()` that receives the object and has to return an array
Expand Down
2 changes: 1 addition & 1 deletion docs/EXTENDING/CUSTOM-EXTENSIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Second argument passed to `loadExtension()` is the array that will passed to `se

As better explained in the *"Extending Foil / Custom Functions & Filters"* Foil functions by default can't output HTML content, because their output is HTML-encoded.

When you register a single functions via `$engine->registerfunction()` is possible to pass `true` as 3rd argument to mark the function as *safe* so that it is allowed to output HTML.
When you register a single functions via `$engine->registerFunction()` is possible to pass `true` as 3rd argument to mark the function as *safe* so that it is allowed to output HTML.

When you load an extension that provides functions that needs to output HTML, you need to register those function as safe as well.

Expand Down
10 changes: 5 additions & 5 deletions docs/INTEGRATE/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ Any other data type will be returned unchanged.

```php
/**
* @param mixed $data Data to convert
* @param bool $escape Should strings in data be HTML-encoded?
* @param array $trasformers Transformers: full qualified class names, objects or callables
* @param bool $tostring Should all scalar items be casted to strings?
* @param mixed $data Data to convert
* @param bool $escape Should strings in data be HTML-encoded?
* @param array $transformers Transformers: full qualified class names, objects or callables
* @param bool $tostring Should all scalar items be casted to strings?
* @return array
*/

function arraize($data = [], $escape = false, array $trasformers = [], $tostring = false)
function arraize($data = [], $escape = false, array $transformers = [], $tostring = false)
```

This function allow to recursively convert to array any kind of data. It is a powerful tool, and there is an entire doc page that explain how it work and how to use it.
Expand Down
4 changes: 2 additions & 2 deletions docs/TEMPLATES/INHERITANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Let's define a base layout, `main.php`, which defines a simple HTML skeleton doc
<head>
<?php $this->section('head') ?>
<link rel="stylesheet" href="style.css" />
<title><?php $this->section('title') ?>My Webpage<?php $this->stop() ?></title>
<title><?php $this->section('title') ?>My Home Page<?php $this->stop() ?></title>
<?php $this->stop() ?>
</head>
<body>
Expand Down Expand Up @@ -81,7 +81,7 @@ E.g. if the child template above is rendered, `<head>` tag will contain:
```html
<head>
<link rel="stylesheet" href="style.css" />
<title>My Webpage</title>
<title>My Home Page</title>
<style type="text/css">
.important { color: #336699; }
</style>
Expand Down
17 changes: 10 additions & 7 deletions inc/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
use Foil\Context\SearchContext;
use Foil\Context\RegexContext;
use Foil\Context\GlobalContext;
use Foil\Contracts\ContextInterface;
use Foil\Kernel\Arraize;
use Traversable;
use LogicException;
use InvalidArgumentException;

Expand Down Expand Up @@ -88,7 +90,7 @@ function engine(array $options = [])
* When used before any engine() call, is possible to set engine options.
*
* @param string $path Full path for the template
* @param array $data Template contex
* @param array $data Template context
* @param array $options Options for the engine
* @return string
*/
Expand Down Expand Up @@ -196,6 +198,7 @@ function fire($event)
*
* @param string $event
* @param callable $callback
* @param bool $once
*/
function on($event, callable $callback, $once = false)
{
Expand Down Expand Up @@ -279,14 +282,14 @@ function decode($data)
* - if the is an instance of JsonSerializable it is JSON-encoded then decoded
* - calling get_object_vars()
*
* @param mixed $data Data to convert
* @param bool $escape Should strings in data be HTML-encoded?
* @param array $trasformers Transformers: full qualified class names, objects or callables
* @param bool $tostring Should all scalar items in data be casted to strings?
* @param mixed $data Data to convert
* @param bool $escape Should strings in data be HTML-encoded?
* @param array $transformers Transformers: full qualified class names, objects or callables
* @param bool $tostring Should all scalar items in data be casted to strings?
* @return array
*/
function arraize($data = [], $escape = false, array $trasformers = [], $tostring = false)
function arraize($data = [], $escape = false, array $transformers = [], $tostring = false)
{
return (new Arraize())->run($data, $escape, $trasformers, $tostring);
return (new Arraize())->run($data, $escape, $transformers, $tostring);
}
}
7 changes: 3 additions & 4 deletions src/Contracts/EngineInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ interface EngineInterface
const STATUS_IN_PARTIAL = 16;

/**
* Find a template fullpath for a given template name.
* Find a template full path for a given template name.
* Templates will be searched in all registered folders.
* If extension is not given default one is added.
* File with matching names but not accepeted exceptions will be skipped.
* File with matching names but not accepted exceptions will be skipped.
*
* @param string $template
*/
Expand Down Expand Up @@ -79,8 +79,7 @@ public function setFolders(array $folders);
/**
* Get engine status
*
* @param string $status
* @return int One of the statues constants
* @return int One of the statues constants
*/
public function status();
}
4 changes: 2 additions & 2 deletions src/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ public function setFolders(array $folders)
* call templates from there.
*
* @param string $path
* @param string $name
* @param string|void $name
* @return \Foil\Engine
*/
public function addFolder($path, $name = 0)
public function addFolder($path, $name = null)
{
$this->finder()->in([$name => $path]);

Expand Down
10 changes: 5 additions & 5 deletions src/Extensions/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function provideFunctions()
*
* @param string $var Variable name
* @param mixed $default Default
* @param string|array $filter Array or pipe-separed list of filters
* @param string|array $filter Array or pipe-separated list of filters
* @return mixed
*/
public function variable($var, $default = '', $filter = null)
Expand All @@ -81,7 +81,7 @@ public function variable($var, $default = '', $filter = null)
*
* @param string $var Variable name
* @param mixed $default Default
* @param string|array $filter Array or pipe-separed list of filters
* @param string|array $filter Array or pipe-separated list of filters
* @return mixed
*/
public function escape($var, $default = '', $filter = null)
Expand All @@ -95,7 +95,7 @@ public function escape($var, $default = '', $filter = null)
*
* @param string $var Variable name
* @param mixed $default Default
* @param string|array $filter Array or pipe-separed list of filters
* @param string|array $filter Array or pipe-separated list of filters
* @return mixed
*/
public function decode($var, $default = '', $filter = null)
Expand All @@ -108,7 +108,7 @@ public function decode($var, $default = '', $filter = null)
*
* @param string $var Variable name
* @param mixed $default Default
* @param string|array $filter Array or pipe-separed list of filters
* @param string|array $filter Array or pipe-separated list of filters
* @return mixed
*/
public function raw($var, $default = '', $filter = null)
Expand Down Expand Up @@ -153,7 +153,7 @@ public function asArray($var, $default = [], $filter = null, $force_raw = false)
*
* @param string $var Variable name
* @param mixed $default Default
* @param string|array $filter Array or pipe-separed list of filters
* @param string|array $filter Array or pipe-separated list of filters
* @return mixed
*/
public function asArrayRaw($var, $default = [], $filter = null)
Expand Down
6 changes: 3 additions & 3 deletions src/Extensions/Links.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public function provideFunctions()
* Return a relative (or absolute if a host is set) url for a file whose directory has been
* set via setup arguments. Allow to easily output long urls with few chars.
*
* @param string $file
* @param string $subdir_url
* @param boolean $use_scheme
* @param string $file
* @param string|bool $subdir_url
* @param boolean $use_scheme
* @return string
*/
public function link($file, $subdir_url = false, $use_scheme = null)
Expand Down
4 changes: 2 additions & 2 deletions src/Extensions/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public function provideFunctions()
public function is($url = '', $if_true = true, $if_false = "")
{
if (is_array($url) && isset($url[0]) && is_int($url[0]) && $url[0] <= count($this->chunks)) {
$chunch = isset($url[1]) && is_string($url[1]) ? $this->clean($url[1]) : '';
$chunk = isset($url[1]) && is_string($url[1]) ? $this->clean($url[1]) : '';

return $this->clean($this->chunks[($url[0] - 1)]) === $chunch ? $if_true : $if_false;
return $this->clean($this->chunks[($url[0] - 1)]) === $chunk ? $if_true : $if_false;
}

return $this->clean($this->path) === $this->clean($url) ? $if_true : $if_false;
Expand Down
14 changes: 7 additions & 7 deletions src/Kernel/Arraize.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Arraize
/**
* @param mixed $data Data to convert
* @param bool $escape Should strings in data be HTML-encoded?
* @param array $trasf Transformes: full qualified class names, objects or callables
* @param array $trasf Transformers: full qualified class names, objects or callables
* @param bool $tostring Should all scalar items in data be casted to strings?
* @return array
*/
Expand Down Expand Up @@ -93,7 +93,7 @@ private function walk($var, $flags, $trasf)
*/
private function transform($var, $class, $trasf)
{
$cb = $this->trasformer(isset($trasf[trim($class, '\\')]) ? $trasf[$class] : false);
$cb = $this->transformer(isset($trasf[trim($class, '\\')]) ? $trasf[$class] : false);

if (is_object($cb) && method_exists($cb, 'transform')) {
$cb = [$cb, 'transform'];
Expand All @@ -103,16 +103,16 @@ private function transform($var, $class, $trasf)
}

/**
* @param mixed $trasformer
* @param mixed $transformer
* @return callable|object|bool
*/
private function trasformer($trasformer)
private function transformer($transformer)
{
if (is_string($trasformer) && class_exists($trasformer)) {
$trasformer = new $trasformer();
if (is_string($transformer) && class_exists($transformer)) {
$transformer = new $transformer();
}

return is_object($trasformer) || is_callable($trasformer) ? $trasformer : false;
return is_object($transformer) || is_callable($transformer) ? $transformer : false;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
* Class that holds all the functions and filters registered in extensions.
* It handle all unexistent methods called on temmplate objects inside template files.
* It handle all non-existent methods called on template objects inside template files.
*
* @author Giuseppe Mazzapica <[email protected]>
* @package foil\foil
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private function engineAddData(ContextCollection $collection, $args)
private function engineAddContext(ContextCollection $collection, $args)
{
if ($args[0] instanceof ContextInterface) {
return $collection->add($args[0]);
$collection->add($args[0]);
}
if (is_string($args[0]) && isset($args[1]) && is_array($args[1])) {
$is_regex = isset($args[2]) && ! empty($args[2]);
Expand Down
46 changes: 26 additions & 20 deletions src/Providers/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,35 @@ public function register(Container $container)
public function boot(Container $container)
{
// register an extension
$container['events']->on('f.extension.load', function (Extension $extension, array $options, $safe) use ($container) {
$extension->setup($options);
$container['command']->registerFunctions($extension->provideFunctions(), $safe);
$container['command']->registerFilters($extension->provideFilters());
if ($extension instanceof TemplateAware) {
$extension->setStack($container['template.stack']);
$container['events']->on(
'f.extension.load',
function (Extension $extension, array $options, $safe) use ($container) {
$extension->setup($options);
$container['command']->registerFunctions($extension->provideFunctions(), $safe);
$container['command']->registerFilters($extension->provideFilters());
if ($extension instanceof TemplateAware) {
$extension->setStack($container['template.stack']);
}
if ($extension instanceof FinderAware) {
$extension->setFinder($container['template.finder']);
}
if ($extension instanceof APIAware) {
$extension->setAPI($container['api']);
}
if ($extension instanceof EngineAware) {
$extension->setEngine($container['engine']);
}
$container['events']->fire('f.extension.registered', $extension);
}
if ($extension instanceof FinderAware) {
$extension->setFinder($container['template.finder']);
}
if ($extension instanceof APIAware) {
$extension->setAPI($container['api']);
}
if ($extension instanceof EngineAware) {
$extension->setEngine($container['engine']);
}
$container['events']->fire('f.extension.registered', $extension);
});
);

// register an function
$container['events']->on('f.function.register', function ($function, callable $callback, $safe) use ($container) {
$container['command']->registerFunctions([$function => $callback], $safe);
});
$container['events']->on(
'f.function.register',
function ($function, callable $callback, $safe) use ($container) {
$container['command']->registerFunctions([$function => $callback], $safe);
}
);

// register a filter
$container['events']->on('f.filter.register', function ($filter, callable $callback) use ($container) {
Expand Down
2 changes: 1 addition & 1 deletion src/Section/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(ArrayAccess $sections, $default_mode = null, $contra
* Factory a section instance (if it was not already factored) and return it.
*
* @param string $name Section name
* @param int $mode Section mode, one of the mode const
* @param int|bool $mode Section mode, one of the mode const
* @param string $class_name Full qualified section class name
* @return \Foil\Contracts\SectionInterface
* @throws InvalidArgumentException
Expand Down
2 changes: 1 addition & 1 deletion src/Template/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(AA $templates, AA $sections, API $api, $contract = n
/**
* Factory and/or returns template objects.
*
* @param string $path Fullpath to template file
* @param string $path Full path to template file
* @param string $class_name A custom template class name
* @return \Foil\Contracts\TemplateInterface
* @throws InvalidArgumentException
Expand Down
8 changes: 4 additions & 4 deletions src/Template/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public function dirs()
}

/**
* Takes a template name and looks for directory name passed in Foil convenction, that is
* Takes a template name and looks for directory name passed in Foil convention, that is
* folder_name::file_name.
* If file name as no extension, defauld estension is appendended if available.
* If file name as no extension, default extension is appended if available.
*
* @param string $template_name
* @return array
Expand All @@ -109,8 +109,8 @@ private function parseName($template_name)
/**
* Find a template when a specific directory name is required
*
* @param type $dir
* @param type $template_name
* @param string $dir
* @param string $template_name
* @return boolean
*/
private function findInDir($dir, $template_name)
Expand Down
1 change: 0 additions & 1 deletion src/Template/Stack.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public function pop()
/**
* Returns the count of templates in the stack.
*
* @param string $mode
* @return int
*/
public function count()
Expand Down
5 changes: 3 additions & 2 deletions src/Template/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct($path, ArrayAccess $sections, API $api)
}

/**
* Proxies inexistent methods to command to call registered extensions functions
* Proxies non-existent methods to command to call registered extensions functions
*
* @param string $name
* @param array $arguments
Expand Down Expand Up @@ -124,7 +124,8 @@ public function render(array $data = [])
while ($this->layoutPath()) {
$layout = $this->layoutPath();
$this->setData($this->buildContext(
$this->layout_data[$layout]['data'], $this->layout_data[$layout]['only']
$this->layout_data[$layout]['data'],
$this->layout_data[$layout]['only']
));
$this->layout = null;
// listener for this event makes sections work in output mode
Expand Down
Loading

0 comments on commit cd555bb

Please sign in to comment.