1. Go to this page and download the library: Download pinkcrab/bladeone-provider library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pinkcrab / bladeone-provider example snippets
/**
* Bootstrap Blade into Perique
*
* @param string|array $views_path The Path or paths used for the template files.
* @param string $cache_path The path where all compiled/cached template files.
* @param int|null $blade_mode The mode to start blade one using ( )
* @param class_string | PinkCrab_BladeOne::class $blade_class The implementation of BladeOne to use
*/
BladeOne_Bootstrap::use( $views_path, $cache_path, $blade_mode, $blade_class );
// Bootstrap for Perique follows as normal..
$app = ( new App_Factory() )->with_wp_dice( true )
->.....
class My_Blade_Config extends Abstract_BladeOne_Config {
// Services can be injected using DI as normal (with Perique)
protected $service;
public function __construct( Mock_Service $service ) {
$this->service = $service;
}
/**
* This is the only method that must be implemented
* @param BladeOne_Provider $provider The instance of BladeOne being used.
*/
public function config( BladeOne_Provider $provider ): void {
// Use this method to configure Blade
// Details of methods can be found below.
$provider->set_compiled_extension( $this->service->get_cache_file_extension() );
$provider->directive( 'test', [ $this->service, 'some_method' ] );
$provider->allow_pipe( false ); // Pipe is enabled by default, unlike standard BladeOne
}
}
/**
* Sets if piping is enabled in templates.
*
* @param bool $bool
* @return self
*/
public function allow_pipe( bool $bool = true ): self{}
/**
* Register a handler for custom directives.
*
* @param string $name
* @param callable $handler
* @return self
*/
public function directive( string $name, callable $handler ): self{}
// Directive Example
$provider->directive('datetime', function ($expression) {
// Return a valid PHP expression in php tags
return " echo ($expression)->format('m/d/Y H:i');
// You will need to pass $now to your view
$class->render('path.to.view', ['now' => new DateTime()]);
/**
* Register a handler for custom directives at runtime only.
*
* @param string $name
* @param callable $handler
* @return self
*/
public function directive_rt( string $name, callable $handler ): self{}
// Directive at Run Time Example
$provider->directive_rt('datetime', function ($expression) {
// Just print/echo the value.
return "echo $expression->format('m/d/Y H:i');";
});
// You will need to pass $now to your view
$class->render('path.to.view', ['now' => new DateTime()]);
/**
* Define a template alias
*
* @param string $view example "folder.template"
* @param string|null $alias example "mynewop". If null then it uses the name of the template.
* @return self
*/
public function add_
// Directive at Run Time Example
$provider->add_s->render('longpath', ['data' => $data]);
/**
* Define a class with a namespace
*
* @param string $alias_name
* @param string $class_with_namespace
* @return self
*/
public function add_alias_classes( $alias_name, $class_with_namespace ): self{}
/**
* Adds a global variable. If <b>$var_name</b> is an array then it merges all the values.
* <b>Example:</b>
* <pre>
* $this->share('variable',10.5);
* $this->share('variable2','hello');
* // or we could add the two variables as:
* $this->share(['variable'=>10.5,'variable2'=>'hello']);
* </pre>
*
* @param string|array<string, mixed> $var_name It is the name of the variable or it is an associative array
* @param mixed $value
* @return self
*/
public function share( $var_name, $value = null ): self{}
/**
* Set the compile mode
*
* @param int $mode
* Constants
* BladeOne::MODE_AUTO,
* BladeOne::MODE_DEBUG,
* BladeOne::MODE_FAST,
* BladeOne::MODE_SLOW
* @return self
*/
public function set_mode( int $mode ): self{}
$provider->set_mode(BladeOne::MODE_AUTO);
/**
* Set the file extension for the template files.
* It must urn self
*/
public function set_file_extension( string $file_extension ): self{}
$provider->set_file_extension('.view.php');
// Can then be used to pass my.view.php as
$foo->render('my', ['data'=>'foo']);
/**
* Set the file extension for the compiled files.
* Including the leading dot for the extension is $file_extension ): self{}
$provider->set_file_extension('.view_cache');
/**
* Sets the esc function.
*
* @param callable(mixed):string $esc
* @return self
*/
public function set_esc_function( callable $esc ): self {}
$provider->set_esc_function('esc_attr');
// None static
$this->view->engine()->some_method($data);
// As static
BladeOne_Provider::some_method($data);
// Using the App's View method to access none static methods on the fly.
App::view()->engine()->some_method($data);
// @file /views/template.blade.php
// Using the $this->view_models() method.
{!! $this->view_modes(new View_Model('path.template', ['key' => 'value'])) !!}
// Using the directive
@viewModel(new View_Model('path.template', ['key' => 'value']))
// @file /views/template.blade.php
// Using the $this->component() method.
{!! $this->component(new SomeComponent()) !!}
// Using the directive
@component(new SomeComponent())
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.