PHP code example of kappa / placeholder-processor

1. Go to this page and download the library: Download kappa/placeholder-processor 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/ */

    

kappa / placeholder-processor example snippets



use Kappa\PlaceholderProcessor\PlaceholderProcessor;

class MySuperPlaceholderProcessor extends PlaceholderProcessor
{
	private $db;
	
	public function __construct(Database $db) 
	{
	    $this->db = $db;
	}
	
	public function configure()
	{
		$this->setName("mySuperPlaceholderProcessor");
		$this->setExternalSources(['user_id']);
	}

	public function run(array $sources = [])
	{
		return $this->db->find('users', $sources['user_id'])->getName();
	}
}


$textFormatter = new TextFormatter([
    new MySuperPlaceholderProcessor()
]);

$textFormatter = new TextFormatter();
$textFormatter->setProcessors([
  new MySuperPlaceholderProcessor()
]);

public function __construct(TextFormatter $textFormatter) {
    
}

$textFormatter = new TextFormatter([
    new mySuperPlaceholderProcessor($db)
]);

$output = $textFormatter->format('Hello %mySuperPlaceholderProcessor%, %foo%', ['user_id' => 1]);