public function fileFsPost() { LFileTest::createTests(); $this->app->response->setBody(LFileTest::$Tester->gibSituationsdaten('fileFsPost')); $this->app->response->setStatus(201); $this->app->stop(); }
/** * Returns whether the component is installed for the given course * * Called when this component receives an HTTP GET request to * /link/exists/course/$courseid(/). * * @param int $courseid A course id. */ public function getExistsCourse($courseid) { $result = Request::routeRequest('GET', '/process/course/' . $courseid . '/component/' . $this->_conf->getId(), $this->app->request->headers->all(), '', $this->_getProcess, 'process'); if (isset($result['status']) && $result['status'] >= 200 && $result['status'] <= 299 && isset($result['content']) && $this->_conf !== null && $this->_conf->getId() !== null) { $this->app->response->setStatus(200); $this->app->stop(); } $this->app->response->setStatus(409); }
/** * Returns informations about a given extension * * Called when this component receives an HTTP GET request to * /link/extension/$name(/). * * @param int $name The name of the component */ public function getExtension($name) { foreach ($this->_extension as $link) { if ($link->getTargetName() === $name || $link->getTarget() === $name) { $this->app->response->setStatus(200); $this->app->response->setBody(Link::encodeLink($link)); $this->app->stop(); } } $this->app->response->setStatus(404); $this->app->response->setBody(null); }
/** * Returns whether the component is installed for the given course * * Called when this component receives an HTTP GET request to * /link/exists/course/$courseid(/). * * @param int $courseid A course id. */ public function getExistsCourse($courseid) { // hier soll geprüft werden, ob ein entsprechender Eintrag für diese Komponente in der referenzierten Prozesstabelle besteht, // ob sie also als Verarbeitung registriert ist (dazu wird die ID dieser Komponente verwendet ($this->_conf->getId())) $result = Request::routeRequest('GET', '/process/course/' . $courseid . '/component/' . $this->_conf->getId(), array(), '', $this->_getProcess, 'process'); // wenn etwas für die ID dieser Komponente von der DB geantwortet wird, ist die Installation korrekt bzw. vorhanden. if (isset($result['status']) && $result['status'] >= 200 && $result['status'] <= 299 && isset($result['content']) && $this->_conf !== null && $this->_conf->getId() !== null) { $this->app->response->setStatus(200); $this->app->stop(); } // die Datenbank hat keinen Eintrag für diese Komponente geliefert oder ein sonstiger Fehler ist aufgetreten, daher // gilt die Installation als nicht vorhanden/korrekt $this->app->response->setStatus(409); }
/** * Adds the component to the platform * * Called when this component receives an HTTP POST request to * /platform. */ public function addPlatform() { Logger::Log('starts POST AddPlatform', LogLevel::DEBUG); // decode the received course data, as an object $insert = Platform::decodePlatform($this->_app->request->getBody()); // always been an array $arr = true; if (!is_array($insert)) { $insert = array($insert); $arr = false; } // this array contains the indices of the inserted objects $res = array(); foreach ($insert as $in) { $file = dirname(__FILE__) . '/config.ini'; $text = "[DB]\n" . "db_path = \"" . str_replace(array("\\", "\""), array("\\\\", "\\\""), $in->getDatabaseUrl()) . "\"\n" . "db_user = \"" . str_replace(array("\\", "\""), array("\\\\", "\\\""), $in->getDatabaseOperatorUser()) . "\"\n" . "db_passwd = \"" . str_replace(array("\\", "\""), array("\\\\", "\\\""), $in->getDatabaseOperatorPassword()) . "\"\n" . "db_name = \"" . str_replace(array("\\", "\""), array("\\\\", "\\\""), $in->getDatabaseName()) . "\"\n" . "[PL]\n" . "urlExtern = \"" . str_replace(array("\\", "\""), array("\\\\", "\\\""), $in->getExternalUrl()) . "\"\n" . "url = \"" . str_replace(array("\\", "\""), array("\\\\", "\\\""), $in->getBaseUrl()) . "\""; if (!@file_put_contents($file, $text)) { Logger::Log('POST AddPlatform failed, config.ini no access', LogLevel::ERROR); $this->_app->response->setStatus(409); $this->_app->stop(); } // starts a query ob_start(); eval("?>" . file_get_contents(dirname(__FILE__) . '/Sql/AddPlatform.sql')); $sql = ob_get_contents(); ob_end_clean(); $result = DBRequest::request2($sql, false, parse_ini_file(dirname(__FILE__) . '/config.ini', TRUE)); // checks the correctness of the query if (!isset($result['errno']) || !$result['errno']) { $platform = new Platform(); $platform->setStatus(201); $res[] = $platform; $this->_app->response->setStatus(201); } else { Logger::Log('POST AddPlatform failed', LogLevel::ERROR); $this->_app->response->setStatus(409); $this->_app->response->setBody(Platform::encodePlatform($res)); $this->_app->stop(); } } if (!$arr && count($res) == 1) { $this->_app->response->setBody(Platform::encodePlatform($res[0])); } else { $this->_app->response->setBody(Platform::encodePlatform($res)); } }
/** * Deletes a course. * * Called when this component receives an HTTP DELETE request to * /course/course/$courseid(/). * * @param int $courseid The id of the course that is being deleted. * * @author Till Uhlig * @date 2014 */ public function deleteCourse($courseid) { Logger::Log('starts DELETE DeleteCourse', LogLevel::DEBUG); $this->app->response->setStatus(201); $header = $this->app->request->headers->all(); $courseid = DBJson::mysql_real_escape_string($courseid); foreach ($this->_deleteCourse as $_link) { $result = Request::routeRequest('DELETE', '/course/' . $courseid, $header, '', $_link, 'course'); // checks the correctness of the query if ($result['status'] == 201) { // ok } else { Logger::Log('DELETE DeleteCourse failed', LogLevel::ERROR); $this->app->response->setStatus(isset($result['status']) ? $result['status'] : 409); $this->app->stop(); } } }
/** * Adds the component to a course * * Called when this component receives an HTTP POST request to * (/:preChoice(/:preForm(/:preExercise)))/course(/). * * @param int $preChoice A optional prefix for the Choice table. * @param int $preForm A optional prefix for the Form table. * @param int $preExercise A optional prefix for the Exercise table. */ public function addCourse($preChoice = '', $preForm = '', $preExercise = '') { $this->loadConfig($preChoice, $preForm, $preExercise); $preChoice = ($preChoice === '' ? '' : '_') . $preChoice; $preForm = ($preForm === '' ? '' : '_') . $preForm; $preExercise = ($preExercise === '' ? '' : '_') . $preExercise; Logger::Log('starts POST AddCourse', LogLevel::DEBUG); // decode the received course data, as an object $insert = Course::decodeCourse($this->_app->request->getBody()); $preChoice = DBJson::mysql_real_escape_string($preChoice); $preForm = DBJson::mysql_real_escape_string($preForm); $preExercise = DBJson::mysql_real_escape_string($preExercise); // always been an array $arr = true; if (!is_array($insert)) { $insert = array($insert); $arr = false; } // this array contains the indices of the inserted objects $res = array(); foreach ($insert as $in) { // starts a query, by using a given file $result = DBRequest::getRoutedSqlFile($this->query, dirname(__FILE__) . '/Sql/AddCourse.sql', array('object' => $in, 'preChoice' => $preChoice, 'preForm' => $preForm, 'preExercise' => $preExercise)); // checks the correctness of the query if ($result['status'] >= 200 && $result['status'] <= 299) { $queryResult = Query::decodeQuery($result['content']); $res[] = $in; $this->_app->response->setStatus(201); if (isset($result['headers']['Content-Type'])) { $this->_app->response->headers->set('Content-Type', $result['headers']['Content-Type']); } } else { Logger::Log('POST AddCourse failed', LogLevel::ERROR); $this->_app->response->setStatus(isset($result['status']) ? $result['status'] : 409); $this->_app->response->setBody(Course::encodeCourse($res)); $this->_app->stop(); } } if (!$arr && count($res) == 1) { $this->_app->response->setBody(Course::encodeCourse($res[0])); } else { $this->_app->response->setBody(Course::encodeCourse($res)); } }
/** * Removes the component from a given course * * Called when this component receives an HTTP DELETE request to * /course/$courseid(/). */ public function deleteCourse($courseid) { Logger::Log('starts DELETE DeleteCourse', LogLevel::DEBUG); $courseid = DBJson::mysql_real_escape_string($courseid); foreach ($this->_createCourse as $_link) { $result = Request::routeRequest('DELETE', '/course/' . $courseid, array(), '', $_link, 'course'); // checks the correctness of the query if ($result['status'] >= 200 && $result['status'] <= 299) { $this->app->response->setStatus(201); if (isset($result['headers']['Content-Type'])) { $this->app->response->headers->set('Content-Type', $result['headers']['Content-Type']); } } else { Logger::Log('POST DeleteCourse failed', LogLevel::ERROR); $this->app->response->setStatus(isset($result['status']) ? $result['status'] : 409); $this->app->stop(); } } }
/** * Adds the component to the platform * * Called when this component receives an HTTP POST request to * /platform. */ public function addPlatform() { Logger::Log('starts POST AddPlatform', LogLevel::DEBUG); // decode the received course data, as an object $insert = Platform::decodePlatform($this->_app->request->getBody()); // always been an array $arr = true; if (!is_array($insert)) { $insert = array($insert); $arr = false; } // this array contains the indices of the inserted objects $res = array(); foreach ($insert as $in) { // starts a query, by using a given file $result = DBRequest::getRoutedSqlFile($this->query2, dirname(__FILE__) . '/Sql/AddPlatform.sql', array('object' => $in), false); // checks the correctness of the query if ($result['status'] >= 200 && $result['status'] <= 299) { $queryResult = Query::decodeQuery($result['content']); $res[] = $in; $this->_app->response->setStatus(201); if (isset($result['headers']['Content-Type'])) { $this->_app->response->headers->set('Content-Type', $result['headers']['Content-Type']); } } else { Logger::Log('POST AddPlatform failed', LogLevel::ERROR); $this->_app->response->setStatus(isset($result['status']) ? $result['status'] : 409); $this->_app->response->setBody(Platform::encodePlatform($res)); $this->_app->stop(); } } if (!$arr && count($res) == 1) { $this->_app->response->setBody(Platform::encodePlatform($res[0])); } else { $this->_app->response->setBody(Platform::encodePlatform($res)); } }
/** * Test Slim Stop * * Pre-conditions: * You have initialized a Slim application and stop * the application inside of a route callback. * * Post-conditions: * A SlimStopException is thrown; * The response is unaffected by code after Slim::stop is called */ public function testSlimStop() { Slim::init(); Slim::get('/', function () { try { echo "foo"; Slim::stop(); echo "bar"; } catch ( Slim_Exception_Stop $e ) {} }); Slim::run(); $this->assertEquals(Slim::response()->body(), 'foo'); }
$app->configureMode('development', function () use($app) { $app->config(array('debug' => true)); }); $app->configureMode('production', function () use($app) { error_reporting(0); $app->notFound(function () use($app) { $page = new ErrorController(404); $page->render(); }); $app->error(function (Exception $e) use($app) { $app->response()->status(500); if (!$app->request()->isAjax()) { $page = new ErrorController(500); $page->render(); } $app->stop(); if (file_exists(BASE_DIR . '/.gbemail')) { foreach (explode('\\n', file_get_contents(BASE_DIR . '/.gbemail')) as $email) { mail(trim($email), "GetchaBooks Error", get_error_message($e)); } } }); }); $app->hook('slim.before', function () use($app) { global $referrers; $request = $app->request(); define('BASE_URL', $request->getUrl() . $request->getRootUri() . '/'); define('CURRENT_URL', $request->getUrl() . $request->getPath()); define('MOBILE_DEVICE', strpos(strtolower($request->getUserAgent()), 'mobile') !== false); // remove extra slashes $path = $request->getPath();
/** * Test stop does not leave output buffers open */ public function testStopDoesNotLeaveOutputBuffersOpen() { $level_start = ob_get_level(); $s = new Slim(); $s->get('/bar', function () use($s) { $s->stop(); }); $s->run(); $this->assertEquals($level_start, ob_get_level()); }
/** * Test stop with subsequent output */ public function testStopWithSubsequentOutput() { $this->expectOutputString('Foo'); $s = new Slim(); $s->get('/bar', function () use($s) { echo "Foo"; //<-- Should be in response body! $s->stop(); echo "Bar"; //<-- Should not be in response body! }); $s->call(); $this->assertEquals('Foo', $s->response()->body()); }
/** * Test Slim Stop * * Pre-conditions: * Slim app instantiated; * Slim app stopped while route invocation in process; * * Post-conditions: * Slim ignores output after `stop()` is invoked; */ public function testSlimStop() { $app = new Slim(); $app->get('/', function () use($app) { try { echo "foo"; $app->stop(); echo "bar"; } catch (Slim_Exception_Stop $e) { } }); $app->run(); $this->assertEquals('foo', $app->response()->body()); }
/** * Test stop with subsequent output */ public function testStopWithSubsequentOutput() { $this->expectOutputString('Foo'); $s = new Slim(); $s->get('/bar', function () use($s) { echo "Foo"; //<-- Should be in response body! $s->stop(); echo "Bar"; //<-- Should not be in response body! }); $env = $s->environment(); list($status, $header, $body) = $s->call($env); $this->assertEquals('Foo', $body); }