PHP Class Piwik\API\Proxy

Proxy receives all the API calls requests via call() and forwards them to the right object, with the parameters in the right order. It will also log the performance of API calls (time spent, parameter values, etc.) if logger available
Inheritance: extends Piwik\Singleton
Show file Open project: piwik/piwik Class Usage Examples

Protected Properties

Property Type Description
$alreadyRegistered array of already registered plugins names

Public Methods

Method Description
__construct ( )
buildApiActionName ( $pluginName, $apiAction )
call ( string $className, string $methodName, array $parametersRequest ) : mixed | null Will execute $className->$methodName($parametersValues) If any error is detected (wrong number of parameters, method not found, class not found, etc.) it will throw an exception
getCountRegisteredClasses ( ) : integer Returns number of classes already loaded
getMetadata ( ) : array Returns array containing reflection meta data for all the loaded classes eg. number of parameters, method names, etc.
getModuleNameFromClassName ( string $className ) : string Returns the 'moduleName' part of '\\Piwik\\Plugins\\moduleName\\API'
getParametersList ( string $class, string $name ) : array Returns the parameters names and default values for the method $name of the class $class
isDeprecatedMethod ( $class, $methodName ) Check if given method name is deprecated or not.
isExistingApiAction ( $pluginName, $apiAction )
registerClass ( string $className ) Registers the API information of a given module.
setHideIgnoredFunctions ( boolean $hideIgnoredFunctions ) Sets whether to hide '@ignore'd functions from method metadata or not.
shouldHideAPIMethod ( $docComment ) : boolean

Protected Methods

Method Description
checkIfMethodIsAvailable ( ReflectionMethod $method ) : boolean

Private Methods

Method Description
checkClassIsSingleton ( string $className ) Checks that the class is a Singleton (presence of the getInstance() method)
checkMethodExists ( string $className, string $methodName ) Checks that the method exists in the class
getRequestParametersArray ( array $requiredParameters, array $parametersRequest ) : array Returns an array containing the values of the parameters to pass to the method to call
includeApiFile ( string $fileName ) Includes the class API by looking up plugins/xxx/API.php
isMethodAvailable ( string $className, string $methodName ) : boolean Returns true if the method is found in the API of the given class name.
loadMethodMetadata ( string $class, ReflectionMethod $method )
setDocumentation ( ReflectionClass $rClass, string $className ) Will be displayed in the API page

Method Details

__construct() public method

public __construct ( )

buildApiActionName() public method

public buildApiActionName ( $pluginName, $apiAction )

call() public method

It also logs the API calls, with the parameters values, the returned value, the performance, etc. You can enable logging in config/global.ini.php (log_api_call)
public call ( string $className, string $methodName, array $parametersRequest ) : mixed | null
$className string The class name (eg. API)
$methodName string The method name
$parametersRequest array The parameters pairs (name=>value)
return mixed | null

checkIfMethodIsAvailable() protected method

protected checkIfMethodIsAvailable ( ReflectionMethod $method ) : boolean
$method ReflectionMethod
return boolean

getCountRegisteredClasses() public method

Returns number of classes already loaded

getMetadata() public method

Returns array containing reflection meta data for all the loaded classes eg. number of parameters, method names, etc.
public getMetadata ( ) : array
return array

getModuleNameFromClassName() public method

Returns the 'moduleName' part of '\\Piwik\\Plugins\\moduleName\\API'
public getModuleNameFromClassName ( string $className ) : string
$className string "API"
return string "Referrers"

getParametersList() public method

Returns the parameters names and default values for the method $name of the class $class
public getParametersList ( string $class, string $name ) : array
$class string The class name
$name string The method name
return array Format array( 'testParameter' => null, // no default value 'life' => 42, // default value = 42 'date' => 'yesterday', );

isDeprecatedMethod() public method

Check if given method name is deprecated or not.
public isDeprecatedMethod ( $class, $methodName )

isExistingApiAction() public method

public isExistingApiAction ( $pluginName, $apiAction )

registerClass() public method

The module to be registered must be - a singleton (providing a getInstance() method) - the API file must be located in plugins/ModuleName/API.php for example plugins/Referrers/API.php The method will introspect the methods, their parameters, etc.
public registerClass ( string $className )
$className string ModuleName eg. "API"

setHideIgnoredFunctions() public method

Sets whether to hide '@ignore'd functions from method metadata or not.
public setHideIgnoredFunctions ( boolean $hideIgnoredFunctions )
$hideIgnoredFunctions boolean

shouldHideAPIMethod() public method

public shouldHideAPIMethod ( $docComment ) : boolean
$docComment
return boolean

Property Details

$alreadyRegistered protected property

array of already registered plugins names
protected $alreadyRegistered