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

Inheritance: implements JsonSerializable
Afficher le fichier Open project: GoogleCloudPlatform/gcloud-php

Méthodes publiques

Méthode 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

Méthode Description
createReturnVar ( $returnVar )

Method Details

__construct() public méthode

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

addLocal() public méthode

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
Résultat void

addUse() public méthode

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

content() public méthode

The snippet content.
public content ( ) : string
Résultat string

file() public méthode

The file in which the snippet is found.
public file ( ) : string
Résultat string

identifier() public méthode

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

index() public méthode

The Snippet Index
public index ( ) : integer
Résultat integer

insertAfterLine() public méthode

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.
Résultat void

invoke() public méthode

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

jsonSerialize() public méthode

public jsonSerialize ( )

line() public méthode

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
Résultat integer

name() public méthode

The snippet name
public name ( ) : string
Résultat string

regexReplace() public méthode

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.
Résultat void

replace() public méthode

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.
Résultat void

setLine() public méthode

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.
Résultat void