示例#1
0
 /**
  * Get the path to the file that should be generated.
  *
  * @param      $srcType         String  name of the directory type
  *                              code            - directory for code (app or workbench)
  *                              commands
  *                              config
  *                              controllers
  *                              lang
  *                              migrations
  *                              models
  *                              public
  *                              routes          - directory/file for the routes file
  *                              seeds
  *                              templates
  *                              tests
  *                              views
  *
  *                              The returned path will be adjusted for bench option to map the directory to the right location
  *                              in the workbench/vendor/package subdirectory based on laravel version
  *
  * @param null $suffix
  *
  * @return string
  */
 protected function getSrcPath($srcType, $suffix = null)
 {
     if ($this->option('path')) {
         $srcPath = $this->option('path');
     } else {
         $srcPath = GeneratorsServiceProvider::getSrcPath($srcType, $this->option('bench'));
     }
     return $suffix ? end_with($srcPath, '/') . $suffix : $srcPath;
 }
示例#2
0
文件: news.php 项目: jojoee/autofeed
 private function test_utility_helper()
 {
     $this->unit->use_strict(true);
     $this->unit->run(get_github_url(), 'is_string', 'get_github_url()');
     $this->unit->run(get_facebook_url(), 'is_string', 'get_facebook_url()');
     $this->unit->run(get_twitter_url(), 'is_string', 'get_twitter_url()');
     $this->unit->run(get_google_map_key(), 'is_string', 'get_google_map_key()');
     $this->unit->run(get_ga_code(), 'is_string', 'get_ga_code()');
     $this->unit->run(is_null_or_empty_string(''), 'is_true', 'is_null_or_empty_string()');
     $this->unit->run(is_null_or_empty_string('test'), 'is_false', 'is_null_or_empty_string()');
     $this->unit->run(is_null_or_empty_string(1), 'is_false', 'is_null_or_empty_string()');
     $this->unit->run(start_with('abcdef', 'ab'), 'is_true', 'start_with()');
     $this->unit->run(start_with('abcdef', 'cd'), 'is_false', 'start_with()');
     $this->unit->run(start_with('abcdef', 'ef'), 'is_false', 'start_with()');
     $this->unit->run(start_with('abcdef', ''), 'is_true', 'start_with()');
     $this->unit->run(start_with('', 'abcdef'), 'is_false', 'start_with()');
     $this->unit->run(end_with("abcdef", "ab"), 'is_false', 'end_with()');
     $this->unit->run(end_with("abcdef", "cd"), 'is_false', 'end_with()');
     $this->unit->run(end_with("abcdef", "ef"), 'is_true', 'end_with()');
     $this->unit->run(end_with("abcdef", ""), 'is_true', 'end_with()');
     $this->unit->run(end_with("", "abcdef"), 'is_false', 'end_with()');
     $this->unit->run(get_domain_name('http://somedomain.co.uk'), 'somedomain.co.uk', 'get_domain_name()');
     $this->unit->run(get_domain_name('http://www2.manager.co.th'), 'manager.co.th', 'get_domain_name()');
     $this->unit->run(get_domain_name('http://test.manager.co.th'), 'manager.co.th', 'get_domain_name()');
     $this->unit->run(get_domain_name('http://manager.co.th'), 'manager.co.th', 'get_domain_name()');
     $this->unit->run(get_domain_name('http://thaiware.com'), 'thaiware.com', 'get_domain_name()');
     $this->unit->run(get_domain_name('http://www.thaiware.com'), 'thaiware.com', 'get_domain_name()');
     $this->unit->run(get_domain_name('http://test.thaiware.com'), 'thaiware.com', 'get_domain_name()');
     $this->unit->run(get_domain_name('http://www.studentloan.ktb.co.th/'), 'ktb.co.th', 'get_domain_name()');
     $this->unit->run(get_domain_name('http://www.studentloan.ktb.co.th/dasdasdasd.html'), 'ktb.co.th', 'get_domain_name()');
     $this->unit->run(get_domain_name('http://www.studentloan.ktb.co.th?quewadsas=2faddasdas'), 'ktb.co.th', 'get_domain_name()');
     $this->unit->run(get_domain_name('http://www.studentloan.ktb.co.th/2011/20/01?=asdasdasdasd'), 'ktb.co.th', 'get_domain_name()');
     $this->unit->run(get_domain_name('http://pantip.com/forum/siam'), 'pantip.com', 'get_domain_name()');
     $this->unit->run(get_domain_name('http://www.wegointer.com/category/variety/'), 'wegointer.com', 'get_domain_name()');
     $this->unit->run(get_domain_name(), 'lab.jojoee.com', 'get_domain_name()');
     $this->unit->run(get_full_domain_name('http://www.wegointer.com/category/variety/'), 'www.wegointer.com', 'get_domain_name()');
     $this->unit->run(get_full_domain_name('http://somedomain.co.uk'), 'somedomain.co.uk', 'get_full_domain_name()');
     $this->unit->run(get_full_domain_name('http://www2.manager.co.th'), 'www2.manager.co.th', 'get_full_domain_name()');
     $this->unit->run(get_full_domain_name('http://test.manager.co.th'), 'test.manager.co.th', 'get_full_domain_name()');
     $this->unit->run(get_full_domain_name('http://manager.co.th'), 'manager.co.th', 'get_full_domain_name()');
     $this->unit->run(get_full_domain_name('http://thaiware.com'), 'thaiware.com', 'get_full_domain_name()');
     $this->unit->run(get_full_domain_name('http://www.thaiware.com'), 'www.thaiware.com', 'get_full_domain_name()');
     $this->unit->run(get_full_domain_name('http://test.thaiware.com'), 'test.thaiware.com', 'get_full_domain_name()');
     $this->unit->run(get_full_domain_name('http://www.studentloan.ktb.co.th/'), 'www.studentloan.ktb.co.th', 'get_full_domain_name()');
     $this->unit->run(get_full_domain_name('http://www.studentloan.ktb.co.th/dasdasdasd.html'), 'www.studentloan.ktb.co.th', 'get_full_domain_name()');
     $this->unit->run(get_full_domain_name('http://www.studentloan.ktb.co.th?quewadsas=2faddasdas'), 'www.studentloan.ktb.co.th', 'get_full_domain_name()');
     $this->unit->run(get_full_domain_name('http://www.studentloan.ktb.co.th/2011/20/01?=asdasdasdasd'), 'www.studentloan.ktb.co.th', 'get_full_domain_name()');
     $this->unit->run(get_full_domain_name('http://pantip.com/forum/siam'), 'pantip.com', 'get_full_domain_name()');
     $this->unit->run(get_full_domain_name('http://www.wegointer.com/category/variety/'), 'www.wegointer.com', 'get_full_domain_name()');
     $this->unit->run(get_full_domain_name(), 'lab.jojoee.com', 'get_full_domain_name()');
     $url = 'http://sub.wegointer.com/category/variety/';
     $this->unit->run(get_request_url($url, get_full_domain_name($url)), '/category/variety', 'get_request_url()');
     $url = 'http://www.wegointer.com/category/variety/';
     $this->unit->run(get_request_url($url, get_full_domain_name($url)), '/category/variety', 'get_request_url()');
     $this->unit->run(get_full_url(), 'http://lab.jojoee.com/nn/test', 'get_full_url()');
     // 404, 301
     // $this->unit->run(is_url_exists('http://jojoee.com/404'), 'is_true', 'is_url_exists()');
     // $this->unit->run(is_url_exists('http://fashion.spokedark.tv/2015/04/24/dichan-magazine/'), 'is_true', 'is_url_exists()');
     // $this->unit->run(is_url_exists('http://www.jojoee.com/'), 'is_true', 'is_url_exists()');
     // $this->unit->run(is_url_exists('http://test4041.com/'), 'is_false', 'is_url_exists()');
     // $this->unit->run(is_url_exists('http://test4041.com/'), 'is_false', 'is_url_exists()');
     // $this->unit->run(is_url_redirects('http://www.jojoee.com/'), 'is_true', 'is_url_exists()');
     // $this->unit->run(is_404('http://jojoee.com/404'), 'is_true', 'is_404()');
     // $url = 'http://fashion.spokedark.tv/?p=6600';
     // $this->unit->run(is_url_exists($url), 'is_true', 'is_url_exists()');
     // $this->unit->run(is_url_redirects($url), 'is_true', 'is_url_redirects()');
     // don't know why it doesn't work
     // $url = 'http://movies.spokedark.tv?p=10054/';
     // $this->unit->run(is_url_exists($url), 'is_true', 'is_url_exists()');
     // $this->unit->run(is_url_redirects($url), 'is_true', 'is_url_redirects()');
     $this->unit->run(get_extension('file.jpeg'), 'jpeg', 'get_extension()');
     $this->unit->run(get_extension('file.bk.zip'), 'zip', 'get_extension()');
     $this->unit->run(remove_trailing_slash('/category/product/'), '/category/product', 'remove_trailing_slash()');
     $this->unit->run(remove_trailing_slash('/category/product'), '/category/product', 'remove_trailing_slash()');
     $this->unit->run(remove_trailing_slash('category/product/'), 'category/product', 'remove_trailing_slash()');
     for ($i = 0; $i < 20; $i++) {
         $urls = $this->get_posts();
         foreach ($urls as $url) {
             $this->unit->run($url['is_publish'], '0', 'get_posts()');
         }
     }
 }
