PHP Class Zephir\Compiler

Main compiler
Show file Open project: phalcon/zephir Class Usage Examples

Public Properties

Property Type Description
$backend BaseBackend
$functionDefinitions zephir\FunctionDefinition[]
$parserCompiled

Protected Properties

Property Type Description
$anonymousFiles array | string[]
$compiledFiles array | string[]
$config zephir\Config
$constants
$currentVersion string
$definitions ClassDefinition[]
$externalDependencies array External dependencies
$extraFiles array
$fcallManager Zephir\Backends\ZendEngine3\FcallManager | Zephir\Backends\ZendEngine2\FcallManager
$files CompilerFile[]
$globals array Extension globals
$internalDefinitions ReflectionClass[]
$internalInitializers array Additional initializer code used for static property initialization
$loadedPrototypes boolean
$logger zephir\Logger
$stringManager zephir\StringsManager

Public Methods

Method Description
__construct ( zephir\Config $config, zephir\Logger $logger, BaseBackend $backend ) Compiler constructor
addClassDefinition ( CompilerFileAnonymous $file, ClassDefinition $classDefinition ) Inserts an anonymous class definition in the compiler
addExternalDependency ( string $namespace, string $location ) Adds an external dependency to the compiler
addFunction ( zephir\FunctionDefinition $func, array $statement = null ) Adds a function to the function definitions
api ( Zephir\Commands\CommandInterface $command, boolean $fromGenerate = false ) Generate a HTML API
build ( Zephir\Commands\CommandInterface $command ) Compiles and installs the extension
buildDev ( Zephir\Commands\CommandInterface $command ) Compiles and installs the extension in development mode (debug symbols and no optimizations)
calculateDependencies ( $files, $_dependency = null )
checkIfPhpized ( ) : boolean Check if the project must be phpized again
clean ( Zephir\Commands\CommandInterface $command ) Clean the extension directory
compile ( Zephir\Commands\CommandInterface $command, boolean $development = false ) Compiles the extension without installing it
compileParser ( ) Compile the parser PHP extension
createConfigFiles ( string $project ) : boolean Create config.m4 and config.w32 for the extension
createProjectFiles ( string $project ) : boolean Create project.c and project.h according to the current extension
fullClean ( Zephir\Commands\CommandInterface $command ) Clean the extension directory
generate ( Zephir\Commands\CommandInterface $command ) : boolean Generates the C sources from Zephir without compiling them
generateFunctionInformation ( )
generatePackageDependenciesM4 ( $contentM4 ) : string Generate package-dependencies config for m4
getClassDefinition ( string $className ) : ClassDefinition | false Returns class the class definition from a given class name
getConfig ( ) : zephir\Config Returns the internal config
getConstant ( string $name ) Returns a Zephir Constant by its name
getCurrentVersion ( ) : string Returns the current version + the ident if available
getExtensionGlobal ( string $name ) : boolean Returns a extension global by its name
getFileSystem ( ) : HardDisk Returns the internal filesystem handler
getGccFlags ( boolean $development = false ) : string Returns GCC flags for current compilation
getInternalClassDefinition ( string $className ) : ClassDefinition Returns class the class definition from a given class name
getLogger ( ) : zephir\Logger Returns the internal logger
getPhpIncludeDirs ( ) : string Returns the php include directories returned by php-config
getShortPath ( string $path ) : string Returns a short path
getShortUserPath ( string $path ) : string Returns a short user path
init ( Zephir\Commands\CommandInterface $command ) Initializes a Zephir extension
install ( Zephir\Commands\CommandInterface $command, boolean $development = false ) Compiles and installs the extension
isBundledClass ( string $className ) : boolean Allows to check if a class is part of PHP
isBundledInterface ( string $className ) : boolean Allows to check if a interface is part of PHP
isClass ( string $className ) : boolean Allows to check if a class is part of the compiled extension
isConstant ( string $name ) : boolean Checks if $name is a Zephir constant
isExtensionGlobal ( string $name ) : boolean Checks if a specific extension global is defined
isInterface ( string $className ) : boolean Allows to check if an interface is part of the compiled extension
loadExternalClass ( string $className, string $location ) : boolean Loads a class definition in an external dependency
preCompileHeaders ( ) Pre-compile headers to speed up compilation
processCodeInjection ( array $entries ) : array Process extension code injection
processExtensionGlobals ( string $namespace ) : array Process extension globals
processExtensionInfo ( ) : string Generates phpinfo() sections showing information about the extension
setExtensionGlobals ( array $globals ) Sets extensions globals
stubs ( Zephir\Commands\CommandInterface $command, boolean $fromGenerate = false ) Generate IDE stubs
test ( Zephir\Commands\CommandInterface $command ) Run tests

