コード例 #1
0
ファイル: app.php プロジェクト: agoemans/EatOut
use Assetic\Asset\FileAsset;
use Assetic\Asset\GlobAsset;
use Assetic\AssetManager;
use Assetic\Asset\AssetCache;
use Assetic\Cache\FilesystemCache;
use Shrubbery\QueryProcesor;
use Shrubbery\RestaurantProcessor;
use Shrubbery\Config;
$app = new Silex\Application();
$app['debug'] = true;
$app['asset_path'] = 'views';
//todo move this to a separate function
$bundles = array(new Symfony\Bundle\AsseticBundle\AsseticBundle());
$styles = new FileAsset('./vendor/twitter/bootstrap/dist/css/bootstrap.css');
$cache = new AssetCache($styles, new FilesystemCache('./views/cache'));
$cache->setTargetPath('bootstrap.css');
$writer = new AssetWriter('./views/assets');
$writer->writeAsset($cache);
//end todo
$getRestaurantList = new RestaurantProcessor();
$jsonObj = $getRestaurantList->readFromDatabase();
//Section for adding configuration
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../templates'));
$twig = $app['twig'];
$twig->addExtension(new \Entea\Twig\Extension\AssetExtension($app));
$app->get('/', function (Request $request) use($app) {
    $output = '';
    $finalList = '';
    $apiKey = '';
    $ini_Obj = parse_ini_file("data.ini", true);
    $apiKey = $ini_Obj["apiKey"];
コード例 #2
0
ファイル: Controller.php プロジェクト: hlfcoding/hlf-ndxz
 protected function processAssets()
 {
     // - Alias.
     $p = $this->paths;
     $app_name = $this->app_name;
     $af = $this->asset_factory;
     $fm = $this->asset_factory->getFilterManager();
     $am = $this->asset_manager;
     $ac = $this->asset_cache;
     // - During debugging, assets aren't minified and so are named differently.
     $min = $this->debug ? '' : '.min';
     // - Initialize `app_assets` and `theme_assets`. We can do this because PHP
     //   arrays are assign-by-copy by default.
     $app_assets = $theme_assets = array('coffee' => array(), 'css' => array(), 'js' => array());
     // - Populate optional assets via `addOptionalAssets`. For Silex
     //   `app_assets`, if the configuration option group `view` exists in the
     //   application scope, assume its asset-properties are set and specifying
     //   optional assets. For application `theme_assets`, the same applies if
     //   the configuration option group `view` exists in the theme scope.
     if (isset($this->options['view'])) {
         $this->addOptionalAssets($app_assets, $this->options['view']);
     }
     if (isset($this->theme_options) && isset($this->theme_options['view'])) {
         $this->addOptionalAssets($theme_assets, $this->theme_options['view']);
     }
     // - `css_assets` is the final array of Assetic asset and asset collection
     //   objects that represents the list of stylesheets to be compiled in the
     //   final distribution stylesheet. It should tentatively be empty for
     //   assets to be handled via S3 on prod. It starts off with the merged
     //   result of the base library and application stylesheets, as well as the
     //   optional library stylesheets for the application and theme, even if
     //   there aren't any.
     $css_assets = $this->is_prod ? array() : array_merge(array(new GlobAsset(array("{$p['lib_web']}/css/*.css")), new FileAsset("{$p['app_web']}/scss/style.scss", array($fm->get('scss')))), $app_assets['css'], $theme_assets['css']);
     // - Run the `willRegisterCSSAssets` hook to transform `css_assets` and get
     //   an updated `css_modifier` for the filename, though it may still be
     //   empty.
     list($css_assets, $css_modifier) = $this->willRegisterCSSAssets($css_assets);
     // - Add the stylesheet for the theme if needed.
     if ($this->is_themable) {
         $css_assets[] = new FileAsset("{$p['theme_web']}/scss/style.scss", array($fm->get('scss')));
     }
     // - Our `css_filters` only has the optional minifier when not debugging.
     $css_filters = $this->debug ? array() : array($fm->get('cssmin'));
     // - Our `css_cache` wraps around our assets and filters for distribution.
     //   Tie it to `asset_cache`. Build our distribution filename. And export it
     //   to `asset_manager`.
     $css_cache = new AssetCache(new AssetCollection($css_assets, $css_filters), $ac);
     $css_cache->setTargetPath("{$app_name}{$css_modifier}.compiled{$min}.css");
     $am->set('all_css', $css_cache);
     // - Finally, add an `asset_urls` entry for `css`.
     $this->asset_urls['css'][] = "/dist/{$css_cache->getTargetPath()}";
     // - `js_assets` is the final collection of arrays of Assetic asset and
     //   asset collection objects. The arrays are labeled by section and
     //   represent the list of scripts to be compiled in the final distribution
     //   script for each section. The arrays should tentatively be empty for
     //   assets to be handled via S3 on prod.
     $js_assets = array();
     // - Add a `head` section with just the scripts in the `js/head`
     //   subdirectory of the `lib_web` path.
     $js_assets['head'] = $this->is_prod ? array() : array(new GlobAsset(array("{$p['lib_web']}/js/head/*.js")));
     // - Add a `lib` section with the root-level scripts in the `js`
     //   subdirectory of the `lib_web` path. Also include any scripts in the
     //   `js/development` subdirectory. Lastly, include any root-level scripts
     //   in the `coffee` subdirectory. Note the passing in of the `coffee`
     //   filter.
     $js_assets['lib'] = $this->is_prod ? array() : array(new GlobAsset(array("{$p['lib_web']}/js/*.js", "{$p['lib_web']}/js/development/*.js")), new GlobAsset(array("{$p['lib_web']}/coffee/*.coffee"), array($fm->get('coffee'))));
     // - Add a `main` section. Include the optional library scripts (js and
     //   coffee) for the application and theme. Note that this isn't in the
     //   `lib` section to ensure the lib distribution file stays consistent
     //   across requests.
     $js_assets['main'] = $this->is_prod ? array() : array_merge($app_assets['coffee'], $app_assets['js'], array(new GlobAsset(array("{$p['app_web']}/coffee/*.coffee", "{$p['app_web']}/coffee/main.coffee", "{$p['app_web']}/coffee/**/*.coffee"), array($fm->get('coffee')))), $theme_assets['coffee'], $theme_assets['js']);
     // - Run the `willRegisterJSAssets` hook to transform `js_assets` and get an
     //   updated `js_modifiers` for the filenames that's labeled by the section
     //   names, though they may still be empty.
     list($js_assets, $js_modifiers) = $this->willRegisterJSAssets($js_assets);
     // - Add the script for the theme if needed to `main`.
     if ($this->is_themable) {
         $js_assets['main'][] = new GlobAsset("{$p['theme_web']}/coffee/*.coffee", array($fm->get('coffee')));
     }
     // - Our `js_filters` only has the optional minifier when not debugging.
     $js_filters = $this->debug ? array() : array($fm->get('jsmin'));
     // - `js_map` transforms the section names into filename modifiers.
     $js_map = array('head' => 'head', 'lib' => 'lib', 'main' => '');
     // - For each section, set `js_cache` to wrap around our assets and filters
     //   for distribution. Tie it to `asset_cache`. Build our distribution
     //   `file_modifier` and filename. And export it to `asset_manager`.
     //   Finally, add an `asset_urls` entry by a hard-coded map depending on
     //   section name.
     foreach ($js_map as $name => $file_modifier) {
         $js_cache = new AssetCache(new AssetCollection($js_assets[$name], $js_filters), $ac);
         $file_modifier = !empty($file_modifier) ? "-{$file_modifier}" : '';
         $file_modifier .= isset($js_modifiers[$name]) ? $js_modifiers[$name] : '';
         $js_cache->setTargetPath("{$app_name}{$file_modifier}.compiled{$min}.js");
         $am->set("{$name}_js", $js_cache);
         if ($name === 'head') {
             $this->asset_urls['head_js'][] = "/dist/{$js_cache->getTargetPath()}";
         } else {
             $this->asset_urls['js'][] = "/dist/{$js_cache->getTargetPath()}";
         }
     }
     // - Finally, have `asset_writer` write to disk the assets from
     //   `asset_manager`. However, on prod, this is tentatively unneeded due to
     //   S3 handling.
     if (!$this->is_prod) {
         $this->asset_writer->writeManagerAssets($am);
     }
 }