/** * Render a template file * * NOTE: This method should be overridden by custom view subclasses * * @var string $template The template pathname, relative to the template base directory * @return string The rendered template * @throws \RuntimeException If resolved template pathname is not a valid file */ protected function render($template) { $templatePathname = $this->getTemplatePathname($template); if (!is_file($templatePathname)) { throw new \RuntimeException("View cannot render `{$template}` because the template does not exist"); } extract($this->data->all()); ob_start(); require $templatePathname; return ob_get_clean(); }
/** * Render a template file * * NOTE: This method should be overridden by custom view subclasses * * @param string $template The template pathname, relative to the template base directory * @param array $data Any additonal data to be passed to the template. * @return string The rendered template * @throws \RuntimeException If resolved template pathname is not a valid file */ protected function render($template, $data = null) { #echo $this->getTemplatePathname($template);die; $templatePathname = $this->getTemplatePathname($template); if (!is_file($templatePathname)) { throw new \RuntimeException("View cannot render `{$template}` because the template does not exist"); } $data = array_merge($this->data->all(), (array) $data); extract($data); ob_start(); require $templatePathname; return ob_get_clean(); }
/** * Tries to create a new access token. */ public function accessTokenPost($request) { $body = $request->getBody(); $body = json_decode($body, true); // Some clients escape the JSON - handle them if (is_string($body)) { $body = json_decode($body, true); } if (json_last_error() !== JSON_ERROR_NONE) { throw new \Exception('Invalid JSON posted. Cannot continue!', Resource::STATUS_BAD_REQUEST); } $requestParams = new Set($body); if ($requestParams->get('user')['email'] === null) { throw new \Exception('Invalid request, user.email property not present!', Resource::STATUS_BAD_REQUEST); } $currentDate = new \DateTime(); $defaultParams = new Set(['user' => ['password' => 'password', 'permissions' => ['all']], 'scopes' => ['all'], 'name' => 'Token for ' . $requestParams->get('user')['email'], 'description' => 'Token generated at ' . Util\Date::dateTimeToISO8601($currentDate), 'expiresAt' => null]); $params = new Set(array_replace_recursive($defaultParams->all(), $requestParams->all())); $scopeDocuments = []; $scopes = $params->get('scopes'); foreach ($scopes as $scope) { $scopeDocument = $this->getScopeByName($scope); $scopeDocuments[] = $scopeDocument; } $permissionDocuments = []; $permissions = $params->get('user')['permissions']; foreach ($permissions as $permission) { $permissionDocument = $this->getScopeByName($permission); $permissionDocuments[] = $permissionDocument; } if (is_numeric($params->get('expiresAt'))) { $expiresAt = $params->get('expiresAt'); } else { if (null === $params->get('expiresAt')) { $expiresAt = null; } else { $expiresAt = new \DateTime($params->get('expiresAt')); $expiresAt = $expiresAt->getTimestamp(); } } $userService = new UserService($this->getSlim()); $user = $userService->addUser($params->get('user')['email'], $params->get('user')['password'], $permissionDocuments); $user->save(); $this->addToken($params->get('name'), $params->get('description'), $expiresAt, $user, $scopeDocuments); return $this; }
public function render($name, $data = array()) { $php = LightnCandy::compile($this->getTemplate($name), array('flags' => LightnCandy::FLAG_ERROR_EXCEPTION | LightnCandy::FLAG_ERROR_LOG | LightnCandy::FLAG_INSTANCE | LightnCandy::FLAG_MUSTACHE | LightnCandy::FLAG_HANDLEBARS, 'basedir' => $this->directories, 'fileext' => $this->extensions, 'helpers' => $this->helpers->all(), 'hbhelpers' => $this->block_helpers->all())); $renderer = LightnCandy::prepare($php); return $renderer(array_merge($data ?: array(), $this->all()), LCRun3::DEBUG_ERROR_LOG); }
// CORS compatibility layer (Internet Explorer) $app->hook('slim.before.router', function () use($app) { if ($app->request->isPost() && $app->request->get('method')) { $method = $app->request->get('method'); $app->environment()['REQUEST_METHOD'] = strtoupper($method); mb_parse_str($app->request->getBody(), $postData); $parameters = new Set($postData); if ($parameters->has('content')) { $content = $parameters->get('content'); $app->environment()['slim.input'] = $content; $parameters->remove('content'); } else { // Content is the only valid body parameter...everything else are either headers or query parameters $app->environment()['slim.input'] = ''; } $app->request->headers->replace($parameters->all()); $app->environment()['slim.request.query_hash'] = $parameters->all(); } }); // Parse version $app->hook('slim.before.dispatch', function () use($app) { // Version $app->container->singleton('version', function () use($app) { if ($app->request->isOptions() || $app->request->getPathInfo() === '/about' || strpos(strtolower($app->request->getPathInfo()), '/oauth') === 0) { $versionString = $app->config('xAPI')['latest_version']; } else { $versionString = $app->request->headers('X-Experience-API-Version'); } if ($versionString === null) { throw new \Exception('X-Experience-API-Version header missing.', Resource::STATUS_BAD_REQUEST); } else {