Esempio n. 1
0
<?php

if (arg('v f i c j a views fonts images styles scripts all')) {
    $cache = array();
    $cache_dir = \Tailor\Config::get('cache_dir');
    $base_path = path(APP_PATH, 'app', 'assets');
    $views_dir = path(APP_PATH, 'app', 'views');
    $static_dir = path(APP_PATH, 'static');
    // views
    if (arg('v views all') && is_dir($views_dir)) {
        \IO\Dir::each($views_dir, '*', function ($file) {
            if (is_file($file)) {
                $name = join('.', array_slice(explode('.', basename($file)), 0, 2));
                $path = str_replace(path(APP_PATH, 'app', 'views') . DIRECTORY_SEPARATOR, '', dirname($file));
                $cache_dir = \Tailor\Config::get('cache_dir');
                $cache_file = path($cache_dir, strtr("{$path}/{$name}", '\\/', '__'));
                write(path(dirname($cache_file), basename($cache_file)), \Tailor\Base::compile($file));
                status('prepare', "{$path}/{$name}");
            }
        });
    }
    $handler = function ($on) use($base_path, $static_dir) {
        $dir = path($static_dir, $on);
        $path = path($base_path, $on);
        return function ($file) use($on, $dir, $path, $base_path, $static_dir) {
            if (is_file($file)) {
                $file_hash = md5(md5_file($file) . filesize($file));
                $file_name = str_replace($path . DIRECTORY_SEPARATOR, '', \IO\File::extn($file)) . $file_hash . \IO\File::ext($file, TRUE);
                $file_path = path($dir, $file_name);
                if (s3_handle()) {
                    s3_upload_asset($file, str_replace($static_dir . DIRECTORY_SEPARATOR, '', $file_path));
Esempio n. 2
0
// routing
\Broil\Config::set('rewrite', TRUE);
\Broil\Config::set('server_base', $base_url);
\Broil\Config::set('tld_size', substr_count($base_url, '.'));
// assets
\Tailor\Config::set('fonts_url', "{$base_url}/font");
\Tailor\Config::set('images_url', "{$base_url}/img");
\Tailor\Config::set('styles_url', "{$base_url}/css");
\Tailor\Config::set('scripts_url', "{$base_url}/js");
// templating
\Tailor\Config::set('cache_dir', TMP);
\Tailor\Config::set('views_dir', path($target_dir, 'views'));
\Tailor\Config::set('fonts_dir', path($assets_dir, 'font'));
\Tailor\Config::set('images_dir', path($assets_dir, 'img'));
\Tailor\Config::set('styles_dir', path($assets_dir, 'css'));
\Tailor\Config::set('scripts_dir', path($assets_dir, 'js'));
if (arg('b build')) {
    say("\n  \\cwhite,blue(**COMPILING**)\\c");
} else {
    say("\n  \\cwhite,magenta(**WATCHING**)\\c\n  Press \\bwhite(CTRL+C)\\b to exit");
}
say("\n  *From*: {$source_dir}\n    *To*: {$output_dir}\n");
$cache_file = path($target_dir, '.cache');
$cache = explode("\n", read($cache_file)) ?: array();
$timeout = (int) arg('t to') ?: 3;
if ($recreate) {
    require path(__DIR__, 'create_skeleton.php');
} elseif (arg('r reset')) {
    $cache = array();
    \IO\Dir::unfile($output_dir, '*', TRUE);
    is_dir($output_dir) or mkdir($output_dir, 0755, TRUE);
Esempio n. 3
0
 private static function extract($from, $on)
 {
     $out = array();
     is_file($from) or $from = \Tailor\Helpers::resolve($from, $on);
     if (!is_file($from)) {
         throw new \Exception("The file '{$from}' does not exists");
     }
     $ext = static::extension($on);
     $dir = \Tailor\Config::get($on);
     $url = \Tailor\Config::get(str_replace('_dir', '_url', $on));
     // TODO: accept other formats?
     if (preg_match_all('/\\s+\\*=\\s+(\\w+)\\s+(\\S+)/m', read($from), $match)) {
         foreach ($match[1] as $i => $key) {
             $tmp = path($dir, $match[2][$i]);
             $old = \Tailor\Helpers::findfile("{$tmp}*", 0);
             if (is_dir($old)) {
                 \IO\Dir::open($old, function ($file) use(&$out, $key) {
                     $out[$key][] = $file;
                 });
             } else {
                 if (!is_file($old)) {
                     $old = "{$url}/{$match[2][$i]}";
                     substr($old, -strlen($ext)) != $ext && ($old .= ".{$ext}");
                 }
                 $out[$key][] = $old;
             }
         }
     }
     return $out;
 }
Esempio n. 4
0
 public static function initialize(\Closure $lambda)
 {
     if (static::$loaded) {
         throw new \Exception("Application already loaded");
     }
     // request vars
     params($_REQUEST);
     // configuration
     config(path(APP_PATH, 'config.php'));
     config(path(APP_PATH, 'config', 'application.php'));
     config(path(APP_PATH, 'config', 'environments', APP_ENV . '.php'));
     // timezone
     date_default_timezone_set(option('timezone', 'UTC'));
     // setup
     $test = strtoupper(PHP_SAPI);
     if (strpos($test, 'CLI') === FALSE or $test === 'CLI-SERVER') {
         define('INDEX', basename(APP_LOADER));
         // root+uri
         $url = array();
         $url['ORIG_PATH_INFO'] = FALSE;
         $url['REQUEST_URI'] = FALSE;
         $url['SCRIPT_URL'] = TRUE;
         $url['PATH_INFO'] = FALSE;
         $url['PHP_SELF'] = TRUE;
         foreach ($url as $key => $val) {
             if (!isset($_SERVER[$key])) {
                 continue;
             }
             if (strpos($_SERVER[$key], INDEX) && $val === FALSE) {
                 continue;
             }
             $url = $_SERVER[$key];
             break;
         }
         $base = array();
         $base['ORIG_SCRIPT_NAME'] = TRUE;
         #$base['SCRIPT_FILENAME'] = TRUE;
         $base['SCRIPT_NAME'] = TRUE;
         $base['PHP_SELF'] = FALSE;
         foreach ($base as $key => $val) {
             if (!isset($_SERVER[$key])) {
                 continue;
             }
             if (strpos($_SERVER[$key], INDEX) && $val === FALSE) {
                 continue;
             }
             $base = $_SERVER[$key];
             break;
         }
         // site root
         $base = preg_replace('/' . preg_quote(INDEX) . '.*$/', '', $base);
         if (($root = server('DOCUMENT_ROOT')) != '/') {
             $base = str_replace($root, '.', $base);
         }
         define('ROOT', ltrim(str_replace(INDEX, '', $base), '.'));
         // URL cleanup
         $root = preg_quote(ROOT, '/');
         $index = preg_quote(INDEX, '/');
         $parts = explode('?', $url);
         $parts = preg_replace("/^(?:{$root}(?:{$index})?)?\$/", '', array_shift($parts));
         define('URI', '/' . trim($parts, '/'));
         if (empty($_SERVER['REQUEST_URI'])) {
             $_SERVER['REQUEST_URI'] = server('SCRIPT_NAME', server('PHP_SELF'));
             $_SERVER['REQUEST_URI'] .= $query = server('QUERY_STRING') ? "?{$query}" : '';
         }
         $base_url = \Postman\Request::host();
     } else {
         $parts = explode('/', option('base_url'));
         $root = '/' . join('/', array_slice($parts, 3));
         $base_url = join('/', array_slice($parts, 0, 3));
         // TODO: set URI/REQUEST_METHOD from CLI arguments...
         define('INDEX', option('index_file') ?: 'index.php');
         define('ROOT', $root ?: '/');
         define('URI', '/');
         $_SERVER['REQUEST_URI'] = URI;
         $_SERVER['REQUEST_METHOD'] = 'GET';
         $_SERVER['DOCUMENT_ROOT'] = APP_PATH;
     }
     // assets
     if (APP_ENV != 'production') {
         $doc_root = $base_url . ROOT . '?@=';
     } elseif (!($doc_root = option('asset_host'))) {
         if ($doc_root = option('asset_subdomain')) {
             $doc_root = \Broil\Helpers::reduce($base_url, $doc_root);
         } else {
             $doc_root = $base_url . ROOT . 'static';
         }
     }
     \Tailor\Config::set('fonts_url', "{$doc_root}/font");
     \Tailor\Config::set('images_url', "{$doc_root}/img");
     \Tailor\Config::set('styles_url', "{$doc_root}/css");
     \Tailor\Config::set('scripts_url', "{$doc_root}/js");
     // templating
     \Tailor\Config::set('cache_dir', path(APP_PATH, 'app', 'cache'));
     \Tailor\Config::set('views_dir', path(APP_PATH, 'app', 'views'));
     \Tailor\Config::set('fonts_dir', path(APP_PATH, 'app', 'assets', 'font'));
     \Tailor\Config::set('images_dir', path(APP_PATH, 'app', 'assets', 'img'));
     \Tailor\Config::set('styles_dir', path(APP_PATH, 'app', 'assets', 'css'));
     \Tailor\Config::set('scripts_dir', path(APP_PATH, 'app', 'assets', 'js'));
     // web goodies
     \Labourer\Config::set('csrf_salt', '');
     \Labourer\Config::set('csrf_token', '');
     \Labourer\Config::set('csrf_expire', 300);
     \Labourer\Config::set('session_path', ROOT);
     \Labourer\Config::set('session_expire', 3600);
     \Labourer\Config::set('upload_path', path(APP_PATH, 'static', 'uploads'));
     \Labourer\Config::set('upload_type', 'image/*');
     \Labourer\Config::set('upload_min_size', 96);
     \Labourer\Config::set('upload_max_size', 2097152);
     \Labourer\Config::set('upload_extension', array('jpeg', 'jpg', 'png', 'gif', 'ico'));
     \Labourer\Config::set('upload_skip_error', FALSE);
     \Labourer\Config::set('upload_multiple', TRUE);
     \Labourer\Config::set('upload_unique', TRUE);
     \Labourer\Config::set('s3_key', '');
     \Labourer\Config::set('s3_secret', '');
     \Labourer\Config::set('s3_bucket', '');
     \Labourer\Config::set('s3_location', FALSE);
     \Labourer\Config::set('s3_permission', 'public_read');
     // database
     \Grocery\Config::set('unserialize', APP_ENV === 'production' ? 'ignore' : 'reset');
     \Servant\Config::set('default', 'sqlite::memory:');
     // caching
     \Cashier\Config::set('cache_dir', TMP);
     \Cashier\Config::set('driver', option('cache', 'php'));
     // connections
     if ($test = option('database')) {
         foreach ($test as $key => $val) {
             \Servant\Config::set($key, $val, APP_ENV === 'production');
         }
     }
     // debug sql
     \Grocery\Config::set('logger', function ($sql, $ms) {
         $sql = preg_replace('/\\s+/', ' ', $sql);
         \Sauce\Logger::info("{$sql} ({$ms})");
     });
     // start up
     \Tailor\Base::initialize();
     \Labourer\Base::initialize();
     // routing
     \Broil\Config::set('root', ROOT);
     \Broil\Config::set('index_file', INDEX);
     \Broil\Config::set('rewrite', option('rewrite'));
     \Broil\Config::set('request_uri', URI);
     \Broil\Config::set('request_method', method());
     \Broil\Config::set('server_base', $base_url);
     \Broil\Config::set('tld_size', option('tld_size'));
     // load routes
     $routes_file = path(APP_PATH, 'config', 'routes.php');
     is_file($routes_file) && (require $routes_file);
     // before any initializer?
     foreach (static::$middleware as $callback) {
         $lambda = $callback($lambda);
     }
     // scripts
     $init_path = path(APP_PATH, 'config', 'initializers');
     if (is_dir($init_path)) {
         \IO\Dir::open($init_path, function ($path) {
             require is_dir($path) ? path($path, 'initialize.php') : $path;
         });
     }
     // go!
     static::$loaded = TRUE;
     static::$response = new \Postman\Response();
     return \Sauce\App\Bootstrap::initialize($lambda);
 }