public function normalize($object, $scope = 'default')
    {
        switch (true) {

            // Cannot normalized anything which already are
            case !is_object($object) :
                return $object;

            // StdClass can be cast as array
            case $object instanceof StdClass :
                return (array) $object;

            // DateTime : ISO format
            case $object instanceof \DateTime:
                return $object->format(\DateTime::ISO8601);

            // Other objects : we use a closure hack to read data
            case !$object instanceof NormalizableInterface :
                $extractor = \Closure::bind($this->createExtractorDelegate(), $object, get_class($object));

                return $extractor($object);

            // At this point, we always got a Normalizable
            default:
                return $object->normalize($scope);
        }
    }
public function normalize($object, $scope = 'default')
    {
        switch (true) {

            // Cannot normalized anything which already are
            case !is_object($object) :
                return $object;

            // StdClass can be cast as array
            case $object instanceof StdClass :
                return (array) $object;

            // DateTime : ISO format
            case $object instanceof \DateTime:
                return $object->format(\DateTime::ISO8601);

            // Other objects : we use a closure hack to read data
            case !$object instanceof NormalizableInterface :
                $extractor = \Closure::bind($this->createExtractorDelegate(), $object, get_class($object));

                return $extractor($object);

            // At this point, we always got a Normalizable
            default:
                return $object->normalize($scope);
        }
    }
public function normalize ( $ object , $ scope = 'default' ) { switch ( true ) { // Cannot normalized anything which already are case ! is_object ( $ object ) : return $ object ; // StdClass can be cast as array case $ object instanceof StdClass : return ( array ) $ object ; // DateTime : ISO format case $ object instanceof \ DateTime : return $ object -> format ( \ DateTime :: ISO8601 ) ; // Other objects : we use a closure hack to read data case ! $ object instanceof NormalizableInterface : $ extractor = \ Closure :: bind ( $ this -> createExtractorDelegate ( ) , $ object , get_class ( $ object ) ) ; return $ extractor ( $ object ) ; // At this point, we always got a Normalizable default : return $ object -> normalize ( $ scope ) ; } }
Normalize given object using given scope.

@param mixed  $object
@param string $scope

@return array|string

@throws ScopeNotFoundException If given scope not defined into given normalizable
@throws InvalidScopeException  If given scope requires an unaccessible field
Normalize given object using given scope .