Skip to content

Commit

Permalink
Merge branch '2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
jlambe committed Nov 29, 2019
2 parents d0149d5 + de0119d commit db9d5c7
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 40 deletions.
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@
"league/fractal": "^0.17.0",
"ramsey/uuid": "^3.8",
"symfony/property-access": "^4.2",
"twig/twig": " ^2.0",
"twig/twig": " ^2.12",
"vlucas/phpdotenv": "^3.3"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.15",
"phpstan/phpstan-shim": "^0.11.8",
"phpunit/phpunit": "^7.0",
"symfony/var-dumper": "^4.1"
"symfony/var-dumper": "^4.1",
"szepeviktor/phpstan-wordpress": "^0.3"
},
"suggest": {
"fzaninotto/faker": "Required to use the eloquent factory builder (^1.8)."
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "themosis-framework",
"version": "2.0.2",
"version": "2.0.5",
"description": "A WordPress framework.",
"directories": {
"test": "resources/assets/js/tests"
Expand Down
18 changes: 18 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Start command: composer update --classmap-authoritative && vendor/bin/phpstan analyze

includes:
# https://github.com/phpstan/phpstan/blob/master/conf/bleedingEdge.neon
- phar://phpstan.phar/conf/bleedingEdge.neon
- vendor/szepeviktor/phpstan-wordpress/extension.neon
parameters:
level: 2
paths:
- %currentWorkingDirectory%/src/
excludes_analyse:
- %currentWorkingDirectory%/src/Page/views
- %currentWorkingDirectory%/src/Core/Exceptions/views
- %currentWorkingDirectory%/src/Taxonomy/views
- %currentWorkingDirectory%/src/PostType/views
- %currentWorkingDirectory%/src/Forms/views
- %currentWorkingDirectory%/src/Auth/Console/stubs/make/views
- %currentWorkingDirectory%/src/User/views
2 changes: 1 addition & 1 deletion src/Core/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Application extends Container implements ApplicationContract, HttpKernelIn
*
* @var string
*/
const VERSION = '2.0.4';
const VERSION = '2.0.5';

/**
* Application textdomain.
Expand Down
4 changes: 3 additions & 1 deletion src/Core/Console/KeyGenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public function handle()
$key = $this->generateRandomKey();

if ($this->option('show')) {
return $this->line('<comment>'.$key.'</comment>');
$this->line('<comment>'.$key.'</comment>');

return;
}

// Next, we will replace the application key in the environment file so it is
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Fields/Types/ChoiceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ protected function saveMultipleValue($value, int $post_id)
} else {
delete_post_meta($post_id, $this->getName());

array_walk($value, function ($val) use ($post_id, $previous) {
array_walk($value, function ($val) use ($post_id) {
add_post_meta($post_id, $this->getName(), $val, false);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Fields/Types/CollectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function metaboxSave($value, int $post_id)
} else {
delete_post_meta($post_id, $this->getName());

array_walk($value, function ($val) use ($post_id, $previous) {
array_walk($value, function ($val) use ($post_id) {
add_post_meta($post_id, $this->getName(), $val, false);
});
}
Expand Down
8 changes: 6 additions & 2 deletions src/Metabox/Metabox.php
Original file line number Diff line number Diff line change
Expand Up @@ -643,12 +643,16 @@ public function getTemplate(): array
/**
* Check if given post should use the template.
*
* @param \WP_Post $post
* @param \WP_Post|\WP_Comment $post
*
* @return bool
*/
private function hasTemplateForPost(\WP_Post $post): bool
private function hasTemplateForPost($post): bool
{
if (is_a($post, 'WP_Comment')) {
return false;
}

$postTemplate = get_post_meta($post->ID, '_wp_page_template', true);

$templates = isset($this->template[$post->post_type]) ? $this->template[$post->post_type] : [];
Expand Down
2 changes: 1 addition & 1 deletion src/Taxonomy/TaxonomyField.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ protected function register()
*/
protected function sanitize(FieldTypeInterface $field)
{
return function ($value, $key, $type) use ($field) {
return function ($value, $key, $type) {
$validator = $this->validator->make(
[$key => $value],
$this->getTermRules(),
Expand Down
9 changes: 5 additions & 4 deletions src/View/Engines/Twig.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Contracts\View\Engine;
use Themosis\View\FileViewFinder;
use Twig\Environment;

class Twig implements Engine
{
Expand All @@ -22,7 +23,7 @@ class Twig implements Engine
*/
protected $extension = '.twig';

public function __construct(\Twig_Environment $twig, FileViewFinder $finder)
public function __construct(Environment $twig, FileViewFinder $finder)
{
$this->twig = $twig;
$this->finder = $finder;
Expand All @@ -34,9 +35,9 @@ public function __construct(\Twig_Environment $twig, FileViewFinder $finder)
* @param string $path The file name with its file extension.
* @param array $data View data (context)
*
* @throws \Twig_Error_Loader
* @throws \Twig_Error_Runtime
* @throws \Twig_Error_Syntax
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*
* @return string
*/
Expand Down
51 changes: 28 additions & 23 deletions src/View/Extensions/WordPress.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

namespace Themosis\View\Extensions;

class WordPress extends \Twig_Extension implements \Twig_Extension_GlobalsInterface
use Twig\Extension\AbstractExtension;
use Twig\Extension\GlobalsInterface;
use Twig\TwigFilter;
use Twig\TwigFunction;

class WordPress extends AbstractExtension implements GlobalsInterface
{
/**
* Register Twig templates globals.
Expand Down Expand Up @@ -44,19 +49,19 @@ public function getFunctions()
/**
* Theme functions
*/
new \Twig_Function('body_class', function ($class = '') {
new TwigFunction('body_class', function ($class = '') {
return body_class($class);
}),
new \Twig_Function('post_class', function ($class = '', $post_id = null) {
new TwigFunction('post_class', function ($class = '', $post_id = null) {
return post_class($class, $post_id);
}),
new \Twig_Function('wp_head', 'wp_head'),
new \Twig_Function('wp_footer', 'wp_footer'),
new TwigFunction('wp_head', 'wp_head'),
new TwigFunction('wp_footer', 'wp_footer'),

/**
* Helper functions
*/
new \Twig_Function('fn', function ($name) {
new TwigFunction('fn', function ($name) {
$args = func_get_args();

// By default, the function signature should be the first argument.
Expand All @@ -65,41 +70,41 @@ public function getFunctions()

return call_user_func_array(trim($name), $args);
}),
new \Twig_Function('meta', function ($object_id, $meta_key = '', $single = false, $meta_type = 'post') {
new TwigFunction('meta', function ($object_id, $meta_key = '', $single = false, $meta_type = 'post') {
return meta($object_id, $meta_key, $single, $meta_type);
}),

/**
* Translations functions
*/
new \Twig_Function('__', function ($text, $domain = 'default') {
new TwigFunction('__', function ($text, $domain = 'default') {
return __($text, $domain);
}),
new \Twig_Function('_e', function ($text, $domain = 'default') {
new TwigFunction('_e', function ($text, $domain = 'default') {
return _e($text, $domain);
}),
new \Twig_Function('_ex', function ($text, $context, $domain = 'default') {
new TwigFunction('_ex', function ($text, $context, $domain = 'default') {
return _ex($text, $context, $domain);
}),
new \Twig_Function('_n', function ($singular, $plural, $number, $domain = 'default') {
new TwigFunction('_n', function ($singular, $plural, $number, $domain = 'default') {
return _n($singular, $plural, $number, $domain);
}),
new \Twig_Function('_n_noop', function ($singular, $plural, $domain = 'default') {
new TwigFunction('_n_noop', function ($singular, $plural, $domain = 'default') {
return _n_noop($singular, $plural, $domain);
}),
new \Twig_Function('_nx', function ($singular, $plural, $number, $context, $domain = 'default') {
new TwigFunction('_nx', function ($singular, $plural, $number, $context, $domain = 'default') {
return _nx($singular, $plural, $number, $context, $domain);
}),
new \Twig_Function('_nx_noop', function ($singular, $plural, $context, $domain = 'default') {
new TwigFunction('_nx_noop', function ($singular, $plural, $context, $domain = 'default') {
return _nx_noop($singular, $plural, $context, $domain);
}),
new \Twig_Function('_x', function ($text, $context, $domain = 'default') {
new TwigFunction('_x', function ($text, $context, $domain = 'default') {
return _x($text, $context, $domain);
}),
new \Twig_Function('translate', function ($text, $domain = 'default') {
new TwigFunction('translate', function ($text, $domain = 'default') {
return translate($text, $domain);
}),
new \Twig_Function('translate_nooped_plural', function ($plural, $count, $domain = 'default') {
new TwigFunction('translate_nooped_plural', function ($plural, $count, $domain = 'default') {
return translate_nooped_plural($plural, $count, $domain);
})
];
Expand All @@ -117,22 +122,22 @@ public function getFilters()
/**
* Formatting filters.
*/
new \Twig_Filter('wpantispam', function ($email, $encoding = 0) {
new TwigFilter('wpantispam', function ($email, $encoding = 0) {
return antispambot($email, $encoding);
}),
new \Twig_Filter('wpautop', function ($text, $br = true) {
new TwigFilter('wpautop', function ($text, $br = true) {
return wpautop($text, $br);
}),
new \Twig_Filter('wpnofollow', function ($text) {
new TwigFilter('wpnofollow', function ($text) {
return wp_rel_nofollow($text);
}),
new \Twig_Filter('wptrimexcerpt', function ($text) {
new TwigFilter('wptrimexcerpt', function ($text) {
return wp_trim_excerpt($text);
}),
new \Twig_Filter('wptrimwords', function ($text, $num_words = 55, $more = null) {
new TwigFilter('wptrimwords', function ($text, $num_words = 55, $more = null) {
return wp_trim_words($text, $num_words, $more);
}),
new \Twig_Filter('zeroise', function ($number, $treshold = 4) {
new TwigFilter('zeroise', function ($number, $treshold = 4) {
return zeroise($number, $treshold);
})
];
Expand Down
9 changes: 6 additions & 3 deletions src/View/ViewServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use Illuminate\View\ViewServiceProvider as IlluminateViewServiceProvider;
use Themosis\View\Engines\Twig;
use Themosis\View\Extensions\WordPress;
use Twig\Environment;
use Twig\Extension\DebugExtension;
use Twig\Loader\FilesystemLoader;

class ViewServiceProvider extends IlluminateViewServiceProvider
{
Expand Down Expand Up @@ -36,7 +39,7 @@ public function registerViewFinder()
public function registerTwigLoader()
{
$this->app->singleton('twig.loader', function ($app) {
return new \Twig_Loader_Filesystem($app['view.finder']->getPaths());
return new FilesystemLoader($app['view.finder']->getPaths());
});
}

Expand All @@ -46,7 +49,7 @@ public function registerTwigLoader()
public function registerTwigEnvironment()
{
$this->app->singleton('twig', function ($app) {
$twig = new \Twig_Environment(
$twig = new Environment(
$app['twig.loader'],
[
'auto_reload' => true,
Expand All @@ -55,7 +58,7 @@ public function registerTwigEnvironment()
);

// Add Twig Debug Extension
$twig->addExtension(new \Twig_Extension_Debug());
$twig->addExtension(new DebugExtension());

// Enable debug.
if ($app['config']['app.debug']) {
Expand Down

0 comments on commit db9d5c7

Please sign in to comment.