/**
  * Takes a scope-notated key and finds the value for it in the given
  * array or object.
  *
  * @param  string       $key     Dot-notated key to find
  * @param  array|object $data    Array or object to search
  * @param  mixed        $default Default value to use if not found
  * @return mixed
  */
 protected function getVariable($key, $data, $default = null)
 {
     // <statamic>
     // detect modifiers
     $modifiers = null;
     if (strpos($key, "|") !== false) {
         $parts = explode("|", $key);
         $key = $parts[0];
         $modifiers = array_splice($parts, 1);
     }
     // </statamic>
     if (strpos($key, $this->scopeGlue) === false) {
         $parts = explode('.', $key);
     } else {
         $parts = explode($this->scopeGlue, $key);
     }
     foreach ($parts as $key_part) {
         if (is_array($data)) {
             if (!array_key_exists($key_part, $data)) {
                 return $default;
             }
             $data = $data[$key_part];
         } elseif (is_object($data)) {
             if (!isset($data->{$key_part})) {
                 return $default;
             }
             $data = $data->{$key_part};
         } else {
             return $default;
         }
     }
     // <statamic>
     // execute modifier chain
     if ($modifiers) {
         foreach ($modifiers as $mod) {
             $now = time();
             if (strpos($mod, ":") === false) {
                 $modifier = $mod;
                 $modifier_params = array();
             } else {
                 $parts = explode(":", $mod);
                 $modifier = $parts[0];
                 $modifier_params = array_splice($parts, 1);
             }
             $hash = \Debug::markStart('modifiers', $modifier, $now);
             try {
                 // load modifier
                 $modifier_obj = \Resource::loadModifier(\Parse::modifierAlias($modifier));
                 // ensure method exists
                 if (!method_exists($modifier_obj, "index")) {
                     throw new \Exception("Improperly formatted modifier object.");
                 }
                 // call method
                 $data = $modifier_obj->index($data, $modifier_params);
                 \Debug::increment('modifiers', $modifier);
             } catch (\Exception $e) {
                 // do nothing
             }
             \Debug::markEnd($hash);
         }
     }
     // </statamic>
     return $data;
 }