标签: service-provider

Laravel - 通过app-> bind传递参数到模型的构造函数

嗯,代码描述了这一切.我有一个实体服务提供程序,它传递一个播放列表模型的实例,它应该得到一个数组作为它的第一个构造函数参数.如何通过app-> bind传递该参数?知道EntityServiceProvider在控制器中引用时会自动注入.

        // Current Code
        /**
         * Playlist Entity
         *
         * @return Playlist\PlaylistEntity
         */
        $this->app->bind('Playlist\PlaylistEntity', function($app)
        {
            return new PlaylistEntity($app->make('Playlist\PlaylistRepositoryInterface'));
        });



        // Should be something like this:
        /**
         * Playlist Entity
         *
         * @return Playlist\PlaylistEntity
         */
        $this->app->bind('Playlist\PlaylistEntity', function($app)
        {
            return new PlaylistEntity($app->make('Playlist\PlaylistRepositoryInterface', $parameters));
        });
Run Code Online (Sandbox Code Playgroud)

类似案例:Laravel 4:将数据从make传递给服务提供者

entity service-provider laravel

6
推荐指数
1
解决办法
7437
查看次数

SP元数据:用于签名和加密的证书

规范说:

OASIS安全断言标记语言(SAML)V2.0的元数据

2.4.1.1元素 <KeyDescriptor>

<KeyDescriptor>元素提供有关实体用于签名数据或接收加密密钥的加密密钥的信息,以及其他加密详细信息.其 KeyDescriptorType复杂类型包含以下元素和属性:

use[可选的]

可选属性,指定所描述的密钥的用途.值是从KeyTypes枚举中提取的,由值encryption和值组成signing.

<ds:KeyInfo>[需要]

直接或间接标识密钥的可选元素.

据我所知,为了向两个方向发送安全数据,我应该:

  1. 我自己的私钥
  2. 我自己的公钥
  3. 收件人的公钥

我应该在SP元数据中指定什么密钥的证书,并且我可以使用相同的证书进行签名和加密?

IdP的供应商提供了所谓的"元数据模板",其中指出了应该拼写的内容和位置.

这是相关部分(逐字):

...
<md:KeyDescriptor use="signing"> 
   <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> 
      <ds:X509Data> 
         <ds:X509Certificate> 
            <!--
             TODO It is necessary to insert here the certificate of the signature 
             key of the service provider in X509 DER format and Base64 encoded
             --> 
          </ds:X509Certificate> 
      </ds:X509Data> 
   </ds:KeyInfo> 
</md:KeyDescriptor> 

<md:KeyDescriptor use="encryption"> 
   <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> 
      <ds:X509Data> 
         <ds:X509Certificate> 
            <!--
             TODO It is necessary to insert here the certificate of …
Run Code Online (Sandbox Code Playgroud)

cryptography shibboleth service-provider saml-2.0

6
推荐指数
1
解决办法
5398
查看次数

困惑 - AppServiceProvider.php与app.php

我在哪里准确指定我的绑定?我似乎可以在这些文件中的任何一个中执行此操作.

config/app.php 里面'providers' =>

app/Providers/AppServiceProvider.php 里面register()

service-provider laravel laravel-5

6
推荐指数
2
解决办法
4162
查看次数

Laravel包注册异常处理程序

我想知道是否可以在Laravel 5的包中注册第二个异常处理程序.

我有一个包(让我们称之为api-serializer)注册一个中间件来将所有请求转换为JSON(对于一个API)和这个包注册2个助手:success()并且failure()在发生错误时(或不发生)特别处理json.

在我的应用程序异常处理程序中,我执行以

/**
 * Render an exception into an HTTP response.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  \Exception  $e
 * @return \Illuminate\Http\Response
 */
public function render($request, Exception $e)
{
    return failure($e->getMessage());
}
Run Code Online (Sandbox Code Playgroud)

现在我有第二个包(让我们称之为tumblr-api),它可以进行http调用并引发异常,例如:

throw (new CustomCoolException)->setModel($model);
Run Code Online (Sandbox Code Playgroud)

我想以不同的方式对待这个异常,因为消息位于,$model像这样做:

if ($e instanceof CustomCoolException) {
    return failure($e->getModel()->getMessage());
}
Run Code Online (Sandbox Code Playgroud)

