예제 #1
0
파일: Context.php 프로젝트: janpoem/kephp
 /**
  *
  * <code>
  * import('file', ['user' => new User()]);
  * import('file');
  * import('file', 'wrapper', ['name' => 'Jack']);
  * import('file', 'wrapper');
  * </code>
  *
  * @param            $file
  * @param null       $layout
  * @param array|null $vars
  * @param bool       $isStrict
  * @return bool|string
  * @throws Exception
  */
 public function loadComponent($file, $layout = null, array $vars = null, bool $isStrict = false)
 {
     if (!isset($layout) || is_array($layout) || is_object($layout)) {
         $vars = (array) $layout;
         $layout = false;
     }
     $content = '';
     $filePath = $this->web->getComponentPath($file);
     if ($filePath === false) {
         $message = "Component {$file} not found!";
         if ($isStrict) {
             throw new Exception($message);
         }
         $content = "<pre>{$message}</pre>";
     } else {
         $content = $this->import($filePath, $vars);
     }
     if (!empty($layout)) {
         $content = $this->layout($content, $layout, $vars);
     }
     return $content;
 }