public function test_contains() { $array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red'); $this->assertTrue(Core_Arrays::contains($array, 'red')); $this->assertFalse(Core_Arrays::contains($array, 'black')); }
public function column_exists($name) { return Core_Arrays::contains($this->columns, (string) $name); }
/** * @param WebKit_HTTP_Request $request * * @return WebKit_Controller_Route */ public function route($request) { if ($this->is_not_match_for($request->urn)) { return null; } if ($route = $this->route_index($request)) { return $route; } $uri = Core_Regexps::replace('{^/|/$}', '', $this->clean_url($request->urn)); $uri = Core_Strings::replace($uri, '.' . ($format = $this->guess_format($uri)), ''); $current = false; $action = false; $nested_ids = array(); $parts = Core_Strings::split_by('/', $uri); $last_idx = count($parts) - 1; foreach ($parts as $idx => $part) { if (!$current) { if (isset($this->resources[$part]) && !isset($this->resources[$part]['parent'])) { $current = $part; } else { return null; } } else { if (isset($nested_ids["{$this->resources[$current]['single']}_id"])) { if (isset($this->resources[$current]['instance']) && isset($this->resources[$current]['instance'][$part]) && Core_Strings::contains($this->resources[$current]['instance'][$part], $request->method) && $idx == $last_idx) { $action = $part; break; } if (isset($this->resources[$part]) && isset($this->resources[$current]['nested']) && Core_Arrays::contains($this->resources[$current]['nested'], $part)) { $current = $part; } else { return null; } } else { if (isset($this->resources[$current]['collection']) && isset($this->resources[$current]['collection'][$part]) && Core_Strings::contains($this->resources[$current]['collection'][$part], $request->method) && $idx == $last_idx) { $action = $part; } else { $nested_ids["{$this->resources[$current]['single']}_id"] = $part; } } } } $id = isset($nested_ids["{$this->resources[$current]['single']}_id"]) ? $nested_ids["{$this->resources[$current]['single']}_id"] : false; if (!$action) { switch ($request->method_name) { case 'get': $action = $id === false ? 'index' : 'view'; break; case 'post': $action = 'create'; break; case 'put': $action = 'update'; break; case 'delete': $action = 'delete'; break; } } return WebKit_Controller::Route()->merge(array('controller' => isset($this->resources[$current]['controller']) ? $this->resources[$current]['controller'] : Core_Strings::capitalize($current) . 'Controller', 'action' => $action, 'format' => $format))->merge($id ? array($id) : array())->merge($nested_ids)->merge($this->defaults)->add_controller_prefix($this->options['prefix']); }