我正在开发一个相当复杂的物流管理系统,该系统将继续发展成其他几个与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) 我有一个基本的调查生成器,如果用户指定问题需要从列表(下拉列表)中选择一个答案,那么每个可能的答案都需要保存在数据库中。
因此,我的视图有一个文本区域,管理员可以输入可用的答案并用换行符分隔它们。我需要提取该文本(逐行)并保存在数组中,以便我的模型可以为每个项目创建一行。
我唯一的问题是如何分隔每一行并保存为数组。该视图实际上是一个弹出窗口,数据是使用 Ajax 发送的,因此最简单的方法是将整个值作为一个输入发送到控制器,然后在 PHP 中将其分开。我想知道 Laravel 是否有为此准备的函数,或者我是否应该使用标准 PHP,例如 str_replace 等......