/**
  * Attempts to find a controller class for the given view template path.
  *
  * @param string $viewName A view template absolute file path.
  * @return null|string null if no controller was found.
  */
 function findControllerForView($viewName)
 {
     /** @var DocumentContext $this */
     $path = $this->viewService->resolveTemplatePath($viewName, $base);
     //    inspect ($viewName, $base, $path);
     if (isset($this->controllers[$path])) {
         return $this->controllers[$path];
     }
     foreach ($this->controllerNamespaces as $nsPath => $ns) {
         //      inspect ($nsPath, $ns);
         if (str_beginsWith($path, $nsPath)) {
             $remaining = substr($path, strlen($nsPath) + 1);
             $a = PS($remaining)->split('/');
             $file = $a->pop();
             $nsPrefix = $a->map('ucfirst', false)->join('\\')->S;
             $class = ($p = strpos($file, '.')) !== false ? ucfirst(substr($file, 0, $p)) : ucfirst($file);
             $FQN = PA([$ns, $nsPrefix, $class])->prune()->join('\\')->S;
             //        inspect ("CLASS $FQN");
             if (class_exists($FQN)) {
                 return $FQN;
             }
         }
     }
     //    inspect ("CLASS NOT FOUND FOR VIEW $viewName");
     return null;
 }
 function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     $url = $request->getAttribute('virtualUri', '');
     if (!str_beginsWith($url, "{$this->settings->fileBaseUrl()}/")) {
         return $next();
     }
     // Strip prefix from URL
     $url = substr($url, strlen($this->settings->fileBaseUrl()) + 1);
     $path = "{$this->settings->fileArchivePath()}/{$url}";
     if (!file_exists($path)) {
         return $this->responseFactory->make(404, "Not found: {$path}", 'text/plain');
     }
     $mime = FileUtil::getMimeType($path);
     // Serve image file.
     if (FileUtil::isImageType($mime)) {
         // Use image manipulation parameters extracted from the request.
         return $this->glideServer->getImageResponse($url, $request->getQueryParams());
     }
     // Server non-image file.
     return $this->responseFactory->makeStream(fopen($path, 'rb'), 200, ['Content-Type' => $mime, 'Content-Length' => (string) filesize($path), 'Cache-Control' => 'max-age=31536000, public', 'Expires' => date_create('+1 years')->format('D, d M Y H:i:s') . ' GMT']);
 }
 /**
  * Constructs a tree-like structure from flat form-submitted data.
  *
  * > <p>**Note:** keys with slashes are expanded into nested arrays.
  *
  * @param array $data
  * @return array
  */
 private function parseFormData(array $data)
 {
     $o = [];
     $root = "{$this->modelRootPath}.";
     $p = strlen($root);
     foreach ($data as $k => $v) {
         $k = str_replace('/', '.', $k);
         if (str_beginsWith($k, $root)) {
             setAt($o, substr($k, $p), $v, true);
         }
     }
     return $o;
 }
 private function toFileName($key)
 {
     if (str_beginsWith($key, $this->appDir)) {
         $key = substr($key, strlen($this->appDir));
     }
     return "{$this->basePath}/" . preg_replace('#/|\\\\#', '.', escapeshellcmd($key));
 }
 protected function preRender()
 {
     $prop = $this->props;
     if ($link = $prop->link) {
         extend($prop, ['label' => $link->title(), 'href' => $link->url(), 'icon' => $link->icon(), 'active' => $link->isActive()]);
     }
     $this->disabled = is_null($prop->href) && !exists($prop->script) || $prop->disabled;
     if ($this->disabled) {
         $this->addClass($prop->disabledClass);
     }
     if ($prop->active || exists($prop->href) && str_beginsWith($prop->currentUrl, $prop->href) || $prop->href === '' && $prop->currentUrl === '') {
         $this->cssClassName = $prop->activeClass;
     }
     if (!empty($prop->wrapper)) {
         $this->containerTag = $prop->wrapper;
     }
     parent::preRender();
 }
 /**
  * Checks if the specified MIME is of image type.
  *
  * @param string $type The file's MIME type.
  * @return bool
  */
 static function isImageType($type)
 {
     return str_beginsWith($type, 'image/');
 }