Protected Methods

Method Description
checkDirectory ( ) : string Checks if the current directory is a valid Zephir project
checkKernelFile ( string $src, string $dst ) : boolean Checks if a file must be copied
checkKernelFiles ( ) : boolean Checks which files in the base kernel must be copied
checkRequires ( ) Check require extensions orther when build your extension
getGccVersion ( ) : string Returns current GCC version
loadConstantsSources ( array $constantsSources ) Registers C-constants as PHP constants from a C-file
preCompile ( string $filePath ) Pre-compiles classes creating a CompilerFile definition
processAddSources ( array $sources, string $project ) : array Process config.w32 sections
recursiveDeletePath ( string $path, string $mask ) Recursively deletes files in a specified location
recursivePreCompile ( string $path ) Recursively pre-compiles all sources found in the given path
recursiveProcess ( $src, $dest, string $pattern = null, mixed $callback = "copy" ) : boolean Copies the base kernel to the extension destination

Method Details

__construct() public method

Compiler constructor
public __construct ( zephir\Config $config, zephir\Logger $logger, BaseBackend $backend )
$config zephir\Config
$logger zephir\Logger
$backend BaseBackend

addClassDefinition() public method

Inserts an anonymous class definition in the compiler
public addClassDefinition ( CompilerFileAnonymous $file, ClassDefinition $classDefinition )
$file CompilerFileAnonymous
$classDefinition ClassDefinition

addExternalDependency() public method

Adds an external dependency to the compiler
public addExternalDependency ( string $namespace, string $location )
$namespace string
$location string

addFunction() public method

Adds a function to the function definitions
public addFunction ( zephir\FunctionDefinition $func, array $statement = null )
$func zephir\FunctionDefinition
$statement array

api() public method

Generate a HTML API
public api ( Zephir\Commands\CommandInterface $command, boolean $fromGenerate = false )
$command Zephir\Commands\CommandInterface
$fromGenerate boolean

build() public method

Compiles and installs the extension
public build ( Zephir\Commands\CommandInterface $command )
$command Zephir\Commands\CommandInterface

buildDev() public method

Compiles and installs the extension in development mode (debug symbols and no optimizations)
public buildDev ( Zephir\Commands\CommandInterface $command )
$command Zephir\Commands\CommandInterface

calculateDependencies() public method

public calculateDependencies ( $files, $_dependency = null )

checkDirectory() protected method

Checks if the current directory is a valid Zephir project
protected checkDirectory ( ) : string
return string

checkIfPhpized() public method

Check if the project must be phpized again
public checkIfPhpized ( ) : boolean
return boolean

checkKernelFile() protected method

Checks if a file must be copied
protected checkKernelFile ( string $src, string $dst ) : boolean
$src string
$dst string
return boolean

checkKernelFiles() protected method

Checks which files in the base kernel must be copied
protected checkKernelFiles ( ) : boolean
return boolean

checkRequires() protected method

Check require extensions orther when build your extension
protected checkRequires ( )

clean() public method

Clean the extension directory
public clean ( Zephir\Commands\CommandInterface $command )
$command Zephir\Commands\CommandInterface

