andresilva/clipboard
Composer 安装命令:
composer require andresilva/clipboard
包简介
Cut, copy and paste values inside your app.
README 文档
README
Copy, cut & paste in your application. You read that right.
use Laragear\Clipboard\Facades\Clipboard; public function foo() { Clipboard::copy('test'); } public function bar() { Clipboard::paste(); // 'test' }
Become a sponsor
Your support allows me to keep this package free, up-to-date and maintainable. Alternatively, you can spread the word!
Requirements
- PHP 8 or later
- Laravel 9, 10 or later
Installation
You can install the package via composer:
composer require laragear/clipboard
Usage
The Clipboard works like your normal clipboard in your application.
| Method | Description |
|---|---|
copy() |
Copies a value into the clipboard. |
cut() |
Moves a value into the clipboard, assigning it null on the current context. |
clone() |
Clones an object into the clipboard. |
paste() |
Pastes a value previously copied in the clipboard. |
pull() |
Pastes a value previously copied, removing it from the Clipboard. |
clear() |
Clears the clipboard value. |
Using the Clipboard to move around values inside the application allows you to avoid registering things into the Service Container unnecessarily, or moving a value around using functions or the cache.
Copy and paste
Copying a value will copy the reference of the object, or the value if is a primitive like a string, int or an array, among others. It works like any other function.
use Laragear\Clipboard\Facades\Clipboard; use App\Models\Article; $article = Article::find(5); // Copy a value Clipboard::copy($article); // Edit the reference after has been copied. $article->title = 'The new title!';
Pasting will paste the value how many times you want. It accepts a default value in case the clipboard is empty.
// Paste a value Clipboard::paste()->title; // 'The new title'
Clone
Sometimes you may want to actually clone the object instead of copy its reference. For these cases, use the clone() method.
use Laragear\Clipboard\Facades\Clipboard; use App\Models\Article; $article = Article::make(['title' => 'Original title']); // Clone an object Clipboard::clone($article);
Since it's a clone, the original variable will be different from the one pasted afterward.
$article->title = 'Different title'; echo Clipboard::paste()->title; // "Original title"
Cut and pull
Cut works like copy, but the value in the current context will be assigned null.
use Laragear\Clipboard\Facades\Clipboard; $article = 'This is a big wall of text.'; // Cut a value Clipboard::cut($article); echo $article; // ''
Meanwhile, pull(), will retrieve the value from the Clipboard and remove it from there. It accepts a default value in case the clipboard is empty.
use Laragear\Clipboard\Facades\Clipboard; $text = Clipboard::pull(); echo $text; // 'This is a big wall of text.'
Clearing
You can clear the Clipboard anytime using clear():
use Laragear\Clipboard\Facades\Clipboard; Clipboard::copy('I am going to dissapear.'); Clipboard::clear(); echo Clipboard::paste(); // ''
Method pass-through
For your convenience, you don't need to retrieve the Clipboard object to do something. The Clipboard will pass through all methods calls to the copied or cloned object.
use Laragear\Clipboard\Facades\Clipboard; use App\Models\Article; $article = Article::make(['title' => 'Original title']); // Copy a value Clipboard::copy($article); // Some lines after... Clipboard::save();
How this works?
It just registers a singleton that holds a value during the life of the request, or the entirety of the command. That's it.
Laravel Octane compatibility
- There are no singletons using a stale application instance.
- There are no singletons using a stale config instance.
- There are no singletons using a stale request instance.
- There are no static properties written during a request.
There should be no problems using this package with Laravel Octane.
Security
If you discover any security related issues, please email darkghosthunter@gmail.com instead of using the issue tracker.
License
This specific package version is licensed under the terms of the MIT License, at time of publishing.
Laravel is a Trademark of Taylor Otwell. Copyright © 2011-2023 Laravel LLC.
Happy April's Fools y'all!
andresilva/clipboard 适用场景与选型建议
andresilva/clipboard 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 56 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 05 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 andresilva/clipboard 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 andresilva/clipboard 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 56
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-05-09