示例#3
0
// 公用函数
require_once FROOT . 'config' . DS . 'core.php';
// 核心配置
require_once AROOT . 'config' . DS . 'database.php';
// 数据库配置
require_once AROOT . 'config' . DS . 'app.php';
// 应用配置
build_route_file();
// build doc
date_default_timezone_set('Asia/Chongqing');
use Lazyphp\Doc\Builder;
use Crada\Apidoc\Exception;
if ($classes = get_declared_classes()) {
    $ret = array();
    foreach ($classes as $class) {
        if (end_with($class, 'Controller')) {
            $controll_classes[] = $class;
        }
    }
}
if (isset($controll_classes)) {
    $output_dir = AROOT . 'docs';
    $output_file = 'index.html';
    // defaults to index.html
    try {
        $builder = new Builder($controll_classes, $output_dir, $output_file);
        $builder->generate();
    } catch (Exception $e) {
        echo 'There was an error generating the documentation: ', $e->getMessage();
    }
}
示例#4
0
function get_website_files($paths)
{
    global $all_settings;
    $public_html_dir = '/' . get_setting('public_html_dir', $all_settings) . '/';
    if (!is_array($paths)) {
        $paths = array($paths);
    }
    $html_files = array();
    foreach ($paths as $path) {
        $path = rtrim(str_replace("\\", "/", $path), '/') . '/';
        if (file_exists($path)) {
            $entries = array();
            $dir = dir($path);
            while (false !== ($entry = $dir->read())) {
                $entries[] = $entry;
            }
            $dir->close();
            foreach ($entries as $entry) {
                $entry1 = strtolower($entry);
                if (end_with($entry1, 'html') || end_with($entry1, 'htm') || end_with($entry1, 'php')) {
                    $fullname = $path . $entry;
                    if ($entry != '.' && $entry != '..' && is_dir($fullname)) {
                        //$html_files = array_merge($html_files, get_website_files($fullname));
                    } else {
                        if (is_file($fullname)) {
                            $html_files[$fullname] = get_url_for_html_file($public_html_dir, $path, $entry);
                        }
                    }
                }
            }
        }
    }
    return $html_files;
}
示例#5
0
function build_route_file($return = false)
{
    $meta = array();
    if ($cfiles = glob(AROOT . 'controller' . DS . '*Controller.php')) {
        foreach ($cfiles as $cfile) {
            require_once $cfile;
        }
    }
    if ($classes = get_declared_classes()) {
        $ret = array();
        foreach ($classes as $class) {
            if (end_with($class, 'Controller')) {
                // 开始遍历
                $ref = new \ReflectionClass($class);
                if ($methods = $ref->getMethods()) {
                    foreach ($methods as $method) {
                        $item = array();
                        if ($item['meta'] = format_meta(parse_comment($method->getDocComment()))) {
                            $item['class'] = $class;
                            $item['method'] = $method->name;
                            $item['meta']['binding'] = get_param_info($method->getParameters());
                            if (isset($item['meta']['LazyRoute'][0]['route'])) {
                                $item['meta']['route'][] = array('uri' => $item['meta']['LazyRoute'][0]['route'], 'params' => get_route_params($item['meta']['LazyRoute'][0]['route']));
                            }
                            $ret[] = $item;
                        }
                    }
                }
            }
        }
        if (count($ret) > 0) {
            foreach ($ret as $method_info) {
                // 只处理标记了路由的方法
                if (isset($method_info['meta']['route'])) {
                    //print_r( $method_info['meta']['route'] );
                    $key = cmkey($method_info);
                    //echo "{$method_info['class']} , {$method_info['method']} = $key (build) \r\n";
                    $meta[$key] = $method_info['meta'];
                    // 生成路由部分代码
                    foreach ($method_info['meta']['route'] as $route) {
                        $source[] = '$app->' . "route('" . t($route['uri']) . "',array( '" . $method_info['class'] . "','" . $method_info['method'] . "'));";
                    }
                }
            }
        }
    }
    $GLOBALS['meta'] = $meta;
    if (isset($source) && is_array($source) && count($source) > 0) {
        $source_code = build_source_code($source, $meta);
        if ($return) {
            return $source_code;
        } else {
            save_route_file($source_code);
        }
    }
}
 public static function getSrcPath($srcType, $package = null)
 {
     $dir_map = GeneratorsServiceProvider::getSrcTypePath();
     if ($package) {
         $benchDir = $dir_map[$srcType]['bench'];
         $srcPath = $benchDir;
         if ($benchDir !== '') {
             $srcPath = str_replace('{{vendor/package}}', self::vendorPackage($package), $srcPath);
             $srcPath = str_replace('{{Vendor/Package}}', $package, $srcPath);
             $srcPath = 'workbench/' . $package . '/' . $srcPath;
         }
     } else {
         $appDir = $dir_map[$srcType]['app'];
         $srcPath = $appDir;
     }
     $srcPath = end_with(base_path(), '/') . $srcPath;
     return $srcPath;
 }
