Pink-Crab / Perique-BladeOne-Provider

A BladeOne Provider for the PinkCrab Renderable Interface.
0 stars 0 forks source link

Extend functions in wrapper #5

Closed gin0115 closed 3 years ago

gin0115 commented 3 years ago

In order to make the config a little nicer, i have added the following methods to custom child class.

/**
 * Sets if piping is enabled in templates.
 *
 * @param bool $bool
 * @return self
 */
public function allow_pipe( bool $bool = true ): self {
    static::$blade->pipeEnable = $bool;
    return $this;
}

/**
 * Register a handler for custom directives.
 *
 * @param string   $name
 * @param callable $handler
 * @return self
 */
public function directive( string $name, callable $handler ): self {
    static::$blade->directive( $name, $handler );
    return $this;
}

/**
 * Register a handler for custom directives for run at runtime
 *
 * @param string   $name
 * @param callable $handler
 * @return self
 */
public function directiveRT( $name, callable $handler ): self {
    static::$blade->directiveRT( $name, $handler );
    return $this;
}

/**
 * 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.
 */
public function addInclude( $view, $alias = null ) {
    static::$blade->addInclude( $view, $alias );
    return $this;
}

/**
 * Define a class with a namespace
 *
 * @param string $aliasName
 * @param string $classWithNS
 */
public function addAliasClasses( $aliasName, $classWithNS ) {
    static::$blade->addAliasClasses( $aliasName, $classWithNS );
    return $this;
}

/**
 * Set the compile mode
 *
 * @param $mode int=[self::MODE_AUTO,self::MODE_DEBUG,self::MODE_FAST,self::MODE_SLOW][$i]
 * @return void
 */
public function setMode( int $mode ): self {
    static::$blade->mode = $mode;
    return $this;
}

/**
 * Adds a global variable. If <b>$varname</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 $varname It is the name of the variable or it is an associative array
 * @param mixed        $value
 * @return $this
 */
public function share( $varname, $value = null ): self {
    static::$blade->share( $varname, $value );
    return $this;
}

/**
 * Sets the function used for resolving classes with inject.
 *
 * @param callable $function
 * @return $this
 */
public function setInjectResolver( callable $function ): self {
    static::$blade->setInjectResolver( $function );
    return $this;
}

/**
 * Set the file extension for the template files.
 * It must includes the leading dot e.g. .blade.php
 *
 * @param string $fileExtension Example: .prefix.ext
 * @return $this
 */
public function setFileExtension( $fileExtension ): self {
    static::$blade->setFileExtension( $fileExtension );
    return $this;
}

/**
 * Set the file extension for the compiled files.
 * Including the leading dot for the extension is required, e.g. .bladec
 *
 * @param $fileExtension
 * @return $this
 */
public function setCompiledExtension( $fileExtension ): self {
    static::$blade->setCompiledExtension( $fileExtension );
    return $this;
}