Go\Instrument\Transformer\WeavingTransformer::processSingleClass PHP Method

processSingleClass() private method

Performs weaving of single class if needed
private processSingleClass ( array $advisors, StreamMetaData $metadata, ReflectionClas\ReflectionClass $class, integer &$lineOffset ) : boolean
$advisors array
$metadata StreamMetaData Source stream information
$class ReflectionClas\ReflectionClass Instance of class to analyze
$lineOffset integer Current offset, will be updated to store the last position
return boolean True if was class processed, false otherwise
    private function processSingleClass(array $advisors, StreamMetaData $metadata, ReflectionClass $class, &$lineOffset)
    {
        $advices = $this->adviceMatcher->getAdvicesForClass($class, $advisors);
        if (empty($advices)) {
            // Fast return if there aren't any advices for that class
            return false;
        }
        // Sort advices in advance to keep the correct order in cache
        foreach ($advices as &$typeAdvices) {
            foreach ($typeAdvices as &$joinpointAdvices) {
                if (is_array($joinpointAdvices)) {
                    $joinpointAdvices = AbstractJoinpoint::sortAdvices($joinpointAdvices);
                }
            }
        }
        // Prepare new parent name
        $newParentName = $class->getShortName() . AspectContainer::AOP_PROXIED_SUFFIX;
        // Replace original class name with new
        $metadata->source = $this->adjustOriginalClass($class, $metadata->source, $newParentName);
        // Prepare child Aop proxy
        $child = $class->isTrait() ? new TraitProxy($class, $advices) : new ClassProxy($class, $advices);
        // Set new parent name instead of original
        $child->setParentName($newParentName);
        $contentToInclude = $this->saveProxyToCache($class, $child);
        // Add child to source
        $lastLine = $class->getEndLine() + $lineOffset;
        // returns the last line of class
        $dataArray = explode("\n", $metadata->source);
        $currentClassArray = array_splice($dataArray, 0, $lastLine);
        $childClassArray = explode("\n", $contentToInclude);
        $lineOffset += count($childClassArray) + 2;
        // returns LoC for child class + 2 blank lines
        $dataArray = array_merge($currentClassArray, array(''), $childClassArray, array(''), $dataArray);
        $metadata->source = implode("\n", $dataArray);
        return true;
    }