public function connect(Application $app) { $controllers = new ControllerCollection(); // ******* // ** Signup member // ******* $controllers->get('signup.html', function () use($app) { $form = $app['form.factory']->create(new \Aperophp\Form\Signup()); return $app['twig']->render('member/signup.html.twig', array('form' => $form->createView())); })->bind('_signupmember'); // ******* // ******* // ** Create member // ******* $controllers->post('create.html', function (Request $request) use($app) { $form = $app['form.factory']->create(new \Aperophp\Form\Signup()); $form->bindRequest($request); if ($form->isValid()) { $data = $form->getData(); // TODO save member in database. var_dump($data); die; } return $app['twig']->render('member/signup.html.twig', array('form' => $form->createView())); })->bind('_createmember'); // ******* return $controllers; }
protected function addRoutes(ControllerCollection $c) { $c->get('/changelog', 'changeOverview')->bind('changelog'); $c->get('/changelog/{contenttype}/{contentid}/{id}', 'changeRecord')->assert('id', '\\d*')->bind('changelogrecordsingle'); $c->get('/changelog/{contenttype}/{contentid}', 'changeRecordListing')->value('contentid', '0')->value('contenttype', '')->bind('changelogrecordall'); $c->get('/systemlog', 'systemOverview')->bind('systemlog'); }
protected function addRoutes(ControllerCollection $c) { $c->get('/login', 'getLogin')->bind('login'); $c->post('/login', 'postLogin')->bind('postLogin'); $c->match('/logout', 'logout')->bind('logout'); $c->get('/resetpassword', 'resetPassword')->bind('resetpassword'); }
public function connect(Application $app) { $controllers = new ControllerCollection(); $supervisor = new API(); $servers = (include __DIR__ . '/../../config.php'); foreach (array_keys($servers) as $server_id) { $servers[$server_id]['id'] = $server_id; } $controllers->get('/list.{_format}', function ($_format) use($supervisor, $app, $servers) { if ($_format == 'json') { return $app->json($servers); } else { // use a closure to avoid leaking any vars into the template that we don't explicitly want return call_user_func(function () use($app) { $url_root = $app['url_generator']->generate('home'); ob_start(); ob_implicit_flush(false); include __DIR__ . '/../../views/supervisorui.html.php'; return ob_get_clean(); }); } })->bind('server_list')->value('_format', 'html'); $controllers->get('/details/{server_id}', function ($server_id) use($supervisor, $app, $servers) { $server_ip = $servers[$server_id]['ip']; $details = array_merge(array('version' => $supervisor->getSupervisorVersion('127.0.0.1'), 'pid' => $supervisor->getPID('127.0.0.1')), $supervisor->getState('127.0.0.1'), $servers[$server_id]); return $app->json($details); }); return $controllers; }
protected function addRoutes(ControllerCollection $c) { $c->method('GET|POST'); $c->match('/editcontent/{contenttypeslug}/{id}', 'edit')->bind('editcontent')->assert('id', '\\d*')->value('id', ''); $c->get('/overview/{contenttypeslug}', 'overview')->bind('overview'); $c->get('/relatedto/{contenttypeslug}/{id}', 'related')->bind('relatedto')->assert('id', '\\d*'); }
protected function addRoutes(ControllerCollection $controllers) { $controllers->get('/tokens', array($this, 'indexAction'))->bind('user_tokens'); $controllers->get('/tokens/new', array($this, 'newAction'))->bind('user_tokens_new'); $controllers->post('/tokens/new', array($this, 'newAction'))->bind('user_tokens_new_process'); $controllers->post('/tokens/{token}/delete', array($this, 'deleteAction'))->bind('user_tokens_delete'); }
protected function addRoutes(ControllerCollection $controllers) { $controllers->get('/users/new', array($this, 'newAction'))->bind('user_new'); $controllers->post('/users/new', array($this, 'handleNewAction'))->bind('user_new_handle'); $controllers->get('/users/choose', array($this, 'chooseAction'))->bind('user_choose'); $controllers->get('/users/{name}', array($this, 'showAction'))->bind('user_show'); }
protected function addRoutes(ControllerCollection $controllers) { $controllers->post('/key', [$this, 'create']); $controllers->get('/key/{id}', [$this, 'show']); $controllers->put('/key/{id}', [$this, 'update']); $controllers->delete('/key/{id}', [$this, 'delete']); }
public function connect(Application $app) { $controllers = new ControllerCollection(); $controllers->get('auth', function () use($app) { if ($app['session']->has($app['config']['prefix'] . 'authed-user')) { return $app->redirect('/'); } return $app['twig']->render('PT/pages/authenticate.html', array('auth_path' => $app['uri']->generate('authenticate'))); })->bind('authenticate'); $controllers->post('auth', function () use($app) { if ($app['request']->get('username') === $app['config']['authenticate']['username'] && $app['request']->get('password') === $app['config']['authenticate']['password']) { $userHash = $userHash = sha1($app['config']['authenticate']['username'] . $app['config']['authenticate']['password']); $currentUser = $app['session']->set($app['config']['prefix'] . 'authed-user', $userHash); return $app->redirect('/'); } else { $app['session']->setFlash('error', 'error'); $app['session']->remove($app['config']['prefix'] . 'authed-user'); return $app->redirect($app['uri']->generate('authenticate')); } })->bind('do_authenticate'); $controllers->get('deauth', function ($result) use($app) { $app['session']->remove($app['config']['prefix'] . 'authed-user'); return $app->redirect($app['uri']->generate('authenticate')); })->value('result', null)->bind('de_authenticate'); return $controllers; }
protected function addRoutes(ControllerCollection $controllers) { $controllers->get('/password/generate', [$this, 'generatePassword']); $controllers->post('/password/generate', [$this, 'generatePassword']); $controllers->get('/password/complication', [$this, 'complicationPassword']); $controllers->get('/secret', [$this, 'secret']); }
public function connect(Application $app) { $controllers = new ControllerCollection(); $controllers->match('/{slug}', function (Application $app, Request $request, $username) { return $this->getProcessor($request)->execute()->getResponse(); }); return $controllers; }
/** * Register the method $controllerName as controller for the given method and uri. * * @param \Silex\ControllerCollection $cc * @param string $controllerName Fully qualified method name of the controller * @return \Silex\Controller */ public function process(ControllerCollection $cc, $controllerName) { $controller = $cc->match($this->uri, $controllerName); if ('MATCH' != ($method = strtoupper($this->method))) { // limit to configured method(s) $controller = $controller->method($method); } return $controller; }
protected function addRoutes(ControllerCollection $c) { $c->match('/file/edit/{namespace}/{file}', 'edit')->assert('file', '.+')->assert('namespace', '[^/]+')->value('namespace', 'files')->bind('fileedit')->after(function (Request $request, Response $response) { if ($request->isMethod('POST')) { $response->headers->set('X-XSS-Protection', '0'); } }); $c->match('/files/{namespace}/{path}', 'manage')->assert('namespace', '[^/]+')->assert('path', '.*')->value('namespace', 'files')->value('path', '')->bind('files'); }
public function testConflictingRouteNames() { $controllers = new ControllerCollection(); $mountedRootController = new Controller(new Route('/')); $controllers->add($mountedRootController); $mainRootController = new Controller(new Route('/')); $mainRootController->bindDefaultRouteName('main_'); $controllers->flush(); $this->assertNotEquals($mainRootController->getRouteName(), $mountedRootController->getRouteName()); }
public function testMount() { $mounted = new ControllerCollection(new Route()); $mounted->get('/{name}', function ($name) { return new Response($name); }); $app = new Application(); $app->mount('/hello', $mounted); $response = $app->handle(Request::create('/hello/Silex')); $this->assertEquals('Silex', $response->getContent()); }
public function match(Resource $resource, $routeType, $to) { $routeClass = $this->routeClass; /* @var $route Route */ $route = new $routeClass(); $route->setPath($resource->getPath($routeType)); $route->setDefault('_controller', $to); $route->setMethods($resource->getMethods($routeType)); $this->routeCollection->add($resource->getName($routeType), $route); return $route; }
public function connect(Application $app) { $index = new ControllerCollection(new Route()); $index->get('/', function () use($app) { $label = $app['models']->load('Pages', 'index'); return $label; }); $index->get('/{name}', function ($name) use($app) { $name = $app['models']->load('Pages', 'hello', $name); return "Hello {$name}"; }); return $index; }
public function connectControllers(ControllerCollection $controllers, $prefix = null) { if ($prefix === null) { $prefix = static::SEPARATOR . $this->getPath(); } foreach ($this->controllerCollections as $collection) { $controllers->mount($prefix, $collection); } foreach ($this->getChildren() as $childNode) { $childNode->connectControllers($controllers); } $this->getBaseNode()->connectControllers($controllers, $prefix); }
/** * Verifies collection is correct type and calls connect on providers. * * Note: This is the same code as {@see Silex\Application::mount} * * @param ControllerProviderInterface|ControllerCollection $collection * * @throws LogicException If controllers is not an instance of ControllerProviderInterface or ControllerCollection * * @return ControllerCollection */ protected function verifyCollection($collection) { if ($collection instanceof ControllerProviderInterface) { $connectedControllers = $collection->connect($this->app); if (!$connectedControllers instanceof ControllerCollection) { throw new LogicException(sprintf('The method "%s::connect" must return a "ControllerCollection" instance. Got: "%s"', get_class($collection), is_object($connectedControllers) ? get_class($connectedControllers) : gettype($connectedControllers))); } $collection = $connectedControllers; } elseif (!$collection instanceof ControllerCollection) { throw new LogicException('The "mount" method takes either a "ControllerCollection" or a "ControllerProviderInterface" instance.'); } return $collection; }
public function connect(Application $app) { $controller = new ControllerCollection($app['route_factory']); // Element Delete (POST) $controller->post('delete', function () use($app) { $id = $app['request']->get('elementId'); $result = $app['repository.element']->delete(array('id' => $id)); if ($result == 1) { return $app->json('OK'); } return $app->json('KO'); })->bind('route.element.delete'); return $controller; }
public static function connectController(ControllerCollection $ctrlsFactory, $controllerArray) { $ctrlAccessPath = $controllerArray['Namespace'] . '\\' . $controllerArray['Name'] . '::'; $prefix = $controllerArray['Prefix']; foreach ($controllerArray['Actions'] as $_action) { $method = Annots\Method::forUsage($_action['Method']); $route = $prefix . $_action['Route']; $action = $_action['Name']; $binded = Annots\Bind::forUsage($_action['Bind'], $prefix, $_action['Name']); /** @var Controller $routeFactored */ $routeFactored = $ctrlsFactory->match($route, $ctrlAccessPath . $action)->bind($binded)->method($method); // TODO : proposer le assert en annot //if (strpos($route, '{id}') !== false) // $routeFactored->assert('id', "\d+"); } }
public function __construct(Route $defaultRoute, $defaultLocale = 'en', array $locales, TranslatorInterface $translator, $translationDomain = 'routes') { $this->defaultLocale = $defaultLocale; $this->locales = $locales; $this->translator = $translator; $this->translationDomain = $translationDomain; parent::__construct($defaultRoute); }
/** * @param string $variable * @param mixed $callback * @return $this */ public function convert($variable, $callback) { if (is_string($callback)) { $callback = $this->callback_prefix . ":" . $callback; } parent::convert($variable, $callback); return $this; }
protected function addRoutes(ControllerCollection $c) { $c->get('/about', 'about')->bind('about'); $c->get('/checks', 'checks')->bind('checks'); $c->get('/clearcache', 'clearCache')->bind('clearcache'); $c->get('/', 'dashboard')->bind('dashboard'); $c->get('/omnisearch', 'omnisearch')->bind('omnisearch-results'); $c->match('/prefill', 'prefill')->bind('prefill'); $c->match('/tr/{domain}/{tr_locale}', 'translation')->bind('translation')->assert('domain', 'messages|contenttypes|infos')->value('domain', 'messages')->value('tr_locale', $this->app['locale']); }
public function connect(Application $app) { $this->app = $app; // api v1 $api = new ControllerCollection(new Route()); $api->get('/{model}', __CLASS__ . '::listAction')->assert('model', '^([a-z]+)$'); $api->get('/{model}/{id}', __CLASS__ . '::itemAction')->assert('model', '^([a-z]+)$')->assert('id', '^([a-z0-9]+)$'); $api->delete('/{model}/{id}', __CLASS__ . '::deleteAction')->assert('model', '^([a-z]+)$')->assert('id', '^([a-z0-9]+)$'); $api->put('/{model}/{id}', __CLASS__ . '::updateAction')->assert('model', '^([a-z]+)$')->assert('id', '^([a-z0-9]+)$'); $api->post('/{model}', __CLASS__ . '::createAction')->assert('model', '^([a-z]+)$'); // $model = $this->checkModel('message'); // // foreach (range(900, 1000) as $id) // { // $message = new $model; // // $message->text = $id; // $message->date = time(); // // $this->dm->persist($message); // } // // $this->dm->flush(); return $api; }
public function connect(Application $app) { $controllers = new ControllerCollection(); // ******* // ** Homepage // ******* $controllers->get('/', function () use($app) { return $app['twig']->render('index.html.twig'); }); // ******* // ******* // ** Add a drink // ******* $controllers->get('apero/new.html', function () use($app) { return $app['twig']->render('apero/new.html.twig'); }); // ******* return $controllers; }
public function match($pattern, $to = null) { $controller = parent::match($pattern, $to); $route = $controller->getRoute(); if (!$route instanceof CorsRoute) { throw new \RuntimeException('The generated route does not have the proper type, did you register the service provider properly?'); } $route->setControllerCollection($this); return $controller; }
public function connect(Application $app) { $controller = new ControllerCollection($app['route_factory']); $controller->match('/', function () use($app) { if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $browsersLocale = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); if (in_array($browsersLocale, array('en', 'fr'))) { $app['locale'] = $browsersLocale; } } return $app->redirect($app['url_generator']->generate('homepage', array('locale' => $app['locale']))); })->bind('home'); $controller->match('/{locale}/', function () use($app) { // Get all reports $reports = $app['repository.report']->findAll(); return $app['twig']->render('Report/list.html.twig', array('reports' => $reports)); })->bind('homepage'); return $controller; }
/** * When mounting a controller class with a prefix most times you have a route with a blank path. * That is the only route that flushes to include an (unwanted) trailing slash. * * This fixes that trailing slash. * * @param string $prefix * @return \Symfony\Component\Routing\RouteCollection */ public function flush($prefix = '') { $routes = parent::flush($prefix); foreach ($routes->all() as $name => $route) { if (substr($route->getPath(), -1) === '/') { $route->setPath(rtrim($route->getPath(), '/')); } } return $routes; }
/** * * * @param ControllerCollection $factory * @return null */ public function createRoutes(ControllerCollection $factory) { $factory->get('/files', [$this, 'get']); $factory->get('/files/{hash}', [$this, 'getOne']); $factory->post('/files/{hash}', [$this, 'userAction']); $factory->delete('/files/{hash}', [$this, 'remove'])->onlyAdmin(); $factory->put('/files/{hash}', [$this, 'update'])->onlyAdmin(); $factory->get('/artists', [$this, 'getArtists']); }