Example #1
0
 public function fromDispatcher($dispatcher)
 {
     $request = $dispatcher->get('request_stack')->getCurrentRequest();
     $uri = $request->getPathInfo();
     if (JString::startswith($uri, "/")) {
         $uri = \substr($uri, 1);
     }
     return \explode("/", $uri);
 }
Example #2
0
 public function fromArray($array)
 {
     foreach ($this as $key => $value) {
         if (array_key_exists($key, $array) && !JString::startswith($key, "_")) {
             $setter = "set" . ucfirst($key);
             $this->{$setter}($array[$key]);
             unset($array[$key]);
         }
     }
     foreach ($array as $key => $value) {
         if (method_exists($this, $key)) {
             try {
                 $this->{$key}($value);
                 unset($array[$key]);
             } catch (\Exception $e) {
                 // Nothing to do
             }
         } else {
             $setter = "set" . ucfirst($key);
             if (method_exists($this, $setter)) {
                 try {
                     $this->{$setter}($value);
                     unset($array[$key]);
                 } catch (\Exception $e) {
                     // Nothing to do
                 }
             }
         }
     }
     return $array;
 }