什么我不想做这是我的包例外添加到我的主要异常处理程序,因为他们会紧密绑定.

我既不想在暴露的api-serializersuccess()failure()我的tumblr-api包之间创建依赖关系.

是否有可能从我的api-serializer注册第二个ExceptionHandler或为它的异常添加特定的开关而不改变其他任何东西?

我想让我的tumblr-api包尽可能独立,所以安装它的用户只需注册服务提供商即可!

php service-provider laravel-5

6
推荐指数
1
解决办法
1491
查看次数

简单的Java"服务提供者框架"?

我指的是有效Java第2章中讨论的"服务提供者框架" ,这似乎是处理我遇到的问题的正确方法,我需要在运行时实例化几个类中的一个,基于a String选择哪个服务和Configuration对象(本质上是一个XML片段):

但是,我如何让各个服务提供商(例如一堆默认提供商+一些自定义提供商)进行自我注册?

 interface FooAlgorithm
 {
     /* methods particular to this class of algorithms */
 }

 interface FooAlgorithmProvider
 {
     public FooAlgorithm getAlgorithm(Configuration c);
 }

 class FooAlgorithmRegistry
 {
     private FooAlgorithmRegistry() {}
     static private final Map<String, FooAlgorithmProvider> directory =
        new HashMap<String, FooAlgorithmProvider>();
     static public FooAlgorithmProvider getProvider(String name)
     {
         return directory.get(serviceName);
     }
     static public boolean registerProvider(String name, 
         FooAlgorithmProvider provider)
     {
         if (directory.containsKey(name))
            return false;
         directory.put(name, provider);
         return true;
     }
 }
Run Code Online (Sandbox Code Playgroud)

例如,如果我编写自定义类MyFooAlgorithm和MyFooAlgorithmProvider来实现FooAlgorithm,并将它分发到jar中,是否有任何方法可以自动调用registerProvider,或者我使用该算法的客户端程序是否必须显式调用FooAlgorithmRegistry.registerProvider( )他们想要使用的每个班级?

java factory service-provider

5
推荐指数
1
解决办法
4403
查看次数

我是否应该要求IdP签署SAML2 SSO回复?

我们的应用程序具有SAML2 SSO与3种不同(Shibboleth)IdP的集成.我们正在尝试添加第4个(也是Shibboleth),但遇到了一些问题,因为我们的应用程序希望所有SSO响应都可以验证签名.这些其他3个正在签署他们的回复,但第4个不是,并且犹豫是否添加自定义配置来强制执行我们的应用程序的签名.

从技术上讲,我可以修改我们的应用程序以接受未签名的SSO响应,但我想知道我是否应该.允许未签名的SSO响应有哪些缺陷?有安全漏洞吗?

是否有任何Shibboleth(或其他SAML2 SSO)文档建议将响应作为最佳实践进行签名?

signing shibboleth single-sign-on service-provider saml-2.0

5
推荐指数
1
解决办法
2665
查看次数

向构造函数注入几个参数是不好的做法吗?

我正在开发一个相当复杂的物流管理系统,该系统将继续发展成其他几个与ERP相关的模块.因此,我正在努力实现尽可能多的SRP和开放/封闭原则,以便于扩展和基于域的管理.

因此,我决定使用Laravel和以下模式(不确定它是否有名称):

我将使用PRODUCT对象作为我的示例.对象/实体/域具有类 class ProductService {}

此类有一个服务提供程序,它包含在providers数组中,并且也是自动加载的: ProductServiceServiceProvider

服务提供者实例化(制作)ProductRepository哪个是接口.该接口当前有一个称为EloquentProductRepository实现的MySQL(和一些Eloquent),并且ProductRepositoryServiceProvider绑定了也加载并在providers数组中的实现.

现在,产品与其他域有许多不同的属性和关系,因为其他域(或实体)需要完全分离并再次遵守上述原则(SRP等).我决定对它们也有相同的结构.我为产品做的...我知道有些人可能认为这太多了,但我们需要让系统非常可扩展,说实话我喜欢有条理并且有一个统一的模式(它不需要更多时间,并节省了我很多).

