Skip to content

[Feature][Long-Term] Interception of methods in the internal PHP classes #188

Open
@lisachenko

Description

@lisachenko

Interception of methods in the internal PHP classes is the most complex one, however, it is required for special cases, for example, to intercept mysql->query() invocation:

class MysqliQueryOperationCollectionAspect implements Aspect {

    /**
     * @param MethodInvocation $invocation Invocation
     * @Around(execution(public mysqli->query(*))
     * @return mixed
     */
    public function aroundQueryMethod(MethodInvocation $invocation) {
        $method = $invocation->getMethod();
        $args = $invocation->getArguments();
        $query = $args[1];
        if ($this->logger->isTraceEnabled()) {
            $this->logger->trace($method->getName().'('.$query.')');
        }

        try {
            $result = $invocation->proceed();
            return $result;
        } catch(Exception $e) {
            if ($this->logger->isTraceEnabled()) {
                $this->logger->trace($method->getName().'('.$query.') '.get_class($e).':' .$e->getMessage());
            }
            throw $e;
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions