Exemplo n.º 1
0
 protected function executeImpl(ArrayAdapter $params)
 {
     $method = $params->str('method');
     $params = $params->arr('params');
     TestManagerCaller::execute($method, $params);
     return new AjaxSuccess();
 }
Exemplo n.º 2
0
 /**
  * Список методов, доступных для вызова
  */
 public static function getMethodsList()
 {
     if (!AuthManager::isAuthorizedAsAdmin() || PsDefines::isProduction()) {
         return array();
     }
     if (!is_array(self::$METHODS)) {
         self::$METHODS = array();
         $methodNames = PsUtil::getClassMethods(TestManager::inst(), true, false, true, true);
         foreach ($methodNames as $name) {
             $method = new ReflectionMethod(TestManager::inst(), $name);
             $params['name'] = $name;
             $params['descr'] = implode("\n", StringUtils::parseMultiLineComments($method->getDocComment()));
             $params['params'] = array();
             /* @var $param ReflectionParameter */
             foreach ($method->getParameters() as $param) {
                 $params['params'][] = array('name' => $param->getName(), 'dflt' => $param->isDefaultValueAvailable() ? var_export($param->getDefaultValue(), true) : null);
             }
             self::$METHODS[$name] = $params;
         }
     }
     return self::$METHODS;
 }
Exemplo n.º 3
0
 /**
  * Основной метод, выполняющий загрузку содержимого тестовой страницы
  */
 private function getContentImpl(RequestArrayAdapter $params, Smarty $smarty)
 {
     //Силовые упражнения
     $exId = $params->int('ex_id');
     if ($exId) {
         //$ex = GymManager::getInstance()->getExercise($exId);
         $tplPath = "gym/exercises/{$exId}.tpl";
         return $smarty->templateExists($tplPath) ? $smarty->fetch($tplPath) : null;
     }
     //Специальные страницы
     $pageType = $params->str('pagetype');
     if ($pageType) {
         $smParams = array();
         switch ($pageType) {
             case 'smarty':
                 foreach (array('blocks', 'functions', 'modifiers') as $type) {
                     $items = DirManager::smarty('plugins/' . $type)->getDirContentFull(null, PsConst::EXT_PHP);
                     /* @var $item DirItem */
                     foreach ($items as $item) {
                         //Название
                         $name = explode('.', $item->getName());
                         $name = $name[1];
                         //Первый комментарий
                         $tokens = token_get_all($item->getFileContents());
                         $comment = array(T_COMMENT, T_DOC_COMMENT);
                         $fileComment = '';
                         foreach ($tokens as $token) {
                             if (in_array($token[0], $comment)) {
                                 $fileComment = trim($token[1]);
                                 break;
                             }
                         }
                         $smParams[$type][] = array('name' => $name, 'comment' => $fileComment);
                     }
                 }
                 break;
             case 'doubleimg':
                 $images = DirManager::images()->getDirContentFull(null, DirItemFilter::IMAGES);
                 $sorted = array();
                 /* @var $img DirItem */
                 foreach ($images as $img) {
                     $ident = $img->getSize() . 'x' . $img->getImageAdapter()->getWidth() . 'x' . $img->getImageAdapter()->getHeight();
                     $sorted[$ident][] = $img;
                 }
                 $result = array();
                 /* @var $img DirItem */
                 foreach ($sorted as $ident => $imgs) {
                     if (count($imgs) > 1) {
                         $result[$ident] = $imgs;
                     }
                 }
                 $smParams = array('images' => $result);
                 break;
             case 'testmethods':
                 $smParams['methods'] = TestManagerCaller::getMethodsList();
                 break;
             case 'imgbysize':
                 $images = DirManager::images()->getDirContentFull(null, DirItemFilter::IMAGES, array('GymExercises'));
                 DirItemSorter::inst()->sort($images, DirItemSorter::BY_SIZE);
                 $smParams = array('images' => $images);
                 break;
             case 'formules':
                 $formules = TexImager::inst()->getAllFormules();
                 $totalSize = 0;
                 /* @var $formula DirItem */
                 foreach ($formules as $formula) {
                     $totalSize += $formula->getSize();
                     $formula->setData('class', 'TeX');
                 }
                 DirItemSorter::inst()->sort($formules, DirItemSorter::BY_SIZE);
                 $smParams = array('formules' => $formules, 'formules_size' => $totalSize);
                 break;
         }
         $content = $smarty->fetch("test/page_{$pageType}.tpl", $smParams);
         if ($pageType) {
             switch ($pageType) {
                 case 'patterns':
                     $out = array();
                     preg_match_all("/===(.*?)===/", $content, $out, PREG_PATTERN_ORDER);
                     $params = array();
                     for ($i = 0; $i < count($out[0]); $i++) {
                         $full = $out[0][$i];
                         $ctt = $out[1][$i];
                         $params[$full] = "<div class=\"demo-head\">{$ctt}</div>";
                     }
                     $content = PsStrings::replaceMap($content, $params);
             }
         }
         return $content;
     }
     //Тестовая страница
     $num = $params->int('num');
     $num = $num ? $num : 1;
     return $smarty->fetch("test/page{$num}.tpl");
 }