find() public method

Find a menu
public find ( string $id, array $with = [] ) : Menu
$id string menu identifier
$with array relation
return Xpressengine\Menu\Models\Menu
Ejemplo n.º 1
0
 /**
  * Find a menu
  *
  * @param string $id   menu identifier
  * @param array  $with relation
  * @return Menu
  */
 public function find($id, $with = [])
 {
     if (!isset($this->bag[$id])) {
         $this->bag[$id] = $this->repo->find($id, $with);
     }
     return $this->bag[$id];
 }
Ejemplo n.º 2
0
 /**
  * Find a menu
  *
  * @param string $id   menu identifier
  * @param array  $with relation
  * @return Menu
  */
 public function find($id, $with = [])
 {
     $key = $this->getCacheKey($id);
     return $this->cache->has($key) ? $this->cache->get($key) : call_user_func(function () use($key, $id, $with) {
         if ($menu = $this->repo->find($id, $with)) {
             $this->cache->put($key, $menu);
         }
         return $menu;
     });
 }
Ejemplo n.º 3
0
 /**
  * Find a menu
  *
  * @param string $id   menu identifier
  * @param array  $with relation
  * @return Menu
  */
 public function find($id, $with = [])
 {
     $key = $this->getCacheKey($id);
     $subKey = $this->getWithKey($with);
     $data = $this->cache->get($key);
     if (!$data || !isset($data[$subKey])) {
         if ($menu = $this->repo->find($id, $with)) {
             $data = $data ?: [];
             $data[$subKey] = $menu;
             $this->cache->put($key, $data);
         }
     } else {
         $menu = $data[$subKey];
     }
     return $menu;
 }
Ejemplo n.º 4
0
 /**
  * Get menu
  *
  * @param string $id   menu identifier
  * @param array  $with relation
  * @return Menu
  */
 public function get($id, $with = [])
 {
     return $this->repo->find($id, $with);
 }