src/phpDocumentor/Compiler/Linker/Linker.php
public function substitute($item, $container = null)
    {
        $result = null;

        if (is_string($item)) {
            $result = $this->findAlias($item, $container);
        } elseif (is_array($item) || ($item instanceof \Traversable && ! $item instanceof ProjectInterface)) {
            $isModified = false;
            foreach ($item as $key => $element) {
                $isModified = true;

                $element = $this->substitute($element, $container);
                if ($element !== null) {
                    $item[$key] = $element;
                }
            }
            if ($isModified) {
                $result = $item;
            }
        } elseif (is_object($item) && $item instanceof UnknownTypeDescriptor) {
            $alias  = $this->findAlias($item->getName());
            $result = $alias ?: $item;
        } elseif (is_object($item)) {
            $hash = spl_object_hash($item);
            if (isset($this->processedObjects[$hash])) {
                // if analyzed; just return
                return null;
            }

            $newContainer = ($this->isDescriptorContainer($item)) ? $item : $container;

            $this->processedObjects[$hash] = true;

            $objectClassName = get_class($item);
            $fieldNames = isset($this->substitutions[$objectClassName])
                ? $this->substitutions[$objectClassName]
                : array();

            foreach ($fieldNames as $fieldName) {
                $fieldValue = $this->findFieldValue($item, $fieldName);
                $response = $this->substitute($fieldValue, $newContainer);

                // if the returned response is not an object it must be grafted on the calling object
                if ($response !== null) {
                    $setter = 'set'.ucfirst($fieldName);
                    $item->$setter($response);
                }
            }
        }

        return $result;
    }
public function substitute($item, $container = null)
    {
        $result = null;

        if (is_string($item)) {
            $result = $this->findAlias($item, $container);
        } elseif (is_array($item) || ($item instanceof \Traversable && ! $item instanceof ProjectInterface)) {
            $isModified = false;
            foreach ($item as $key => $element) {
                $isModified = true;

                $element = $this->substitute($element, $container);
                if ($element !== null) {
                    $item[$key] = $element;
                }
            }
            if ($isModified) {
                $result = $item;
            }
        } elseif (is_object($item) && $item instanceof UnknownTypeDescriptor) {
            $alias  = $this->findAlias($item->getName());
            $result = $alias ?: $item;
        } elseif (is_object($item)) {
            $hash = spl_object_hash($item);
            if (isset($this->processedObjects[$hash])) {
                // if analyzed; just return
                return null;
            }

            $newContainer = ($this->isDescriptorContainer($item)) ? $item : $container;

            $this->processedObjects[$hash] = true;

            $objectClassName = get_class($item);
            $fieldNames = isset($this->substitutions[$objectClassName])
                ? $this->substitutions[$objectClassName]
                : array();

            foreach ($fieldNames as $fieldName) {
                $fieldValue = $this->findFieldValue($item, $fieldName);
                $response = $this->substitute($fieldValue, $newContainer);

                // if the returned response is not an object it must be grafted on the calling object
                if ($response !== null) {
                    $setter = 'set'.ucfirst($fieldName);
                    $item->$setter($response);
                }
            }
        }

        return $result;
    }
public function substitute ( $ item , $ container = null ) { $ result = null ; if ( is_string ( $ item ) ) { $ result = $ this -> findAlias ( $ item , $ container ) ; } elseif ( is_array ( $ item ) || ( $ item instanceof \ Traversable && ! $ item instanceof ProjectInterface ) ) { $ isModified = false ; foreach ( $ item as $ key => $ element ) { $ isModified = true ; $ element = $ this -> substitute ( $ element , $ container ) ; if ( $ element !== null ) { $ item [ $ key ] = $ element ; } } if ( $ isModified ) { $ result = $ item ; } } elseif ( is_object ( $ item ) && $ item instanceof UnknownTypeDescriptor ) { $ alias = $ this -> findAlias ( $ item -> getName ( ) ) ; $ result = $ alias ? : $ item ; } elseif ( is_object ( $ item ) ) { $ hash = spl_object_hash ( $ item ) ; if ( isset ( $ this -> processedObjects [ $ hash ] ) ) { // if analyzed; just return return null ; } $ newContainer = ( $ this -> isDescriptorContainer ( $ item ) ) ? $ item : $ container ; $ this -> processedObjects [ $ hash ] = true ; $ objectClassName = get_class ( $ item ) ; $ fieldNames = isset ( $ this -> substitutions [ $ objectClassName ] ) ? $ this -> substitutions [ $ objectClassName ] : array ( ) ; foreach ( $ fieldNames as $ fieldName ) { $ fieldValue = $ this -> findFieldValue ( $ item , $ fieldName ) ; $ response = $ this -> substitute ( $ fieldValue , $ newContainer ) ; // if the returned response is not an object it must be grafted on the calling object if ( $ response !== null ) { $ setter = 'set' . ucfirst ( $ fieldName ) ; $ item -> $ setter ( $ response ) ; } } } return $ result ; }
Substitutes the given item or its children's FQCN with an object alias.

This method may do either of the following depending on the item's type

String
If the given item is a string then this method will attempt to find an appropriate Class, Interface or
TraitDescriptor object and return that. See {@see findAlias()} for more information on the normalization
of these strings.

Array or Traversable
Iterate through each item, pass each key's contents to a new call to substitute and replace the key's
contents if the contents is not an object (objects automatically update and saves performance).

Object
Determines all eligible substitutions using the substitutions property, construct a getter and retrieve
the field's contents. Pass these contents to a new call of substitute and use a setter to replace the field's
contents if anything other than null is returned.

This method will return null if no substitution was possible and all of the above should not update the parent
item when null is passed.

@param string|object|\Traversable|array $item
@param DescriptorAbstract|null          $container A descriptor that acts as container for all elements
underneath or null if there is no current container.

@return null|string|DescriptorAbstract
Substitutes the given item or its children s FQCN with an object alias .