src/Isolator.php
public function isolatePHP(string $source): string
    {
        $phpBlock = false;

        $isolated = '';
        foreach (token_get_all($source) as $token) {
            if ($this->isOpenTag($token)) {
                $phpBlock = $token[1];

                continue;
            }

            if ($this->isCloseTag($token)) {
                $blockID = $this->uniqueID();

                $this->phpBlocks[$blockID] = $phpBlock . $token[1];
                $isolated .= $this->placeholder($blockID);

                $phpBlock = '';

                continue;
            }

            $tokenContent = is_array($token) ? $token[1] : $token;

            if (!empty($phpBlock)) {
                $phpBlock .= $tokenContent;
            } else {
                $isolated .= $tokenContent;
            }
        }

        return $isolated;
    }
public function isolatePHP(string $source): string
    {
        $phpBlock = false;

        $isolated = '';
        foreach (token_get_all($source) as $token) {
            if ($this->isOpenTag($token)) {
                $phpBlock = $token[1];

                continue;
            }

            if ($this->isCloseTag($token)) {
                $blockID = $this->uniqueID();

                $this->phpBlocks[$blockID] = $phpBlock . $token[1];
                $isolated .= $this->placeholder($blockID);

                $phpBlock = '';

                continue;
            }

            $tokenContent = is_array($token) ? $token[1] : $token;

            if (!empty($phpBlock)) {
                $phpBlock .= $tokenContent;
            } else {
                $isolated .= $tokenContent;
            }
        }

        return $isolated;
    }
public function isolatePHP ( string $ source ) : string { $ phpBlock = false ; $ isolated = '' ; foreach ( token_get_all ( $ source ) as $ token ) { if ( $ this -> isOpenTag ( $ token ) ) { $ phpBlock = $ token [ 1 ] ; continue ; } if ( $ this -> isCloseTag ( $ token ) ) { $ blockID = $ this -> uniqueID ( ) ; $ this -> phpBlocks [ $ blockID ] = $ phpBlock . $ token [ 1 ] ; $ isolated .= $ this -> placeholder ( $ blockID ) ; $ phpBlock = '' ; continue ; } $ tokenContent = is_array ( $ token ) ? $ token [ 1 ] : $ token ; if ( ! empty ( $ phpBlock ) ) { $ phpBlock .= $ tokenContent ; } else { $ isolated .= $ tokenContent ; } } return $ isolated ; }
Isolates all returned PHP blocks with a defined pattern. Method uses
token_get_all function. Resulted src have all php blocks replaced
with non executable placeholder.

@param string $source

@return string
Isolates all returned PHP blocks with a defined pattern . Method uses token_get_all function . Resulted src have all php blocks replaced with non executable placeholder .