Skip to content

Commit

Permalink
update: 格式化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
NHZEX committed Aug 14, 2023
1 parent 592da35 commit 38fc5ed
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
->in([
'driver',
'src-next',
'tests',
]);

return (new PhpCsFixer\Config())
Expand All @@ -12,7 +13,6 @@
'@PHP74Migration' => true,
'normalize_index_brace' => true,
'global_namespace_import' => ['import_classes' => true, 'import_constants' => true, 'import_functions' => true],
'operator_linebreak' => ['only_booleans' => true, 'position' => 'beginning'],
'standardize_not_equals' => true,
'unary_operator_spaces' => true,
// risky
Expand Down
14 changes: 9 additions & 5 deletions driver/Blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@

namespace think\view\driver;

use HZEX\Blade\Register;
use think\App;
use think\contract\TemplateHandlerInterface;
use think\helper\Str;
use think\template\exception\TemplateNotFoundException;
use Zxin\Think\Blade\BladeViewService;
use Zxin\Think\Blade\ViewFactory;
use RuntimeException;

use function call_user_func_array;
use function is_object;
use function get_class;

class Blade implements TemplateHandlerInterface
{
Expand Down Expand Up @@ -91,11 +95,11 @@ public function fetch(string $template, array $data = []): void
$template = $this->parseTemplate($template);
}
// 模板不存在 抛出异常
if (! is_file($template)) {
if (!is_file($template)) {
if (class_exists(TemplateNotFoundException::class)) {
throw new TemplateNotFoundException('template not exists:'.$template, $template);
} else {
throw new \RuntimeException('template not exists:'.$template, 0);
throw new RuntimeException('template not exists:'.$template, 0);
}
}
$this->debugViewRender($template, $data);
Expand Down Expand Up @@ -139,10 +143,10 @@ public function parseTemplate(string $template)
[$app, $template] = explode('@', $template);
}

if ($this->config['view_path'] && ! isset($app)) {
if ($this->config['view_path'] && !isset($app)) {
$path = $this->config['view_path'];
} else {
$appName = isset($app) ? $app : $this->app->http->getName();
$appName = $app ?? $this->app->http->getName();
$view = $this->config['view_dir_name'];

if (is_dir($this->app->getAppPath().$view)) {
Expand Down
2 changes: 1 addition & 1 deletion src-next/BladeViewService.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function registerBladeCompiler()
public function registerEngineResolver()
{
$this->container->singleton('view.engine.resolver', function () {
$resolver = new EngineResolver;
$resolver = new EngineResolver();

// Next, we will register the various view engines with the resolver so that the
// environment will resolve the engines needed for various views based on the
Expand Down
30 changes: 16 additions & 14 deletions src-next/ContainerBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
use Closure;
use Illuminate\Contracts\Container\Container as ContainerContract;
use think\Container as ThinkContainer;
use ArrayAccess;
use RuntimeException;

class ContainerBridge implements \ArrayAccess, ContainerContract
class ContainerBridge implements ArrayAccess, ContainerContract
{
private ThinkContainer $container;

Expand All @@ -29,12 +31,12 @@ public function alias($abstract, $alias)

public function tag($abstracts, $tags)
{
throw new \RuntimeException('not support');
throw new RuntimeException('not support');
}

public function tagged($tag)
{
throw new \RuntimeException('not support');
throw new RuntimeException('not support');
}

public function bind($abstract, $concrete = null, $shared = false)
Expand All @@ -46,7 +48,7 @@ public function bind($abstract, $concrete = null, $shared = false)

public function bindIf($abstract, $concrete = null, $shared = false)
{
if (! $this->bound($abstract)) {
if (!$this->bound($abstract)) {
$this->bind($abstract, $concrete, $shared);
}
}
Expand All @@ -58,24 +60,24 @@ public function singleton($abstract, $concrete = null)

public function singletonIf($abstract, $concrete = null)
{
if (! $this->bound($abstract)) {
if (!$this->bound($abstract)) {
$this->singleton($abstract, $concrete);
}
}

public function scoped($abstract, $concrete = null)
{
throw new \RuntimeException('not support');
throw new RuntimeException('not support');
}

public function scopedIf($abstract, $concrete = null)
{
throw new \RuntimeException('not support');
throw new RuntimeException('not support');
}

public function extend($abstract, Closure $closure)
{
throw new \RuntimeException('not support');
throw new RuntimeException('not support');
}

public function instance($abstract, $instance)
Expand All @@ -85,12 +87,12 @@ public function instance($abstract, $instance)

public function addContextualBinding($concrete, $abstract, $implementation)
{
throw new \RuntimeException('not support');
throw new RuntimeException('not support');
}

public function when($concrete)
{
throw new \RuntimeException('not support');
throw new RuntimeException('not support');
}

public function factory($abstract)
Expand All @@ -101,7 +103,7 @@ public function factory($abstract)
public function flush()
{
// 可以考虑静默忽略
throw new \RuntimeException('not support');
throw new RuntimeException('not support');
}

public function make($abstract, array $parameters = [])
Expand All @@ -114,7 +116,7 @@ public function call($callback, array $parameters = [], $defaultMethod = null)
// $defaultMethod 无法实现,tp 仅支持`__make`

if (null !== $defaultMethod && '__make' !== $defaultMethod) {
throw new \RuntimeException('not support $defaultMethod');
throw new RuntimeException('not support $defaultMethod');
}

$this->container->invoke($callback, $parameters);
Expand All @@ -127,7 +129,7 @@ public function resolved($abstract)

public function beforeResolving($abstract, Closure $callback = null)
{
throw new \RuntimeException('not support');
throw new RuntimeException('not support');
}

public function resolving($abstract, Closure $callback = null)
Expand All @@ -137,7 +139,7 @@ public function resolving($abstract, Closure $callback = null)

public function afterResolving($abstract, Closure $callback = null)
{
throw new \RuntimeException('not support');
throw new RuntimeException('not support');
}

public function get(string $id)
Expand Down
2 changes: 1 addition & 1 deletion src-next/NullEventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ public function forgetPushed()
{
// TODO: Implement forgetPushed() method.
}
}
}
1 change: 1 addition & 0 deletions src-next/TpFileViewFinder.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Zxin\Think\Blade;
Expand Down
2 changes: 1 addition & 1 deletion src-next/ViewFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ public function render(string $view, array $params = []): string
{
return $this->make($view, $params)->render();
}
}
}
5 changes: 3 additions & 2 deletions tests/ViewBladeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
use PHPUnit\Framework\TestCase;
use think\App;
use think\view\driver\Blade;
use Generator;

class ViewBladeTest extends TestCase
{
const CONFIG = [
public const CONFIG = [
// 默认模板渲染规则 1 解析为小写+下划线 2 全部转换小写
'auto_rule' => 1,
// 模板引擎类型 支持 php think 支持扩展
Expand Down Expand Up @@ -202,7 +203,7 @@ public function testCustomDirective()
}

/**
* @return \Generator
* @return Generator
*/
public function customConditionProvider()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../vendor/autoload.php';

0 comments on commit 38fc5ed

Please sign in to comment.