acidjazz/larjectus

为Laravel和Lumen添加objectus的强大功能

v0.9 2016-09-05 06:47 UTC

This package is auto-updated.

Last update: 2024-08-29 04:03:37 UTC


README

允许您在Laravel 5和Lumen中无缝使用Objectus

Total Downloads Latest Stable Version License Build Status Dependency Status Coverage Status codecov Codacy Badge

这是做什么的

  • 将您的.envconfig/选项与您想要添加到config/中的任意数量的YAML和JSON文件和目录结合
  • 允许在您的resources/public/文件夹可能使用的任何语言中共享这些数据的功能

为什么我要使用这个

我的大多数项目都有扩展配置,从样式指南到网站副本,这允许stylus/css和coffeescript/javascript访问这些数据

要求

安装

使用Composer安装此包

composer require acidjazz/larjectus

Laravel

一旦Composer安装或更新了您的包,您需要将Larjectus注册到Laravel本身。打开config/app.php,找到providers键,在文件末尾,并添加'larjectus\serviceprovider'到末尾

'providers' => [
  ...
    Larjectus\ServiceProvider::class,
],

Lumen

对于与Lumen的使用,在bootstrap/app.php中添加服务提供者。

$app->register(Larjectus\ServiceProvider::class);

配置

gulpfile.js示例

您的gulp任务与Objectus的工作方式不同,这里是一个将您的配置编译为JavaScript版本以供JavaScript访问的示例

🚨 注意secure数组,其中我移除了任何安全数据,如数据库密码和AWS凭证。 🚨

exec = require('child_process').exec;

objectify = function() {
  var config, secure;
  config = {};
  secure = ['auth', 'database'];
  return exec('php artisan larjectus:config', function(error, result, stderr) {
    var dim, i, len, pubconfig;
    if (error) {
      notify(error);
    }
    this.config = JSON.parse(result);
    pubconfig = this.config;
    for (i = 0, len = secure.length; i < len; i++) {
      dim = secure[i];
      delete pubconfig[dim];
    }
    return fs.writeFileSync('public/js/config.js', "config="+JSON.stringify(pubconfig)+";", 'utf8');
  });
};

objectify();

gulp.task('larjectus', objectify);

gulp.task('watch', function() {
  gulp.watch('config/**/*', ['larjectus']);
);

以下是一个将配置访问权授予stylus的示例,您将需要上面的示例gulp任务

stylus = require('gulp-stylus');

gulp.task('stylus', function() {
  return gulp.src('resources/stylus/main.styl')
    .pipe(stylus({
      rawDefine: {
        config: config
      }
    }).on('error', notify.onError(function(error) {
      return {
        title: 'Stylus error: ' + error.name,
        message: error.message,
        sound: 'Pop'
      };
    })))
  .pipe(gulp.dest('public/css/'))
  .pipe(sync.stream());
}