compile() public method

Compiles the extension without installing it
public compile ( Zephir\Commands\CommandInterface $command, boolean $development = false )
$command Zephir\Commands\CommandInterface
$development boolean

compileParser() public method

Compile the parser PHP extension
public compileParser ( )

createConfigFiles() public method

Create config.m4 and config.w32 for the extension
public createConfigFiles ( string $project ) : boolean
$project string
return boolean true if need to run configure TODO: move this to backend?

createProjectFiles() public method

Create project.c and project.h according to the current extension
public createProjectFiles ( string $project ) : boolean
$project string
return boolean TODO: Move the part of the logic which depends on templates (backend-specific) to backend?

fullClean() public method

Clean the extension directory
public fullClean ( Zephir\Commands\CommandInterface $command )
$command Zephir\Commands\CommandInterface

generate() public method

Generates the C sources from Zephir without compiling them
public generate ( Zephir\Commands\CommandInterface $command ) : boolean
$command Zephir\Commands\CommandInterface
return boolean

generateFunctionInformation() public method

generatePackageDependenciesM4() public method

Generate package-dependencies config for m4
public generatePackageDependenciesM4 ( $contentM4 ) : string
$contentM4
return string TODO: Move the template depending part to backend?

getClassDefinition() public method

Returns class the class definition from a given class name
public getClassDefinition ( string $className ) : ClassDefinition | false
$className string
return ClassDefinition | false returns false if no class definition is found

getConfig() public method

Returns the internal config
public getConfig ( ) : zephir\Config
return zephir\Config

getConstant() public method

Returns a Zephir Constant by its name
public getConstant ( string $name )
$name string

getCurrentVersion() public static method

Returns the current version + the ident if available
public static getCurrentVersion ( ) : string
return string

getExtensionGlobal() public method

Returns a extension global by its name
public getExtensionGlobal ( string $name ) : boolean
$name string
return boolean

getFileSystem() public method

Returns the internal filesystem handler
public getFileSystem ( ) : HardDisk
return Zephir\FileSystem\HardDisk

getGccFlags() public method

Returns GCC flags for current compilation
public getGccFlags ( boolean $development = false ) : string
$development boolean
return string

getGccVersion() protected method

Returns current GCC version
protected getGccVersion ( ) : string
return string

getInternalClassDefinition() public method

Returns class the class definition from a given class name
public getInternalClassDefinition ( string $className ) : ClassDefinition
$className string
return ClassDefinition

getLogger() public method

Returns the internal logger
public getLogger ( ) : zephir\Logger
return zephir\Logger

getPhpIncludeDirs() public method

Returns the php include directories returned by php-config
public getPhpIncludeDirs ( ) : string
return string

getShortPath() public static method

Returns a short path
public static getShortPath ( string $path ) : string
$path string
return string

getShortUserPath() public static method

Returns a short user path
public static getShortUserPath ( string $path ) : string
$path string
return string

init() public method

Initializes a Zephir extension
public init ( Zephir\Commands\CommandInterface $command )
$command Zephir\Commands\CommandInterface

install() public method

Compiles and installs the extension
public install ( Zephir\Commands\CommandInterface $command, boolean $development = false )
$command Zephir\Commands\CommandInterface
$development boolean

isBundledClass() public method

Allows to check if a class is part of PHP
public isBundledClass ( string $className ) : boolean
$className string
return boolean

isBundledInterface() public method

Allows to check if a interface is part of PHP
public isBundledInterface ( string $className ) : boolean
$className string
return boolean

isClass() public method

Allows to check if a class is part of the compiled extension
public isClass ( string $className ) : boolean
$className string
return boolean

isConstant() public method

Checks if $name is a Zephir constant
public isConstant ( string $name ) : boolean
$name string
return boolean

isExtensionGlobal() public method

Checks if a specific extension global is defined
public isExtensionGlobal ( string $name ) : boolean
$name string
return boolean

