Zephir\FunctionCall::optimize PHP Method

optimize() protected method

Tries to find specific an specialized optimizer for function calls
protected optimize ( string $funcName, array $expression, Call $call, zephir\CompilationContext $compilationContext )
$funcName string
$expression array
$call Call
$compilationContext zephir\CompilationContext
    protected function optimize($funcName, array $expression, Call $call, CompilationContext $compilationContext)
    {
        $optimizer = false;
        /**
         * Check if the optimizer is already cached
         */
        if (!isset(self::$_optimizers[$funcName])) {
            $camelizeFunctionName = Utils::camelize($funcName);
            /**
             * Check every optimizer directory for an optimizer
             */
            foreach (self::$_optimizerDirectories as $directory) {
                $path = $directory . DIRECTORY_SEPARATOR . $camelizeFunctionName . 'Optimizer.php';
                if (file_exists($path)) {
                    require_once $path;
                    $className = 'Zephir\\Optimizers\\FunctionCall\\' . $camelizeFunctionName . 'Optimizer';
                    if (!class_exists($className, false)) {
                        throw new \Exception('Class ' . $className . ' cannot be loaded');
                    }
                    $optimizer = new $className();
                    if (!$optimizer instanceof OptimizerAbstract) {
                        throw new \Exception('Class ' . $className . ' must be instance of OptimizerAbstract');
                    }
                    break;
                }
            }
            self::$_optimizers[$funcName] = $optimizer;
        } else {
            $optimizer = self::$_optimizers[$funcName];
        }
        if ($optimizer) {
            return $optimizer->optimize($expression, $call, $compilationContext);
        }
        return false;
    }