/** * Get the url to a action of the current route * * !Important it's not possible to link between action on multiple routes * This method always assumes that all actions are in the same route. * If you want to link to another route using an alias you could do something like: * * CCUrl::to( '@myalias/myaction' ); * * @param string $action * @param array $params * @param bool $retain Should we keep the get parameters? * @return string */ public static function action($action = '', $params = array(), $retain = false) { if ($action == 'index') { $action = ''; } if (CCRequest::current() && ($route = CCRequest::current()->route)) { $uri = $route->uri; if (!is_null($route->action)) { $uri = substr($uri, 0, strlen($route->action) * -1); } if (substr($uri, -1) != '/') { $uri .= '/'; } return static::to($uri . $action, $params, $retain); } throw new CCException('CCUrl::action - There has been no route executed yet.'); }
/** * CCUrl::action */ public function test_action() { CCRouter::on('test_action', 'CCUnit::Test'); CCRequest::uri('test_action/detail')->perform(); $this->assertEquals('/test_action/detail/?woo=yay', CCUrl::action('detail/', array('woo' => 'yay'))); $this->assertEquals('/test_action/?woo=yay', CCUrl::action('index', array('woo' => 'yay'))); $this->assertEquals('/test_action/', CCUrl::action()); // another route CCRouter::on('test_action/wurst', 'CCUnit::Test'); CCRequest::uri('test_action/wurst/detail')->perform(); $this->assertEquals('/test_action/wurst/detail/?woo=yay', CCUrl::action('detail/', array('woo' => 'yay'))); $this->assertEquals('/test_action/wurst/?woo=yay', CCUrl::action('index', array('woo' => 'yay'))); $this->assertEquals('/test_action/wurst/', CCUrl::action()); }
/** * error response * executes an private route with the error status code and * delivers the resulting response * * @param int $status * @return CCResponse */ public static function error($status) { return CCRequest::uri('#' . $status)->perform()->response(); }
<?php /* *--------------------------------------------------------------- * ClanCatsFramework runner *--------------------------------------------------------------- * * This file just loads CCF and all needed resources to run the * php unit tests. PHPUnit is a really elegant way to make sure * that everything works how it should. * *--------------------------------------------------------------- * Require CCF *--------------------------------------------------------------- * * load the framework file wich wil initialize CCF. */ require_once __DIR__ . "/clancatsapp/framework.php"; /* * execute the main request * The main request contains the params of the http header */ $response = CCRequest::uri(CCServer::uri())->perform()->response(); /* * "send" means actaully printing the response. * If the secound parameter is true the response will * also set headers */ $response->send(true);
/** * Tests the CCRouter filter escaping */ public function test_escaping() { CCRouter::on('this/u$l/conta([num])n+special/[any]', function () { echo "Escaping works"; }); $response = CCRequest::uri('this/u$l/conta(1)n+special/chars')->perform()->response()->body; $this->assertEquals($response, "Escaping works"); }
/** * delete deployment worker (not the worker-file itself, but the supervisor-daemon entry). * * @param string $applicationName applications name * @param string $deploymentName deployments name * @param string $workerId deployment worker id * * @throws TokenRequiredError * @throws BadRequestError * @throws UnauthorizedError * @throws ForbiddenError * @throws GoneError * @throws InternalServerError * @throws NotImplementedError * @throws ThrottledError * @throws CCException * * @return boolean */ public function removeWorker($applicationName, $deploymentName, $workerId) { $this->requiresToken(); $resource = sprintf('/app/%s/deployment/%s/worker/%s/', $applicationName, $deploymentName, $workerId); $request = new CCRequest($this->_url, $this->getToken()); $content = $request->delete($resource); return true; }