public function testRequest() { $r = new Request(); $r->setRequestUri('/test', '/admin'); $this->assertEquals('/admin', $r->getBasePath()); $this->assertEquals('/test', $r->getRequestUri()); $this->assertEquals('/admin/test', $r->getFullUri()); $this->assertFalse($r->isFile()); $this->assertFalse($r->isSecure()); $this->assertEquals('', $r->getDocRoot()); $this->assertEquals('/admin', $r->getFullPath()); $this->assertNull($r->getFilename()); $this->assertEquals('http', $r->getScheme()); $this->assertTrue(is_array($r->getQuery())); $this->assertNull($r->getQuery('test')); $this->assertTrue(is_array($r->getPost())); $this->assertNull($r->getPost('test')); $this->assertTrue(is_array($r->getPut())); $this->assertNull($r->getPut('test')); $this->assertTrue(is_array($r->getPatch())); $this->assertNull($r->getPatch('test')); $this->assertTrue(is_array($r->getDelete())); $this->assertNull($r->getDelete('test')); $this->assertTrue(is_array($r->getCookie())); $this->assertNull($r->getCookie('test')); $this->assertTrue(is_array($r->getServer())); $this->assertNull($r->getServer('test')); $this->assertTrue(is_array($r->getEnv())); $this->assertNull($r->getEnv('test')); }
public function index() { if (!isset($this->sess->user)) { $this->redirect('/login'); } $this->prepareView('index.phtml'); if (null !== $this->request->getQuery('modules')) { $model = new Model\Module(); $this->view->title = 'Modules'; } else { if (null !== $this->request->getQuery('themes')) { $model = new Model\Theme(); $this->view->title = 'Themes'; } else { $model = new Model\System(); $this->view->title = 'System'; } } if ($model->hasPages($this->pagination)) { $limit = $this->pagination; $pages = new Paginator($model->getCount(), $limit); $pages->useInput(true); } else { $limit = null; $pages = null; } $this->view->pages = $pages; $this->view->stats = $model->getAll($limit, $this->request->getQuery('page'), $this->request->getQuery('sort')); $this->view->php = $model->php; $this->view->db = $model->db; $this->view->server = $model->server; $this->view->os = $model->os; $this->send(); }
/** * Get query string * * @param mixed $omit * @return string */ public function getQueryString($omit = null) { if (null !== $omit && !is_array($omit)) { $omit = [$omit]; } $get = $this->request->getQuery(); $query = []; foreach ($get as $key => $value) { if (!isset($query[$key]) && !in_array($key, $omit)) { $query[$key] = $value; } } return count($query) > 0 ? http_build_query($query) : ''; }
public function fetch($resource) { if ($this->isValidPostData($this->request->getPost())) { $data = $this->parsePostData(); try { $ftp = new Ftp($data['address'], $data['username'], $data['password'], $data['ssl']); $ftp->pasv($data['pasv']); switch ($resource) { case 'phirecms': if (file_exists(__DIR__ . '/../../public/releases/phire/phire.json')) { $files = json_decode(file_get_contents(__DIR__ . '/../../public/releases/phire/phire.json'), true); $remote = $data['root'] . $data['base_path'] . $data['app_path'] . '/'; foreach ($files as $file) { $dir = dirname($file); if (!$ftp->dirExists($remote . $dir)) { $ftp->mkdirs($remote . $dir); } $ftp->put($remote . $file, __DIR__ . '/../../public/releases/phire/phire-cms/' . $file); } } break; default: if ($this->request->getQuery('theme') == 1 && file_exists(__DIR__ . '/../../public/releases/themes/' . $resource . '.zip') && !empty($data['content_path'])) { $remote = $data['root'] . $data['base_path'] . $data['content_path'] . '/themes/'; $ftp->put($remote . $resource . '.zip', __DIR__ . '/../../public/releases/themes/' . $resource . '.zip'); $ftp->chmod($resource . '.zip', 0777); } else { if (file_exists(__DIR__ . '/../../public/releases/modules/' . $resource . '.zip') && !empty($data['content_path'])) { $remote = $data['root'] . $data['base_path'] . $data['content_path'] . '/modules/'; $ftp->put($remote . $resource . '.zip', __DIR__ . '/../../public/releases/modules/' . $resource . '.zip'); $ftp->chmod($resource . '.zip', 0777); } } } $this->response->setBody(json_encode(['message' => 'Successful transfer.'], JSON_PRETTY_PRINT)); $this->response->send(200); } catch (\Exception $e) { $this->response->setBody(json_encode(['error' => $e->getMessage()], JSON_PRETTY_PRINT)); $this->response->send(401); } } else { $this->error(); } }
<?php require_once '../../bootstrap.php'; use Pop\Http\Request; try { $request = new Request(); switch ($request->getMethod()) { case 'GET': print_r($request->getQuery()); break; case 'POST': print_r($request->getPost()); break; case 'PUT': print_r($request->getPut()); break; case 'PATCH': print_r($request->getPatch()); break; case 'DELETE': print_r($request->getDelete()); break; } } catch (\Exception $e) { echo $e->getMessage(); }