private function executeFlag($flag) { $tasklists = $this->getAllTaskLists(); foreach ($tasklists as $tasklist) { $method = 'flag' . String::camelCase($flag); $this->invokeTaskMethod($tasklist, $method, array()); } }
private function createDebugTableData($debug) { $data = ''; foreach ($debug as $name => $value) { $id = StringUtility::underScore($name); $data .= $this->element('tr', $this->element('th', $name, array('scope' => 'row', 'id' => 'asarwf_dbgl_' . $id)) . $this->element('td', $this->createDataValues($value), array('id' => 'asarwf_dbgv_' . $id))); } return $data; }
private function removeInternalHeaders(MessageInterface $message) { $headers = $message->getHeaders(); foreach (array_keys($headers) as $key) { if (String::startsWith($key, 'Asar-Internal')) { $message->unsetHeader($key); } } }
/** * TODO: Refactor this! */ private function getNameFromPath($app_name, $path) { $rname = $this->getResourceNamePrefix($app_name); $prefixed_with = $this->resource_lister->getResourceListFor($app_name); $count = substr_count($this->getResourceNamePrefix($app_name), '\\'); foreach ($this->getPathSubspaces($path) as $subspace) { $count++; $old_rname = $rname; $rname = $rname . '\\' . String::camelCase($subspace); if (class_exists($rname)) { continue; } $rname = $this->getWildCardTypeRoute($old_rname, $prefixed_with, $rname, $count); if (!class_exists($rname)) { $this->throwResourceNotFoundException($path); } } return $rname; }
private function formatResourceNameFragment($path) { if (String::startsWith($path, '{')) { return 'Rt' . String::camelCase(trim($path, '{}')); } return String::camelCase($path); }
private function passRequest($request, $response, $path) { if ($this->forward_recursion >= $this->forward_level_max) { /** * @todo Throw Asar\Application\Exception instead */ throw new Exception("Maximum forwards reached for path '{$request->getPath()}'."); } $this->forward_recursion++; try { $resource = $this->router->route($this->name, $path, $this->getMap()); $this->checkIfResource($resource); $response = $this->returnIfResponse($resource->handleRequest($request)); } catch (ResourceNotFound $e) { $response->setStatus(404); } catch (ForwardRequest $e) { $payload = $e->getPayload(); $req = $payload['request']; $req->setHeader('Asar-Internal-Isforwarded', true); $response = $this->passRequest($payload['request'], $response, $e->getMessage()); } if ($response->getStatus() >= 300 && $response->getStatus() < 400 && !String::startsWith($response->getHeader('Location'), '/')) { $resource = $this->router->route($this->name, $response->getHeader('Location'), $this->getMap()); if ($resource instanceof PathDiscoverInterface) { $response->setHeader('Location', $resource->getPermaPath()); } } return $response; }
private function getPathTemplate() { if (!$this->path_template) { $this->path_template = array(); $relevant = $this->getResourceNameAsArray(); $keys = array_map(array('Asar\\Utility\\String', 'dashLowerCase'), $relevant); for ($i = 0, $size = count($keys); $i < $size; $i++) { if (String::startsWith($keys[$i], 'rt-')) { $this->path_template[substr($keys[$i], 3)] = null; } else { $this->path_template[$keys[$i]] = $keys[$i]; } } } return $this->path_template; }
private function _testHeaders($headers, $str) { foreach ($headers as $key => $value) { $pattern = "/\r\n" . str_replace(array('.', '-'), array('\\.', '\\-'), String::dashCamelCase($key)) . ": {$value}\r\n/"; $this->assertRegExp($pattern, $str, "Did not find the {$key} header that was set."); } }
function testStartsWith() { $this->assertSame(true, String::startsWith('Rararara', 'R')); $this->assertSame(true, String::startsWith('Wararara', 'War')); $this->assertSame(false, String::startsWith('Rararara', 'ar')); }