Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed Aug 19, 2020
2 parents deee3d7 + 53b5305 commit 49c0c19
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 49 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/site/compare/v1.2.0...v1.3.0) (2020-08-19)

### Features

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

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

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

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

Site plugin to display entries content on the website frontend.
Expand All @@ -14,7 +14,7 @@ The following dependencies need to be downloaded and installed for Site Plugin.

| Item | Version | Download |
|---|---|---|
| [flextype](https://github.com/flextype/flextype) | 0.9.9 | [download](https://github.com/flextype/flextype/releases) |
| [flextype](https://github.com/flextype/flextype) | 0.9.10 | [download](https://github.com/flextype/flextype/releases) |
| [twig](https://github.com/flextype-plugins/twig) | >=1.0.0 | [download](https://github.com/flextype-plugins/twig/releases) |
| [noir](https://github.com/flextype-themes/noir) | >=1.0.0 | [download](https://github.com/flextype-themes/noir/releases) |

Expand Down Expand Up @@ -92,8 +92,8 @@ You can also reach these same values from a Flextype theme(s) with PHP syntax:
Usage:

```php
$theme_name = $flextype->registry->get('themes.noir.manifest.name');
$theme_version = $flextype->registry->get('themes.noir.manifest.version');
$theme_name = $flextype->container('registry')->get('themes.noir.manifest.name');
$theme_version = $flextype->container('registry')->get('themes.noir.manifest.version');
```

### Accessing Theme Configuration
Expand Down Expand Up @@ -131,7 +131,7 @@ Result:
In PHP you can access the current theme configuration like this:

```php
$highlight = $flextype->registry->get('themes.noir.settings.highlight');
$highlight = $flextype->container('registry')->get('themes.noir.settings.highlight');
```

## LICENSE
Expand Down
39 changes: 21 additions & 18 deletions app/Controllers/SiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
use Psr\Http\Message\ServerRequestInterface as Request;
use function ltrim;
use Flextype\Component\Filesystem\Filesystem;
use Flextype\App\Foundation\Container;

class SiteController extends Container
class SiteController
{
/**
* Current entry data array
Expand All @@ -29,13 +28,17 @@ class SiteController extends Container
*/
public $entry = [];

/**
* Flextype
*/
protected $flextype;

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

/**
Expand All @@ -58,13 +61,13 @@ public function index(Request $request, Response $response, array $args) : Respo

// If uri is empty then it is main entry else use entry uri
if ($uri === '/') {
$entry_uri = $this->registry->get('plugins.site.settings.entries.main');
$entry_uri = $this->flextype->container('registry')->get('plugins.site.settings.entries.main');
} else {
$entry_uri = ltrim($uri, '/');
}

// Get entry body
$entry_body = $this->entries->fetch($entry_uri);
$entry_body = $this->flextype->container('entries')->fetch($entry_uri);

// is entry not found
$is_entry_not_found = false;
Expand All @@ -88,7 +91,7 @@ public function index(Request $request, Response $response, array $args) : Respo
$this->entry = $entry;

// Run event onSiteEntryAfterInitialized
$this->emitter->emit('onSiteEntryAfterInitialized');
$this->flextype->container('emitter')->emit('onSiteEntryAfterInitialized');

// Return in JSON Format
if ($is_json) {
Expand All @@ -100,24 +103,24 @@ public function index(Request $request, Response $response, array $args) : Respo
}

// Set template path for current entry
$path = 'themes/' . $this->registry->get('plugins.site.settings.theme') . '/' . (empty($this->entry['template']) ? 'templates/default' : 'templates/' . $this->entry['template']) . '.html';
$path = 'themes/' . $this->flextype->container('registry')->get('plugins.site.settings.theme') . '/' . (empty($this->entry['template']) ? 'templates/default' : 'templates/' . $this->entry['template']) . '.html';

self::includeCurrentThemeBootstrap($this->container, $this->app);
self::includeCurrentThemeBootstrap($this->flextype);

if (! Filesystem::has(PATH['project'] . '/' . $path)) {
return $response->write("Template {$this->entry['template']} not found");
}

if ($is_entry_not_found) {
return $this->twig->render($response->withStatus(404), $path, ['entry' => $this->entry, 'query' => $query, 'uri' => $uri]);
return $this->flextype->container('twig')->render($response->withStatus(404), $path, ['entry' => $this->entry, 'query' => $query, 'uri' => $uri]);
}

return $this->twig->render($response, $path, ['entry' => $this->entry, 'query' => $query, 'uri' => $uri]);
return $this->flextype->container('twig')->render($response, $path, ['entry' => $this->entry, 'query' => $query, 'uri' => $uri]);
}

private static function includeCurrentThemeBootstrap($flextype, $app)
private static function includeCurrentThemeBootstrap($flextype)
{
$bootstrap_path = 'themes/' . $flextype->registry->get('plugins.site.settings.theme') . '/bootstrap.php';
$bootstrap_path = 'themes/' . $flextype->container('registry')->get('plugins.site.settings.theme') . '/bootstrap.php';

if (Filesystem::has(PATH['project'] . '/' . $bootstrap_path)) {
include_once PATH['project'] . '/' . $bootstrap_path;
Expand All @@ -134,10 +137,10 @@ private static function includeCurrentThemeBootstrap($flextype, $app)
public function error404() : array
{
return [
'title' => $this->registry->get('plugins.site.settings.entries.error404.title'),
'description' => $this->registry->get('plugins.site.settings.entries.error404.description'),
'content' => $this->registry->get('plugins.site.settings.entries.error404.content'),
'template' => $this->registry->get('plugins.site.settings.entries.error404.template'),
'title' => $this->flextype->container('registry')->get('plugins.site.settings.entries.error404.title'),
'description' => $this->flextype->container('registry')->get('plugins.site.settings.entries.error404.description'),
'content' => $this->flextype->container('registry')->get('plugins.site.settings.entries.error404.content'),
'template' => $this->flextype->container('registry')->get('plugins.site.settings.entries.error404.template'),
];
}
}
24 changes: 12 additions & 12 deletions app/Models/Themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
class Themes
{
/**
* Flextype Dependency Container
*
*/
private $flextype;
protected $flextype;

/**
* Private construct method to enforce singleton behavior.
Expand All @@ -38,10 +38,10 @@ public function __construct($flextype)
/**
* Init themes
*/
public function init($flextype, $app) : void
public function init($flextype) : void
{
// Set empty themes list item
$this->flextype['registry']->set('themes', []);
$this->flextype->container('registry')->set('themes', []);

// Get themes list
$themes_list = $this->getThemes();
Expand All @@ -55,8 +55,8 @@ public function init($flextype, $app) : void
$themes_cache_id = $this->getThemesCacheID($themes_list);

// Get themes list from cache or scan themes folder and create new themes cache item in the registry
if ($this->flextype['cache']->contains($themes_cache_id)) {
$this->flextype['registry']->set('themes', $this->flextype['cache']->fetch($themes_cache_id));
if ($this->flextype->container('cache')->contains($themes_cache_id)) {
$this->flextype->container('registry')->set('themes', $this->flextype->container('cache')->fetch($themes_cache_id));
} else {
$themes = [];
$themes_settings = [];
Expand Down Expand Up @@ -91,7 +91,7 @@ public function init($flextype, $app) : void
if (trim($default_theme_settings_file_content) === '') {
$default_theme_settings = [];
} else {
$default_theme_settings = $this->flextype['yaml']->decode($default_theme_settings_file_content);
$default_theme_settings = $this->flextype->container('yaml')->decode($default_theme_settings_file_content);
}

// Create custom theme settings file
Expand All @@ -102,7 +102,7 @@ public function init($flextype, $app) : void
if (trim($custom_theme_settings_file_content) === '') {
$custom_theme_settings = [];
} else {
$custom_theme_settings = $this->flextype['yaml']->decode($custom_theme_settings_file_content);
$custom_theme_settings = $this->flextype->container('yaml')->decode($custom_theme_settings_file_content);
}

// Check if default theme manifest file exists
Expand All @@ -112,7 +112,7 @@ public function init($flextype, $app) : void

// Get default theme manifest content
$default_theme_manifest_file_content = Filesystem::read($default_theme_manifest_file);
$default_theme_manifest = $this->flextype['yaml']->decode($default_theme_manifest_file_content);
$default_theme_manifest = $this->flextype->container('yaml')->decode($default_theme_manifest_file_content);

// Merge theme settings and manifest data
$themes[$theme['dirname']]['manifest'] = $default_theme_manifest;
Expand All @@ -121,14 +121,14 @@ public function init($flextype, $app) : void
}

// Save parsed themes list in the registry themes
$this->flextype['registry']->set('themes', $themes);
$this->flextype->container('registry')->set('themes', $themes);

// Save parsed themes list in the cache
$this->flextype['cache']->save($themes_cache_id, $themes);
$this->flextype->container('cache')->save($themes_cache_id, $themes);
}

// Emit onThemesInitialized
$this->flextype['emitter']->emit('onThemesInitialized');
$this->flextype->container('emitter')->emit('onThemesInitialized');
}

/**
Expand Down
6 changes: 3 additions & 3 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
/**
* Include web routes
*/
include_once 'routes/web.php';
include_once __DIR__ . '/routes/web.php';

/**
* Include dependencies
*/
include_once 'dependencies.php';
include_once __DIR__ . '/dependencies.php';

/**
* Include Middlewares
*/
include_once 'middlewares.php';
include_once __DIR__ . '/middlewares.php';
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
"issues": "https://github.com/flextype-plugins/site/issues"
},
"require": {
"php": ">=7.2.5",
"php": ">=7.3.0",
"ext-json": "*",
"middlewares/trailing-slash": "~1.1.0"
},
"config": {
"apcu-autoloader": true,
"optimize-autoloader": true,
"platform": {
"php": "7.2.5"
"php": "7.3.0"
}
},
"autoload": {
Expand Down
10 changes: 5 additions & 5 deletions dependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
/**
* Add themes service to Flextype container
*/
$flextype['themes'] = static function ($flextype) use ($app) {
return new Themes($flextype, $app);
$flextype->container()['themes'] = static function () use ($flextype) {
return new Themes($flextype);
};

/**
* Init themes
*/
$flextype['themes']->init($flextype, $app);
$flextype->container()['themes']->init($flextype);

/**
* Add site controller to Flextype container
*/
$flextype['SiteController'] = static function ($flextype) use ($app) {
return new SiteController($flextype, $app);
$flextype->container()['SiteController'] = static function () use ($flextype) {
return new SiteController($flextype);
};
2 changes: 1 addition & 1 deletion middlewares.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
/**
* Add middleware TrailingSlash for all routes
*/
$app->add((new TrailingSlash(false))->redirect(true));
$flextype->add((new TrailingSlash(false))->redirect(true));
4 changes: 2 additions & 2 deletions plugin.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Site
version: 1.2.0
version: 1.3.0
description: Site plugin to display entries content on the website frontend.
icon: fas fa-globe
author:
Expand All @@ -11,5 +11,5 @@ bugs: https://github.com/flextype-plugins/site/issues
license: MIT

dependencies:
flextype: 0.9.9
flextype: 0.9.10
twig: '>=1.0.0'
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
* file that was distributed with this source code.
*/

$app->get('{uri:.+}', 'SiteController:index')->setName('site.index')->add('csrf');
$flextype->get('{uri:.+}', 'SiteController:index')->setName('site.index')->add('csrf');

0 comments on commit 49c0c19

Please sign in to comment.