isInterface() public method

Allows to check if an interface is part of the compiled extension
public isInterface ( string $className ) : boolean
$className string
return boolean

loadConstantsSources() protected method

Registers C-constants as PHP constants from a C-file
protected loadConstantsSources ( array $constantsSources )
$constantsSources array

loadExternalClass() public method

Loads a class definition in an external dependency
public loadExternalClass ( string $className, string $location ) : boolean
$className string
$location string
return boolean

preCompile() protected method

Pre-compiles classes creating a CompilerFile definition
protected preCompile ( string $filePath )
$filePath string

preCompileHeaders() public method

Pre-compile headers to speed up compilation
public preCompileHeaders ( )

processAddSources() protected method

Process config.w32 sections
protected processAddSources ( array $sources, string $project ) : array
$sources array
$project string
return array

processCodeInjection() public method

Process extension code injection
public processCodeInjection ( array $entries ) : array
$entries array
return array

processExtensionGlobals() public method

Process extension globals
public processExtensionGlobals ( string $namespace ) : array
$namespace string
return array

processExtensionInfo() public method

Generates phpinfo() sections showing information about the extension
public processExtensionInfo ( ) : string
return string

recursiveDeletePath() protected method

Recursively deletes files in a specified location
protected recursiveDeletePath ( string $path, string $mask )
$path string
$mask string

recursivePreCompile() protected method

Recursively pre-compiles all sources found in the given path
protected recursivePreCompile ( string $path )
$path string

recursiveProcess() protected method

Copies the base kernel to the extension destination
protected recursiveProcess ( $src, $dest, string $pattern = null, mixed $callback = "copy" ) : boolean
$src
$dest
$pattern string
$callback mixed
return boolean

setExtensionGlobals() public method

Sets extensions globals
public setExtensionGlobals ( array $globals )
$globals array

stubs() public method

Generate IDE stubs
public stubs ( Zephir\Commands\CommandInterface $command, boolean $fromGenerate = false )
$command Zephir\Commands\CommandInterface
$fromGenerate boolean

test() public method

Run tests
public test ( Zephir\Commands\CommandInterface $command )
$command Zephir\Commands\CommandInterface

Property Details

$anonymousFiles protected property

protected array|string[] $anonymousFiles
return array | string[]

$backend public property

public BaseBackend,zephir $backend
return BaseBackend

$compiledFiles protected property

protected array|string[] $compiledFiles
return array | string[]

$config protected property

protected Config,zephir $config
return zephir\Config

$constants protected property

protected $constants

$currentVersion protected static property

protected static string $currentVersion
return string

$definitions protected property

protected ClassDefinition[],zephir $definitions
return ClassDefinition[]

$externalDependencies protected property

External dependencies
protected array $externalDependencies
return array

$extraFiles protected property

protected array $extraFiles
return array

$fcallManager protected property

protected FcallManager,Zephir\Backends\ZendEngine3|FcallManager,Zephir\Backends\ZendEngine2 $fcallManager
return Zephir\Backends\ZendEngine3\FcallManager | Zephir\Backends\ZendEngine2\FcallManager

$files protected property

protected CompilerFile[],zephir $files
return CompilerFile[]

$functionDefinitions public property

public FunctionDefinition[],zephir $functionDefinitions
return zephir\FunctionDefinition[]

$globals protected property

Extension globals
protected array $globals
return array

$internalDefinitions protected static property

protected static ReflectionClass[] $internalDefinitions
return ReflectionClass[]

$internalInitializers protected property

Additional initializer code used for static property initialization
protected array $internalInitializers
return array

$loadedPrototypes protected static property

protected static bool $loadedPrototypes
return boolean

$logger protected property

protected Logger,zephir $logger
return zephir\Logger

$parserCompiled public property

public $parserCompiled

$stringManager protected property

protected StringsManager,zephir $stringManager
return zephir\StringsManager