Skip to content

Commit

Permalink
Twig 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed Aug 25, 2020
1 parent d4a45f1 commit ad4cf07
Show file tree
Hide file tree
Showing 18 changed files with 89 additions and 159 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<a name="1.3.0"></a>
# [1.3.0](https://github.com/flextype-plugins/twig/compare/v1.2.0...v1.3.0) (2020-08-25)

### Features

* **core** update code base for new Flextype 0.9.11

<a name="1.2.0"></a>
# [1.2.0](https://github.com/flextype-plugins/twig/compare/v1.1.1...v1.2.0) (2020-08-19)

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h1 align="center">Twig Plugin for <a href="https://flextype.org/">Flextype</a></h1>

<p align="center">
<a href="https://github.com/flextype-plugins/twig/releases"><img alt="Version" src="https://img.shields.io/github/release/flextype-plugins/twig.svg?label=version&color=black"></a> <a href="https://github.com/flextype-plugins/twig"><img src="https://img.shields.io/badge/license-MIT-blue.svg?color=black" alt="License"></a> <a href="https://github.com/flextype-plugins/twig"><img src="https://img.shields.io/github/downloads/flextype-plugins/twig/total.svg?color=black" alt="Total downloads"></a> <a href="https://github.com/flextype-plugins/twig"><img src="https://img.shields.io/badge/Flextype-0.9.10-green.svg?color=black" alt="Flextype"></a> <a href="https://flextype.org/en/discord"><img src="https://img.shields.io/discord/423097982498635778.svg?logo=discord&color=black&label=Discord%20Chat" alt="Discord"></a>
<a href="https://github.com/flextype-plugins/twig/releases"><img alt="Version" src="https://img.shields.io/github/release/flextype-plugins/twig.svg?label=version&color=black"></a> <a href="https://github.com/flextype-plugins/twig"><img src="https://img.shields.io/badge/license-MIT-blue.svg?color=black" alt="License"></a> <a href="https://github.com/flextype-plugins/twig"><img src="https://img.shields.io/github/downloads/flextype-plugins/twig/total.svg?color=black" alt="Total downloads"></a> <a href="https://github.com/flextype-plugins/twig"><img src="https://img.shields.io/badge/Flextype-0.9.11-green.svg?color=black" alt="Flextype"></a> <a href="https://flextype.org/en/discord"><img src="https://img.shields.io/discord/423097982498635778.svg?logo=discord&color=black&label=Discord%20Chat" alt="Discord"></a>
</p>

Twig plugin to present Twig template engine for Flextype.
Expand All @@ -12,7 +12,7 @@ The following dependencies need to be installed for Twig Plugin.

