public function testMuxGetMethod() { $mux = new Mux(); $mux->get('/news', array('NewsController', 'listAction')); $mux->get('/news_item', array('NewsController', 'itemAction'), array()); $routes = $mux->getRoutes(); $this->assertCount(2, $routes); $this->assertEquals(2, $mux->length()); $_SERVER['REQUEST_METHOD'] = "GET"; $this->assertNotNull($mux->dispatch('/news_item')); $this->assertNotNull($mux->dispatch('/news')); }
* Created by PhpStorm. * User: Aztyu * Date: 26/12/2015 * Time: 15:24 */ require_once 'vendor/autoload.php'; require_once 'controller/api/ApiUserController.php'; require_once 'controller/api/ApiFuelController.php'; require_once 'controller/api/SiteController.php'; require_once 'entities/Coordinates.php'; use Pux\Mux; use Pux\Executor; $path = explode("?", $_SERVER['REQUEST_URI'])[0]; $api_mux = new Mux(); $api_user_mux = new Mux(); $api_fuel_mux = new Mux(); $main_mux = new Mux(); $api_user_mux->get('/check', ['ApiUserController', 'checkAction']); $api_user_mux->get('/connect', ['ApiUserController', 'connectAction']); $api_user_mux->get('/create', ['ApiUserController', 'createAction']); $api_mux->mount('/user', $api_user_mux); $api_fuel_mux->get('/find', ['ApiFuelController', 'findAction']); $api_fuel_mux->post('/insert', ['ApiFuelController', 'insertAction']); $api_mux->mount('/fuel', $api_fuel_mux); $main_mux->mount('/api', $api_mux); $main_mux->get('/', ['SiteController', 'indexAction']); $route = $main_mux->dispatch($path); if ($route == null) { $route = $main_mux->dispatch('/'); } echo Executor::execute($route);
{ $path = "office/{$name}"; if (file_exists($path)) { $handle = fopen($path, "r"); $size = filesize($path); $contents = fread($handle, $size); $SHA256 = base64_encode(hash('sha256', $contents, true)); $json = array('BaseFileName' => $name, 'OwnerId' => 'admin', 'Size' => $size, 'SHA256' => $SHA256, 'Version' => '222888822'); echo json_encode($json); } else { echo json_encode(array()); } } public function getFileAction($name) { $path = "office/{$name}"; if (file_exists($path)) { $handle = fopen($path, "r"); $contents = fread($handle, filesize($path)); header("Content-type: application/octet-stream"); echo $contents; } } } $mux = new Mux(); $mux->get('/files/:name', ['FilesController', 'getFileInfoAction']); $mux->get('/files/:name/contents', ['FilesController', 'getFileAction']); $path = $_SERVER['PATH_INFO']; $args = explode("&", $path); $route = $mux->dispatch($args[0]); Executor::execute($route);