PHP code example of localheinz / token

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

    

localheinz / token example snippets


use Localheinz\Token\Sequence;

$source = <<<'PHP'


class Foo
{
    /**
     * @param Bar $bar
     */
    public function __construct(Bar $bar)
    {
        $this->bar = $bar;
    }
}
PHP;

$sequence = Sequence::fromSource($source);

use Localheinz\Token\Token;

/** @var Token $token */
$token = $sequence->at(10);

var_dump($token->index()); // 10
var_dump($token->isType(T_PUBLIC)); // true
var_dump($token->isContent('public')); // true

use Localheinz\Token\Token;

/** @var Token $before */
$before = $sequence->significantBefore(10);

var_dump($before->index()); // 6
var_dump($before->isType(T_STRING)); // true
var_dump($before->isContent('{')); // true

use Localheinz\Token\Token;

/** @var Token $after */
$after = $sequence->significantAfter(10);

var_dump($after->index()); // 12
var_dump($after->isType(T_FUNCTION)); // true
var_dump($after->isContent('function')); // true