public function register(Application $app) { parent::register($app); $config = $app['config']; $app['handlebars'] = $app->share(function ($app) use($config) { $templatePathConfigPath = 'template.handlebars.path'; if (!Arr::path($config, $templatePathConfigPath)) { Arr::setPath($config, $templatePathConfigPath, APP_PATH . '/templates'); } return new Handlebars(['loader' => new FilesystemLoader(Arr::path($config, $templatePathConfigPath), ['extension' => '.hbs']), 'partials_loader' => new FilesystemLoader(Arr::path($config, $templatePathConfigPath), ['prefix' => '_'])]); }); $app['config'] = $config; }
/** * Retrieves multiple paths from an array. If the path does not exist in the * array, the default value will be added instead. * * // Get the values "username", "password" from $_POST * $auth = Arr::extract($_POST, array('username', 'password')); * * // Get the value "level1.level2a" from $data * $data = array('level1' => array('level2a' => 'value 1', 'level2b' => 'value 2')); * Arr::extract($data, array('level1.level2a', 'password')); * * @param array $array array to extract paths from * @param array $paths list of path * @param mixed $default default value * @return array */ public static function extract($array, array $paths, $default = null) { $found = []; foreach ($paths as $path) { Arr::setPath($found, $path, Arr::path($array, $path, $default)); } return $found; }