示例#7
0
 function end_with($string, $end)
 {
     if (is_array($end)) {
         foreach ($end as $val) {
             if (end_with($string, $val)) {
                 return true;
             }
         }
         return false;
     }
     return substr($string, -1, strlen($end)) === $end;
 }
示例#8
0
function process_file_in_rar($file_path, $type)
{
    global $is_debug;
    debug("process_file_in_rar: " . $file_path);
    $rar_file_path = "";
    if (strpos(strtolower($file_path), ".rar") != FALSE) {
        $rar_file_path = parse_real_path($file_path, ".rar");
    }
    if (strpos(strtolower($file_path), ".cbr") != FALSE) {
        $rar_file_path = parse_real_path($file_path, ".cbr");
    }
    $image_path = str_replace($rar_file_path . "/", "", $file_path);
    debug("rar_file_path: " . $rar_file_path);
    debug("image_path: " . $image_path);
    $rar_handle = rar_open($rar_file_path);
    if ($rar_handle != FALSE) {
        foreach ($rar_handle->getEntries() as $entry) {
            $entry_name = $entry->getName();
            $entry_name = change_encoding($entry_name);
            if (end_with($entry_name, $image_path)) {
                debug("found file in rar: " . $entry_name);
                $entry_size = $entry->getUnpackedSize();
                $fp = $entry->getStream();
                rar_close($rar_handle);
                if (!$is_debug) {
                    header("Content-Type: " . $type);
                    header("Content-Length: " . $entry_size);
                    while (!feof($fp)) {
                        $buff = fread($fp, 8192);
                        if ($buff !== false) {
                            echo $buff;
                        } else {
                            break;
                        }
                    }
                }
                fclose($fp);
            }
        }
    } else {
        debug("handle error");
    }
}