我的问题是这个.处理Product的所有业务逻辑并使"Product"成为现实的ProductService将通过构造函数在创建它的实例时注入几个依赖项.

这就是它目前所拥有的:

namespace Ecommerce\Services\Product;

use Ecommerce\Repositories\Product\ProductRepository;
use Ecommerce\Services\ShopEntity\ShopEntityDescriptionService;
use Content\Services\Entity\EntitySeoService;
use Content\Services\Entity\EntitySlugService;
use Ecommerce\Services\Tax\TaxService;
use Ecommerce\Services\Product\ProductAttributeService;
use Ecommerce\Services\Product\ProductCustomAttributeService;
use Ecommerce\Services\Product\ProductVolumeDiscountService;
use Ecommerce\Services\Product\ProductWeightAttributeService;
use Ecommerce\Services\Product\ProductDimensionAttributeService;

/**
 * Class ProductService
 * @package Ecommerce\Services\Product
 */
class ProductService {

    /**
     * @var ProductRepository
     */
    protected $productRepo;

    /**
     * @var ShopEntityDescriptionService
     */
    protected $entityDescription;

    /**
     * @var EntitySeoService
     */
    protected $entitySeo;

    /**
     * @var EntitySlugService
     */
    protected $entitySlug;

    /** …
Run Code Online (Sandbox Code Playgroud)

php constructor service-provider laravel laravel-4

5
推荐指数
1
解决办法
1479
查看次数

如何在课堂上访问Laravel Singletons?

我在服务提供商中注册了一个单身人士,如下所示:

$this->app->singleton(MyClass::class);
Run Code Online (Sandbox Code Playgroud)

通常只需在参数中声明它就可以访问它:

class FooController extends Controller
{
    public function index(MyClass $myClass)
    {
        //...
    }
}
Run Code Online (Sandbox Code Playgroud)

但是我似乎无法在其他自定义类(即非控制器类)中访问此单例.(https://laravel.com/docs/5.2/container#resolving)

比如像这里:

class Bar {
   private $myClass;
   private $a;
   private $b;

   public function __construct($a, $b) {
      $this->a = $a;
      $this->b = $b;
      $this->myClass = ... // TODO: get singleton
   }
}
Run Code Online (Sandbox Code Playgroud)

我该怎么做呢?

请注意,我将创建多个实例Bar.

php service-provider laravel laravel-5

5
推荐指数
2
解决办法
7571
查看次数

Laravel 5.2外观getFacadeAccessor返回什么

因此,我正在努力创建我的第一个服务提供商和Laravel的免费Facade.

服务提供者:

<?php namespace Jbm\Providers;

use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;
use Illuminate\Support\ServiceProvider as BaseServiceProvider;

use Jbm\Helpers\ReportGenerator;

class ReportGeneratorServiceProvider extends BaseServiceProvider
{
    /**
     * Indicates if loading of the provider is deferred.
     *
     * @var bool
     */
    protected $defer = true;

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $this->app->bind('Jbm\Helpers\Contracts\ReportGeneratorContract', function($app){
            return new ReportGenerator();
        });
    }

    /**
     * Add the Cors middleware to the router.
     *
     * @param Kernel $kernel
     */
    public function boot(Request $request, …
Run Code Online (Sandbox Code Playgroud)

php facade service-provider laravel

5
推荐指数
1
解决办法
2524
查看次数

如何在laravel中使用RouteServiceProvider添加多个路由文件

我想创建模块明智的路由文件并使用 RouteServiceProvider mapApiRoutes() 加载所有路由文件。我创建了 category.php 文件和 admin.php 文件,其中包含其中的路由。现在我想在 api.php 文件中加载这两个文件的路由。

下面是我用来执行此操作的代码,但它不起作用。它只处理 admin.php 中的路由。当我使用category.php 的路由时,它显示“抱歉,找不到您要查找的页面。”的错误。提前感谢您的帮助。

protected function mapApiRoutes()
{
    Route::prefix('api')
         ->middleware('api')
         ->namespace($this->namespace)
         ->group(
                base_path('routes/admin.php'),
                base_path('routes/category.php'),
                base_path('routes/api.php')
              );
}
Run Code Online (Sandbox Code Playgroud)

php routes service-provider laravel-5.6

5
推荐指数
1
解决办法
2325
查看次数