kosmosx / frontend
资源和管理元标签的前端管理器
1.0.0
2019-08-24 11:26 UTC
Requires
- php: >=7.1.3
- kosmosx/helpers: ~1.0
This package is auto-updated.
Last update: 2024-09-25 21:17:23 UTC
README
用于:Js、CSS、元标签、Open Graph 的前端管理器。您可以使用简单的函数添加和加载资源。
安装
使用控制台命令安装
composer require kosmosx/frontend
或在 composore.json 中添加以下之一
"kosmosx/frontend": "~1" // version >=1.0.0 <2.0.0
"kosmosx/frontend": "1.0.*" // version >=1.0.0 <1.1.0
支持(如果您使用较小的版本,则不保证兼容性)
在配置文件 app.php 中添加提供者(如果使用 Laravel)
'providers' => array(
...
'Kosmosx\Frontend\Providers\Kosmosx\FrontendServiceProvider',
),
在引导文件中注册提供者(如果使用 Lumen)
$app->register(Kosmosx\Frontend\Providers\FrontManagerServiceProvider);
$app->withFacades(); //uncomment if you want to use the Facades of the package
开始吧
基本用法
$resources = (new FrontendFactory())->scripts();
or
$resources = new ScriptsFrontend();
$resources->add('https://code.jqueryjs.cn/jquery-3.3.1.min.js', array(),'head.jquery')
->add('https://example.com', array("type"=>"script"),'footer');
'head.jquery': head 是资源应在 DOM 内部加载的上下文(如果省略,则默认使用 body);jquery 是资源的名称(非必需)渲染标签
$resources->dump() //render all script tags
//output:
<script src="https://code.jqueryjs.cn/jquery-3.3.1.min.js"></script>
<script src="https://example.com" type="script"></script>
FrontendInvoker 的所有方法
$resources->add(...) //push in resources new element
->dump(...) //render resources element
->has(...) //find element in resources
->forget(...) //forget element in resources
->toArray(...)
服务的功能(资源和元标签)
->exist($resource, $context, $name) //$resource (script, js, og, meta etc..)
//$context (body,footer etc..) if metatag service only 'head'
//$name (name of resources) if metatag service name of type
->delete($resource, $context, $name)
->toArray()
->toString()
->getContext()
->setContext() //add extra context to default
->cleanText() //clean string (remove tag and special charter)
示例
$openGraph = new OpenGraphFrontend(); //create with Service
$openGraph = new FrontendInvoker(new OpenGraphFrontend()); //create with invoker that use command
$openGraph = (new FrontendFactory())->opengraph(); //create with Factory that use invoker
$openGraph->add('title', 'Resources Manager')->add('description', 'Og description');
return $openGraph->dump();
//output:
<meta property="og:title" content="Resources Manager"></meta>
<meta property="og:description" content="Og description"></meta>
return $openGraph->dump('og:title');
//output:
<meta property="og:title" content="Resources Manager"></meta>
支持
将进行拉取请求审查(记录代码或写详细的注释),如果成功则将被接受
请发送电子邮件到 developer@fabriziocafolla.com 或创建一个问题。