定制 halaabusalim/laravel-dynamic-placeholder 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

halaabusalim/laravel-dynamic-placeholder

最新稳定版本:v1.0.0

Composer 安装命令:

composer require halaabusalim/laravel-dynamic-placeholder

包简介

A Laravel package to generate context-aware placeholder content.

README 文档

README

A Laravel package to generate context-aware placeholder content for your applications.

Installation

  1. Install the package via Composer:
composer require halaabusalim/laravel-dynamic-placeholder
  1. Publish the configuration file:
php artisan vendor:publish --provider="Halaabusalim\LaravelDynamicPlaceholder\DynamicPlaceholderServiceProvider" --tag="config"

Usage

Using the Facade

use Halaabusalim\LaravelDynamicPlaceholder\Facades\DynamicPlaceholder;

// Generate text placeholders
$productName = DynamicPlaceholder::text('ecommerce.product_name');
$blogTitle = DynamicPlaceholder::text('blog.title');

// Generate number placeholders
$price = DynamicPlaceholder::number('ecommerce.price');

// Generate image placeholders
$imageUrl = DynamicPlaceholder::image('product-image');

Using Dependency Injection

use Halaabusalim\LaravelDynamicPlaceholder\DynamicPlaceholder;

class ProductController extends Controller
{
    public function __construct(private DynamicPlaceholder $placeholder)
    {
    }

    public function index()
    {
        $productName = $this->placeholder->text('ecommerce.product_name');
        $price = $this->placeholder->number('ecommerce.price');
        
        return view('products.index', compact('productName', 'price'));
    }
}

Configuration

The package comes with a configuration file that you can customize. Edit config/dynamic-placeholder.php:

return [
    'contexts' => [
        'ecommerce' => [
            'product_name' => ['Laptop', 'Smartphone', 'Headphones', 'Smartwatch'],
            'description' => [
                'High-performance device for professionals.',
                'Sleek design with cutting-edge technology.',
                'Perfect for everyday use.'
            ],
            'price' => ['min' => 50, 'max' => 1000],
        ],
        'blog' => [
            'title' => ['Top 10 Tips for Success', 'How to Start a Blog', 'The Future of Tech'],
            'content' => ['Lorem ipsum dolor sit amet...', 'In this article, we explore...'],
        ],
    ],
];

Methods

text(string $context): string

Returns a random text from the configured context.

number(string $context): float

Returns a random number within the configured range.

image(string $context): string

Returns a placeholder image URL (currently uses via.placeholder.com).

Testing

Running Tests

  1. Unit Tests with PHPUnit:
./vendor/bin/phpunit
  1. Manual Testing:
php test-manual.php

Test Coverage

The test suite covers:

  • ✅ Text placeholder generation
  • ✅ Number placeholder generation with ranges
  • ✅ Image placeholder URL generation
  • ✅ Error handling for missing contexts
  • ✅ Facade functionality
  • ✅ Service provider registration
  • ✅ Configuration merging
  • ✅ Singleton pattern verification

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-28