コード例 #1
0
 private function loadEndpoints()
 {
     foreach ($this->endpoints as $endpoint) {
         $wordpress_pre = 'wp_ajax';
         if ($endpoint->accessibleForAuthorized()) {
             $function = [$wordpress_pre, $this->prefix, $endpoint->getRoute(), strtolower($endpoint->getMethod())];
             add_action(implode('_', $function), function () use($endpoint) {
                 $perm = $endpoint->getRequiredPermission();
                 if ($perm == null || $perm != null && $this->permssions->has($perm)) {
                     $response = $this->kernel->handleRequest($endpoint->getAction());
                 } else {
                     $response = new Response("Unauthorized", Response::HTTP_UNAUTHORIZED);
                 }
                 $response->send();
                 die;
             });
         }
         if ($endpoint->accessibleForUnauthorized()) {
             $function = [$wordpress_pre, 'nopriv', $this->prefix, $endpoint->getRoute(), strtolower($endpoint->getMethod())];
             add_action(implode('_', $function), function () use($endpoint) {
                 $response = $this->kernel->handleRequest($endpoint->getAction());
                 $response->sendContent();
                 die;
             });
         }
     }
 }
コード例 #2
0
 /**
  * Handle a page call, executed when the page is being accessed.
  *
  * @param MenuItem $menuItem the menu item
  */
 private function handlePageCall(MenuItem $menuItem)
 {
     $response = $this->kernel->handleRequest($menuItem->getAction());
     $response->sendContent();
 }