| Item | Version | Download |
|---|---|---|
| [flextype](https://github.com/flextype/flextype) | 0.9.10 | [download](https://github.com/flextype/flextype/releases) |
| [flextype](https://github.com/flextype/flextype) | 0.9.11 | [download](https://github.com/flextype/flextype/releases) |

## Installation

Expand Down
20 changes: 10 additions & 10 deletions dependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,28 @@
/**
* Add CSRF (cross-site request forgery) protection service to Flextype container
*/
$flextype->container()['csrf'] = static function () use ($flextype){
flextype()->container()['csrf'] = static function (){
return new Guard();
};

/**
* Add Twig service to Flextype container
*/
$flextype->container()['twig'] = static function () use ($flextype) {
flextype()->container()['twig'] = static function () {

// Get twig settings
$twigSettings = [
'auto_reload' => $flextype->container('registry')->get('plugins.twig.settings.auto_reload'),
'cache' => $flextype->container('registry')->get('plugins.twig.settings.cache') ? PATH['cache'] . '/twig' : false,
'debug' => $flextype->container('registry')->get('plugins.twig.settings.debug'),
'charset' => $flextype->container('registry')->get('plugins.twig.settings.charset')
'auto_reload' => flextype('registry')->get('plugins.twig.settings.auto_reload'),
'cache' => flextype('registry')->get('plugins.twig.settings.cache') ? PATH['cache'] . '/twig' : false,
'debug' => flextype('registry')->get('plugins.twig.settings.debug'),
'charset' => flextype('registry')->get('plugins.twig.settings.charset')
];

// Create Twig View
$twig = new Twig(PATH['project'], $twigSettings);

// Instantiate
$router = $flextype->container('router');
$router = flextype('router');
$uri = Uri::createFromEnvironment(new Environment($_SERVER));

// Add Twig Extension
Expand All @@ -53,7 +53,7 @@
$twig->addExtension(new DebugExtension());

// Load Flextype Twig extensions from directory /flextype/twig/ based on settings.twig.extensions array
$twig_extensions = $flextype->container('registry')->get('plugins.twig.settings.extensions');
$twig_extensions = flextype('registry')->get('plugins.twig.settings.extensions');

foreach ($twig_extensions as $twig_extension) {
$twig_extension_class_name = $twig_extension . 'TwigExtension';
Expand All @@ -62,12 +62,12 @@
if (file_exists(ROOT_DIR . '/project/plugins/twig/twig/' . $twig_extension_class_name . '.php')) {

if ($twig_extension == 'Flash') {
$flextype->container()['flash'] = static function () {
flextype()->container()['flash'] = static function () {
return new Messages();
};
}

$twig->addExtension(new $twig_extension_class_name_with_namespace($flextype));
$twig->addExtension(new $twig_extension_class_name_with_namespace());
}
}

Expand Down
4 changes: 2 additions & 2 deletions plugin.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Twig
version: 1.2.0
version: 1.3.0
description: Twig plugin to present Twig template engine for Flextype.
icon: fas fa-palette
author:
Expand All @@ -11,4 +11,4 @@ bugs: https://github.com/flextype-plugins/twig/issues
license: MIT

dependencies:
flextype: 0.9.10
flextype: 0.9.11
17 changes: 6 additions & 11 deletions twig/ArraysTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,12 @@

class ArraysTwigExtension extends AbstractExtension implements GlobalsInterface
{
/**
* Flextype Application
*/
protected $flextype;

/**
* Constructor
*/
public function __construct($flextype)
public function __construct()
{
$this->flextype = $flextype;

}

/**
Expand All @@ -34,7 +29,7 @@ public function __construct($flextype)
public function getGlobals() : array
{
return [
'arrays' => new ArraysTwig($this->flextype),
'arrays' => new ArraysTwig(),
];
}
}
Expand All @@ -44,14 +39,14 @@ class ArraysTwig
/**
* Flextype Application
*/
protected $flextype;


/**
* Constructor
*/
public function __construct($flextype)
public function __construct()
{
$this->flextype = $flextype;

}

/**
Expand Down
11 changes: 3 additions & 8 deletions twig/CacheTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,12 @@

class CacheTwigExtension extends AbstractExtension implements GlobalsInterface
{
/**
* Flextype Application
*/
protected $flextype;

/**
* Constructor
*/
public function __construct($flextype)
public function __construct()
{
$this->flextype = $flextype;

}

/**
Expand All @@ -33,7 +28,7 @@ public function __construct($flextype)
public function getGlobals() : array
{
return [
'cache' => $this->flextype->container('cache'),
'cache' => flextype('cache'),
];
}
}
9 changes: 2 additions & 7 deletions twig/CollectionTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,12 @@

class CollectionTwigExtension extends AbstractExtension
{
/**
* Flextype Application
*/
protected $flextype;

/**
* Constructor
*/
public function __construct($flextype)
public function __construct()
{
$this->flextype = $flextype;

}

/**
Expand Down
21 changes: 8 additions & 13 deletions twig/CsrfTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,12 @@

class CsrfTwigExtension extends AbstractExtension implements GlobalsInterface
{
/**
* Flextype Application
*/
protected $flextype;

/**
* Constructor
*/
public function __construct($flextype)
public function __construct()
{
$this->flextype = $flextype;

}

/**
Expand All @@ -33,10 +28,10 @@ public function __construct($flextype)
public function getGlobals() : array
{
// CSRF token name and value
$csrfNameKey = $this->flextype->container('csrf')->getTokenNameKey();
$csrfValueKey = $this->flextype->container('csrf')->getTokenValueKey();
$csrfName = $this->flextype->container('csrf')->getTokenName();
$csrfValue = $this->flextype->container('csrf')->getTokenValue();
$csrfNameKey = flextype('csrf')->getTokenNameKey();
$csrfValueKey = flextype('csrf')->getTokenValueKey();
$csrfName = flextype('csrf')->getTokenName();
$csrfValue = flextype('csrf')->getTokenValue();

return [
'csrf' => [
Expand Down Expand Up @@ -72,7 +67,7 @@ public function getFunctions() : array
*/
public function csrf() : string
{
return '<input type="hidden" name="' . $this->flextype->container('csrf')->getTokenNameKey() . '" value="' . $this->flextype->container('csrf')->getTokenName() . '">' .
'<input type="hidden" name="' . $this->flextype->container('csrf')->getTokenValueKey() . '" value="' . $this->flextype->container('csrf')->getTokenValue() . '">';
return '<input type="hidden" name="' . flextype('csrf')->getTokenNameKey() . '" value="' . flextype('csrf')->getTokenName() . '">' .
'<input type="hidden" name="' . flextype('csrf')->getTokenValueKey() . '" value="' . flextype('csrf')->getTokenValue() . '">';
}
}
21 changes: 8 additions & 13 deletions twig/EmitterTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,12 @@

class EmitterTwigExtension extends AbstractExtension implements GlobalsInterface
{
/**
* Flextype Application
*/
protected $flextype;

/**
* Constructor
*/
public function __construct($flextype)
public function __construct()
{
$this->flextype = $flextype;

}

/**
Expand All @@ -33,7 +28,7 @@ public function __construct($flextype)
public function getGlobals() : array
{
return [
'emitter' => new EmitterTwig($this->flextype),
'emitter' => new EmitterTwig(),
];
}
}
Expand All @@ -43,29 +38,29 @@ class EmitterTwig
/**
* Flextype Application
*/
protected $flextype;


/**
* Constructor
*/
public function __construct($flextype)
public function __construct()
{
$this->flextype = $flextype;

}

/**
* Emitting event
*/
public function emit($event)
{
return $this->flextype->container('emitter')->emit($event);
return flextype('emitter')->emit($event);
}

/**
* Emitting events in batches
*/
public function emitBatch(array $events)
{
return $this->flextype->container('emitter')->emitBatch($events);
return flextype('emitter')->emitBatch($events);
}
}
27 changes: 7 additions & 20 deletions twig/EntriesTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,13 @@

class EntriesTwigExtension extends AbstractExtension implements GlobalsInterface
{
/**
* Flextype Application
*/
protected $flextype;

/**
* Constructor
*/
public function __construct($flextype)
{
$this->flextype = $flextype;
}

/**
* Register Global variables in an extension
*/
public function getGlobals() : array
{
return [
'entries' => new EntriesTwig($this->flextype),
'entries' => new EntriesTwig(),
];
}
}
Expand All @@ -43,37 +30,37 @@ class EntriesTwig
/**
* Flextype Application
*/
protected $flextype;


/**
* Constructor
*/
public function __construct($flextype)
public function __construct()
{
$this->flextype = $flextype;

}

/**
* Fetch entry(entries)
*/
public function fetch(string $path, bool $collection = false, array $filter = []) : array
{
return $this->flextype->container('entries')->fetch($path, $collection, $filter);
return flextype('entries')->fetch($path, $collection, $filter);
}

/**
* Fetch single entry
*/
public function fetchSingle(string $path) : array
{
return $this->flextype->container('entries')->fetch($path);
return flextype('entries')->fetch($path);
}

/**
* Fetch entries collection
*/
public function fetchCollection(string $path, array $filter = []) : array
{
return $this->flextype->container('entries')->fetchCollection($path, $filter);
return flextype('entries')->fetchCollection($path, $filter);
}
}
Loading

0 comments on commit ad4cf07

Please sign in to comment.