pinkcrab/bladeone-engine 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pinkcrab/bladeone-engine

Composer 安装命令:

composer require pinkcrab/bladeone-engine

包简介

An implementation of the PinkCrab Renderable Interface used in the PinkCrab Plugin Framework V2+.

README 文档

README

logo

BladeOne_Engine

A BladeOne Engine for the PinkCrab Renderable Interface.

Latest Stable Version Total Downloads License PHP Version Require GitHub contributors GitHub issues

WP6.6 [PHP8.0-8.4] Tests WP6.7 [PHP8.0-8.4] Tests WP6.8 [PHP8.0-8.4] Tests WP6.9 [PHP8.0-8.4] Tests

codecov Scrutinizer Code Quality Maintainability

Supports and tested with the PinkCrab Perique Framework versions 2.1.*

Why?

The BladeOne implementation of the Renderable interface, allows the use of Blade within the PinkCrab Framework.

Setup

$ composer require pinkcrab/bladeone-engine

Out of the box, you can just include the BladeOne module when you are booting Perique and you will have full access to the BladeOne engine.

// Bootstrap for Perique follows as normal.. 
$app = ( new App_Factory('path/to/project/root') )
   ->default_config()
   ->module(BladeOne::class)
   // Rest of setup
   ->boot();

By default the following are assumed

  • path/to/project/root/views as the view path
  • path/wp-content/uploads/blade-cache as the cache path
  • MODE_AUTO

Usage

Just like the native PHP_Engine found with Perique, you can inject the View service into any class and use it to render a view.

class Some_Class {
   
      public function __construct( View $view ) {
         $this->view = $view;
      }
   
      public function render_view() {
         return $this->view->render('some.path.view_name', ['data' => 'to pass']);
      }
}

The above would render the template path/to/project/root/views/some/path/view_name.blade.php with access to $data in the view which would be to pass.

<p>{{ $data }}</p>

Would render as

<p>to pass</p>

It is fully possible to make use of the template inheritance and other blade features.

<div class="wrap">
   @include('partials.header')
   @yield('content')
   @include('partials.footer')
</div>
@extends('layouts.default')
@section('content')
   Some content
@stop

Configuring BladeOne

As with all other modules, BladeOne can be configured by passing a \Closure as the 2nd argument to the module() method.

// Bootstrap for Perique follows as normal..
$app = ( new App_Factory('path/to/project/root') )
   ->default_config()
   ->module(BladeOne::class, function( BladeOne $blade ) {
      // Module config.
      $blade
         ->template_path('path/to/custom/views')
         ->compiled_path('path/to/custom/cache'); // Fluent API for chaining.
      
      // Set the rendering mode.
      $blade->mode(  PinkCrab_BladeOne::MODE_DEBUG );

      // Set the comment mode.
      $blade->comment_mode( PinkCrab_BladeOne::COMMENT_RAW );

      // BladeOne_Engine config.
      $blade->config( function( BladeOne_Engine $engine  {
         // See all methods below.
         $engine
            ->set_compiled_extension('.php')
            ->directive('test', fn($e) =>'test'); // Fluent API for chaining.
         
         $engine->allow_pipe( false ); 
      });

      // Ensure you return the instance.
      return $blade;
   })
   // Rest of setup
   ->boot();
Compact BladeOne Config

It is possible to do the Module config in a much more concise fashion, using the fluent API and PHP Arrow functions

$app = ( new App_Factory('path/to/project/root') )
   ->default_config()
   ->module(BladeOne::class, fn( BladeOne $blade ) => $blade
      ->template_path('path/to/custom/views')
      ->compiled_path('path/to/custom/cache')
      ->mode(  PinkCrab_BladeOne::MODE_DEBUG )
      ->comment_mode( PinkCrab_BladeOne::COMMENT_RAW )
      ->config( fn( BladeOne_Engine $engine ) => $engine
         ->set_compiled_extension('.php')
         ->directive('test', fn($e) =>'test')
         ->allow_pipe( false )
      )
   )
->boot();

You can also hold the config in its own class and use that.

/** Some Class */
class BladeOneConfig {
   public function __invoke( BladeOne $blade ): BladeOne {
      return $blade
         // The setup.
   }
}

$app = ( new App_Factory('path/to/project/root') )
   ->default_config()
   ->module(BladeOne::class, new BladeOneConfig() )
   ->boot();

BladeOne_Module Config

You can call the following methods on the BladeOne Module to configure the BladeOne Module.

BladeOne_Engine Config

You can call the following methods on the BladeOne_Engine to configure the BladeOne_Engine.

Blade Templating

Most Blade features are present, to see the full docs please visit the EFTEC/BladeOne wiki

Included Components

Out of the box PinkCrab_BladeOne comes with the BladeOneHTML trait added, giving access all HTML components.

Magic Call Methods

The BladeOne class has a large selection of Static and regular methods, these can all be accessed from BladeOne_Engine. These can be called as follows.

// None static
$this->view->engine()->some_method($data);

// As static 
BladeOne_Engine::some_method($data);

The can also be called in templates.

{$this->some_method($data)}

// Or
{BladeOne_Engine::some_method($data)}

For the complete list of methods, please visit https://github.com/EFTEC/BladeOne/wiki/Methods-of-the-class

Static Access

// Using the App's View method to access none static methods on the fly.
App::view()->engine()->some_method($data);

calling engine() on view, will return the underlying rendering engine used, in this case PinkCrab_BladeOne.

Of course you can set the engine it self as a global variable using $provider->share('view_helper', [App::view(), 'engine']). Then you can use {$view_helper->some_method(\$data)} in your view.

Extending

It is possible to extend BladeOne via other plugins, if you would like to add additional functionality by adding custom directives, or adding additional methods to the BladeOne_Engine class. You can do this by using the PinkCrab_BladeOne::SETUP_CONFIG action and add any additional configs such as directives.

add_action( PinkCrab_BladeOne::SETUP_CONFIG, function( PinkCrab_BladeOne $engine ) {
    $engine->directive( 'my_directive', function( $expression ) {
        return "<?php echo 'Hello World'; ?>";
    } );
} );

Dependencies

Requires

License

MIT License

http://www.opensource.org/licenses/mit-license.html

Previous Perique Support

Change Log

  • 2.1.1 - Updated dev dependencies.
  • 2.1.0 - Updated to support Perique V2.1.x -- Please note version number jumped to match rest of Perique Framework --
  • 1.1.0 - Provides BladeOne 4.12+ and BladeOneHTML 2.4+. With comment mode support.
  • 1.0.1 - Last version to support pre 4.12 BladeOne (will be the last)
  • 1.0.0 - Migrated over from the Perique V2 Prep branch of BladeOne_Provider.
    • New Features
    • Auth and Permissions now hooked up and based on the current user.
    • Perique V2 Module structure.
    • WP Nonce support.

pinkcrab/bladeone-engine 适用场景与选型建议

pinkcrab/bladeone-engine 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.73k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 03 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 pinkcrab/bladeone-engine 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 pinkcrab/bladeone-engine 我们能提供哪些服务?
定制开发 / 二次开发

基于 pinkcrab/bladeone-engine 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.73k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 11
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-18