PHP Class Google\Cloud\Dev\Snippet\Parser\Snippet

Inheritance: implements JsonSerializable
Datei anzeigen Open project: GoogleCloudPlatform/gcloud-php

Public Methods

Method Description
__construct ( string $identifier, array $config = [] ) Create a snippet
addLocal ( string $name, mixed $value ) : void Add a local variable to make available in the snippet execution scope.
addUse ( string $name ) : void Add a use statement for a class.
content ( ) : string The snippet content.
file ( ) : string The file in which the snippet is found.
identifier ( ) : string A unique identifier for the snippet.
index ( ) : integer The Snippet Index
insertAfterLine ( integer $line, string $content ) : void Inject new code after a given line.
invoke ( $returnVar = null ) : mixed Eval the snippet and return the result.
jsonSerialize ( )
line ( ) : integer The line number where the snippet's method or class is declared.
name ( ) : string The snippet name
regexReplace ( string $pattern, string $new ) : void Find something with a regex and replace it.
replace ( string $old, string $new ) : void Replace a string in the snippet with a new one.
setLine ( integer $line, string $content ) : void Replace a line with new code.

Private Methods

Method Description
createReturnVar ( $returnVar )

Method Details

__construct() public method

Create a snippet
public __construct ( string $identifier, array $config = [] )
$identifier string The snippet ID
$config array The snippet config

addLocal() public method

Add a local variable to make available in the snippet execution scope.
public addLocal ( string $name, mixed $value ) : void
$name string The variable name
$value mixed The variable value
return void

addUse() public method

Add a use statement for a class.
public addUse ( string $name ) : void
$name string The class name to import.
return void

content() public method

The snippet content.
public content ( ) : string
return string

file() public method

The file in which the snippet is found.
public file ( ) : string
return string

identifier() public method

This identifier is deterministic and will remain constant unless the snippet is modified or moved.
public identifier ( ) : string
return string

index() public method

The Snippet Index
public index ( ) : integer
return integer

insertAfterLine() public method

Hopefully this is obvious, but be careful using this, and only use it when no other feasible options present themselves. It's pretty easy to make your test useless when you're modifying the thing you are trying to test. This is provided for cases when a snippet relies on a global, or on something else which can not be overridden or mocked.
public insertAfterLine ( integer $line, string $content ) : void
$line integer The line number (0-indexed) to write in after.
$content string The PHP code to inject.
return void

invoke() public method

Eval the snippet and return the result.
public invoke ( $returnVar = null ) : mixed
return mixed

jsonSerialize() public method

public jsonSerialize ( )

line() public method

Note that this is NOT the line number where the snippet is declared. It indicates the method or class which the snippet annotates.
public line ( ) : integer
return integer

name() public method

The snippet name
public name ( ) : string
return string

regexReplace() public method

Hopefully this is obvious, but be careful using this, and only use it when no other feasible options present themselves. It's pretty easy to make your test useless when you're modifying the thing you are trying to test. This is provided for cases when a snippet relies on a global, or on something else which can not be overridden or mocked.
public regexReplace ( string $pattern, string $new ) : void
$pattern string The regex pattern to search for.
$new string The new string to insert.
return void

replace() public method

Hopefully this is obvious, but be careful using this, and only use it when no other feasible options present themselves. It's pretty easy to make your test useless when you're modifying the thing you are trying to test. This is provided for cases when a snippet relies on a global, or on something else which can not be overridden or mocked.
public replace ( string $old, string $new ) : void
$old string The string to be replaced.
$new string The new string to insert.
return void

setLine() public method

Hopefully this is obvious, but be careful using this, and only use it when no other feasible options present themselves. It's pretty easy to make your test useless when you're overwriting the thing you are trying to test. This is provided for cases when a snippet relies on a global, or on something else which can not be overridden or mocked.
public setLine ( integer $line, string $content ) : void
$line integer The line number (0-indexed) to replace.
$content string The PHP code to inject.
return void