/** * inspect a variable, and determine which method name to return * * @param mixed $item * the item to describe * @return string * the method name that you should call */ public function mapTypeToMethodName($item) { // we are optimised for objects, because they can be cached if (is_object($item)) { $type = get_class($item); } else { if (is_string($item) || is_array($item)) { // it isn't safe to cache these data types // the result depends upon their contents return $this->typeMapper->using($item, $this->typeMethods, $this->fallback); } else { // this is NULL, boolean, double, integer, resource // // NOTE that callable is a pseudotype; it's something that // other data types can satisfy $type = gettype($item); } } // have we seen this before? if (isset($this->dispatchCache[$type])) { return $this->dispatchCache[$type]; } // first time we've seen this $this->dispatchCache[$type] = $this->typeMapper->using($item, $this->typeMethods, $this->fallback); return $this->dispatchCache[$type]; }
/** * inspect a variable, and determine which method to call * * @param object $item * the item to describe * @return string * the method to call */ public function mapTypeToMethodName($item) { $type = get_class($item); // have we seen this before? if (isset($this->dispatchCache[$type])) { return $this->dispatchCache[$type]; } // first time we've seen this $this->dispatchCache[$type] = $this->typeMapper->using($item, $this->typeMethods, $this->fallback); return $this->dispatchCache[$type]; }
/** * inspect a variable, and determine which method to call * * @param mixed $item * the item to describe * @return string * the method to call */ public function mapTypeToMethodName($item) { // this provides the best all-around performance for both // objects and non-objects if (is_object($item)) { $type = get_class($item); } else { $type = gettype($item); } if (isset($this->dispatchCache[$type])) { return $this->dispatchCache[$type]; } // at this point, fall back to using the type mapper $this->dispatchCache[$type] = $this->typeMapper->using($item, $this->typeMethods, $this->fallback); return $this->dispatchCache[$type]; }