aboutsummaryrefslogtreecommitdiffhomepage
path: root/main/app/sprinkles/core/src/Twig
diff options
context:
space:
mode:
authorMarvin Borner2018-06-08 20:03:25 +0200
committerMarvin Borner2018-06-08 20:03:25 +0200
commit92b7dd3335a6572debeacfb5faa82c63a5e67888 (patch)
tree7ebbca22595d542ec5e2912a24a0400ac8f6b113 /main/app/sprinkles/core/src/Twig
parent22a1bb27f94ea33042b0bdd35bef1a5cfa96cc0d (diff)
Some minor fixes
Diffstat (limited to 'main/app/sprinkles/core/src/Twig')
-rw-r--r--main/app/sprinkles/core/src/Twig/CacheHelper.php114
-rw-r--r--main/app/sprinkles/core/src/Twig/CoreExtension.php240
2 files changed, 177 insertions, 177 deletions
diff --git a/main/app/sprinkles/core/src/Twig/CacheHelper.php b/main/app/sprinkles/core/src/Twig/CacheHelper.php
index a3c11c6..64799ca 100644
--- a/main/app/sprinkles/core/src/Twig/CacheHelper.php
+++ b/main/app/sprinkles/core/src/Twig/CacheHelper.php
@@ -1,57 +1,57 @@
-<?php
-/**
- * UserFrosting (http://www.userfrosting.com)
- *
- * @link https://github.com/userfrosting/UserFrosting
- * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
- */
-
-namespace UserFrosting\Sprinkle\Core\Twig;
-
-use Interop\Container\ContainerInterface;
-use Illuminate\Filesystem\Filesystem;
-
-/**
- * Provides helper function to delete the Twig cache directory
- *
- * @author Alex Weissman (https://alexanderweissman.com)
- */
-class CacheHelper
-{
-
- /**
- * @var ContainerInterface The global container object, which holds all your services.
- */
- protected $ci;
-
- /**
- * Constructor.
- *
- * @param ContainerInterface $ci The global container object, which holds all your services.
- */
- public function __construct(ContainerInterface $ci) {
- $this->ci = $ci;
- }
-
- /**
- * Function that delete the Twig cache directory content
- *
- * @access public
- * @return bool true/false if operation is successfull
- */
- public function clearCache() {
- // Get location
- $path = $this->ci->locator->findResource('cache://twig', TRUE, TRUE);
-
- // Get Filesystem instance
- $fs = new FileSystem;
-
- // Make sure directory exist and delete it
- if ($fs->exists($path)) {
- return $fs->deleteDirectory($path, TRUE);
- }
-
- // It's still considered a success if directory doesn't exist yet
- return TRUE;
- }
-}
+<?php
+/**
+ * UserFrosting (http://www.userfrosting.com)
+ *
+ * @link https://github.com/userfrosting/UserFrosting
+ * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
+ */
+
+namespace UserFrosting\Sprinkle\Core\Twig;
+
+use Interop\Container\ContainerInterface;
+use Illuminate\Filesystem\Filesystem;
+
+/**
+ * Provides helper function to delete the Twig cache directory
+ *
+ * @author Alex Weissman (https://alexanderweissman.com)
+ */
+class CacheHelper
+{
+
+ /**
+ * @var ContainerInterface The global container object, which holds all your services.
+ */
+ protected $ci;
+
+ /**
+ * Constructor.
+ *
+ * @param ContainerInterface $ci The global container object, which holds all your services.
+ */
+ public function __construct(ContainerInterface $ci) {
+ $this->ci = $ci;
+ }
+
+ /**
+ * Function that delete the Twig cache directory content
+ *
+ * @access public
+ * @return bool true/false if operation is successfull
+ */
+ public function clearCache() {
+ // Get location
+ $path = $this->ci->locator->findResource('cache://twig', TRUE, TRUE);
+
+ // Get Filesystem instance
+ $fs = new FileSystem;
+
+ // Make sure directory exist and delete it
+ if ($fs->exists($path)) {
+ return $fs->deleteDirectory($path, TRUE);
+ }
+
+ // It's still considered a success if directory doesn't exist yet
+ return TRUE;
+ }
+}
diff --git a/main/app/sprinkles/core/src/Twig/CoreExtension.php b/main/app/sprinkles/core/src/Twig/CoreExtension.php
index 2837e84..fccd542 100644
--- a/main/app/sprinkles/core/src/Twig/CoreExtension.php
+++ b/main/app/sprinkles/core/src/Twig/CoreExtension.php
@@ -1,120 +1,120 @@
-<?php
-/**
- * UserFrosting (http://www.userfrosting.com)
- *
- * @link https://github.com/userfrosting/UserFrosting
- * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
- */
-
-namespace UserFrosting\Sprinkle\Core\Twig;
-
-use Interop\Container\ContainerInterface;
-use UserFrosting\Sprinkle\Core\Util\Util;
-
-/**
- * Extends Twig functionality for the Core sprinkle.
- *
- * @author Alex Weissman (https://alexanderweissman.com)
- */
-class CoreExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface
-{
-
- /**
- * @var ContainerInterface The global container object, which holds all your services.
- */
- protected $services;
-
- /**
- * Constructor.
- *
- * @param ContainerInterface $services The global container object, which holds all your services.
- */
- public function __construct(ContainerInterface $services) {
- $this->services = $services;
- }
-
- /**
- * Get the name of this extension.
- *
- * @return string
- */
- public function getName() {
- return 'userfrosting/core';
- }
-
- /**
- * Adds Twig functions `getAlerts` and `translate`.
- *
- * @return array[\Twig_SimpleFunction]
- */
- public function getFunctions() {
- return array(
- // Add Twig function for fetching alerts
- new \Twig_SimpleFunction('getAlerts', function ($clear = TRUE) {
- if ($clear) {
- return $this->services['alerts']->getAndClearMessages();
- } else {
- return $this->services['alerts']->messages();
- }
- }),
- new \Twig_SimpleFunction('translate', function ($hook, $params = array()) {
- return $this->services['translator']->translate($hook, $params);
- }, [
- 'is_safe' => ['html']
- ])
- );
- }
-
- /**
- * Adds Twig filters `unescape`.
- *
- * @return array[\Twig_SimpleFilter]
- */
- public function getFilters() {
- return array(
- /**
- * Converts phone numbers to a standard format.
- *
- * @param String $num A unformatted phone number
- * @return String Returns the formatted phone number
- */
- new \Twig_SimpleFilter('phone', function ($num) {
- return Util::formatPhoneNumber($num);
- }),
- new \Twig_SimpleFilter('unescape', function ($string) {
- return html_entity_decode($string);
- })
- );
- }
-
- /**
- * Adds Twig global variables `site` and `assets`.
- *
- * @return array[mixed]
- */
- public function getGlobals() {
- // CSRF token name and value
- $csrfNameKey = $this->services->csrf->getTokenNameKey();
- $csrfValueKey = $this->services->csrf->getTokenValueKey();
- $csrfName = $this->services->csrf->getTokenName();
- $csrfValue = $this->services->csrf->getTokenValue();
-
- $csrf = [
- 'csrf' => [
- 'keys' => [
- 'name' => $csrfNameKey,
- 'value' => $csrfValueKey
- ],
- 'name' => $csrfName,
- 'value' => $csrfValue
- ]
- ];
-
- $site = array_replace_recursive($this->services->config['site'], $csrf);
-
- return [
- 'site' => $site,
- 'assets' => $this->services->assets
- ];
- }
-}
+<?php
+/**
+ * UserFrosting (http://www.userfrosting.com)
+ *
+ * @link https://github.com/userfrosting/UserFrosting
+ * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
+ */
+
+namespace UserFrosting\Sprinkle\Core\Twig;
+
+use Interop\Container\ContainerInterface;
+use UserFrosting\Sprinkle\Core\Util\Util;
+
+/**
+ * Extends Twig functionality for the Core sprinkle.
+ *
+ * @author Alex Weissman (https://alexanderweissman.com)
+ */
+class CoreExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface
+{
+
+ /**
+ * @var ContainerInterface The global container object, which holds all your services.
+ */
+ protected $services;
+
+ /**
+ * Constructor.
+ *
+ * @param ContainerInterface $services The global container object, which holds all your services.
+ */
+ public function __construct(ContainerInterface $services) {
+ $this->services = $services;
+ }
+
+ /**
+ * Get the name of this extension.
+ *
+ * @return string
+ */
+ public function getName() {
+ return 'userfrosting/core';
+ }
+
+ /**
+ * Adds Twig functions `getAlerts` and `translate`.
+ *
+ * @return array[\Twig_SimpleFunction]
+ */
+ public function getFunctions() {
+ return array(
+ // Add Twig function for fetching alerts
+ new \Twig_SimpleFunction('getAlerts', function ($clear = TRUE) {
+ if ($clear) {
+ return $this->services['alerts']->getAndClearMessages();
+ } else {
+ return $this->services['alerts']->messages();
+ }
+ }),
+ new \Twig_SimpleFunction('translate', function ($hook, $params = array()) {
+ return $this->services['translator']->translate($hook, $params);
+ }, [
+ 'is_safe' => ['html']
+ ])
+ );
+ }
+
+ /**
+ * Adds Twig filters `unescape`.
+ *
+ * @return array[\Twig_SimpleFilter]
+ */
+ public function getFilters() {
+ return array(
+ /**
+ * Converts phone numbers to a standard format.
+ *
+ * @param String $num A unformatted phone number
+ * @return String Returns the formatted phone number
+ */
+ new \Twig_SimpleFilter('phone', function ($num) {
+ return Util::formatPhoneNumber($num);
+ }),
+ new \Twig_SimpleFilter('unescape', function ($string) {
+ return html_entity_decode($string);
+ })
+ );
+ }
+
+ /**
+ * Adds Twig global variables `site` and `assets`.
+ *
+ * @return array[mixed]
+ */
+ public function getGlobals() {
+ // CSRF token name and value
+ $csrfNameKey = $this->services->csrf->getTokenNameKey();
+ $csrfValueKey = $this->services->csrf->getTokenValueKey();
+ $csrfName = $this->services->csrf->getTokenName();
+ $csrfValue = $this->services->csrf->getTokenValue();
+
+ $csrf = [
+ 'csrf' => [
+ 'keys' => [
+ 'name' => $csrfNameKey,
+ 'value' => $csrfValueKey
+ ],
+ 'name' => $csrfName,
+ 'value' => $csrfValue
+ ]
+ ];
+
+ $site = array_replace_recursive($this->services->config['site'], $csrf);
+
+ return [
+ 'site' => $site,
+ 'assets' => $this->services->assets
+ ];
+ }
+}