
การแปล : español
ไลบรารี PHP สำหรับการจัดการลิงก์และสคริปต์ HTML
ระบบปฏิบัติการ: Linux | Windows.
เวอร์ชัน PHP: 8.1 | 8.2.
วิธีที่ต้องการในการติดตั้งส่วนขยายนี้คือผ่านนักแต่งเพลง
ในการติดตั้ง ไลบรารีสินทรัพย์ PHP เพียง:
composer require josantonius/assetคำสั่งก่อนหน้านี้จะติดตั้งไฟล์ที่จำเป็นเท่านั้นหากคุณต้องการ ดาวน์โหลดซอร์สโค้ดทั้งหมดที่ คุณสามารถใช้ได้:
composer require josantonius/asset --prefer-sourceนอกจากนี้คุณยังสามารถ โคลนพื้นที่เก็บข้อมูลที่สมบูรณ์ ด้วย GIT:
git clone https://github.com/josantonius/php-asset.git JosantoniusAssetAsset
พิมพ์สคริปต์เพิ่มเติมสำหรับร่างกาย:
public function outputBodyScripts(): string ;พิมพ์สคริปต์ที่เพิ่มขึ้นสำหรับหัว:
public function outputHeadScripts(): string ;พิมพ์ลิงก์ที่เพิ่มขึ้น:
public function outputLinks(): string ; JosantoniusAssetFacadesAsset
เพิ่มสคริปต์ร่างกาย:
/**
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script
*/
public static function addBodyScript(
null | bool $ async = null ,
null | string $ crossorigin = null ,
null | bool $ defer = null ,
null | string $ fetchpriority = null ,
null | string $ integrity = null ,
null | bool $ nomodule = null ,
null | string $ nonce = null ,
null | string $ referrerpolicy = null ,
null | string $ src = null ,
null | string $ type = null
): BodyScript ;เพิ่มหัวสคริปต์:
/**
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script
*/
public static function addHeadScript(
null | bool $ async = null ,
null | string $ crossorigin = null ,
null | bool $ defer = null ,
null | string $ fetchpriority = null ,
null | string $ integrity = null ,
null | bool $ nomodule = null ,
null | string $ nonce = null ,
null | string $ referrerpolicy = null ,
null | string $ src = null ,
null | string $ type = null
): HeadScript ;เพิ่มลิงค์:
/**
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link
*/
public static function addLink(
null | string $ as = null ,
null | string $ crossorigin = null ,
null | bool $ disabled = null ,
null | string $ fetchpriority = null ,
null | string $ href = null ,
null | string $ hreflang = null ,
null | string $ imagesizes = null ,
null | string $ imagesrcset = null ,
null | string $ integrity = null ,
null | string $ media = null ,
null | string $ prefetch = null ,
null | string $ referrerpolicy = null ,
null | string $ rel = null ,
null | string $ sizes = null ,
null | string $ target = null ,
null | string $ title = null ,
null | string $ type = null ,
): Link ;พิมพ์สคริปต์เพิ่มเติมสำหรับร่างกาย:
public static function outputBodyScripts(): string ;พิมพ์สคริปต์ที่เพิ่มขึ้นสำหรับหัว:
public static function outputHeadScripts(): string ;พิมพ์ลิงก์ที่เพิ่มขึ้น:
public static function outputLinks(): string ; JosantoniusAssetElementsBodyScript
เพิ่มสคริปต์ร่างกาย:
/**
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script
*/
public function __construct(
private null | bool $ async = null ,
private null | string $ crossorigin = null ,
private null | bool $ defer = null ,
private null | string $ fetchpriority = null ,
private null | string $ integrity = null ,
private null | bool $ nomodule = null ,
private null | string $ nonce = null ,
private null | string $ referrerpolicy = null ,
private null | string $ src = null ,
private null | string $ type = null
); JosantoniusAssetElementsHeadScript
เพิ่มหัวสคริปต์:
/**
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script
*/
public function __construct(
private null | bool $ async = null ,
private null | string $ crossorigin = null ,
private null | bool $ defer = null ,
private null | string $ fetchpriority = null ,
private null | string $ integrity = null ,
private null | bool $ nomodule = null ,
private null | string $ nonce = null ,
private null | string $ referrerpolicy = null ,
private null | string $ src = null ,
private null | string $ type = null
); JosantoniusAssetElementsLink
เพิ่มลิงค์:
/**
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link
*/
public function __construct(
private null | string $ as = null ,
private null | string $ crossorigin = null ,
private null | bool $ disabled = null ,
private null | string $ fetchpriority = null ,
private null | string $ href = null ,
private null | string $ hreflang = null ,
private null | string $ imagesizes = null ,
private null | string $ imagesrcset = null ,
private null | string $ integrity = null ,
private null | string $ media = null ,
private null | string $ prefetch = null ,
private null | string $ referrerpolicy = null ,
private null | string $ rel = null ,
private null | string $ sizes = null ,
private null | string $ target = null ,
private null | string $ title = null ,
private null | string $ type = null ,
);ตัวอย่างการใช้งานสำหรับไลบรารีนี้:
use Josantonius Asset Elements BodyScript ;
new BodyScript (
src: ' https://example.com/script.js '
); use Josantonius Asset Facades Asset ;
Asset:: addBodyScript (
src: ' script.js ' ,
type: ' text/javascript '
); use Josantonius Asset Elements HeadScript ;
new HeadScript (
src: ' script.js ' ,
type: ' module '
); use Josantonius Asset Facades Asset ;
Asset:: addHeadScript (
crossorigin: ' anonymous ' ,
defer: true ,
integrity: ' sha256-n9+ ' ,
src: ' https://example.com/script.js ' ,
type: ' text/javascript '
); use Josantonius Asset Elements Link ;
new Link (
crossorigin: ' anonymous ' ,
href: ' https://example.com/style.css ' ,
integrity: ' sha256-n9+ ' ,
media: ' all ' ,
rel: ' stylesheet '
); use Josantonius Asset Facades Asset ;
Asset:: addLink (
href: ' https://example.com/style.css ' ,
rel: ' stylesheet '
); use Josantonius Asset Asset ;
$ asset = new Asset ();
echo $ asset -> outputBodyScripts (); use Josantonius Asset Facades Asset ;
echo Asset:: outputBodyScripts (); use Josantonius Asset Asset ;
$ asset = new Asset ();
echo $ asset -> outputHeadScripts (); use Josantonius Asset Facades Asset ;
echo Asset:: outputHeadScripts (); use Josantonius Asset Asset ;
$ asset = new Asset ();
echo $ asset -> outputLinks (); use Josantonius Asset Facades Asset ;
echo Asset:: outputLinks (); index.php
use Josantonius Asset Elements Link ;
use Josantonius Asset Elements BodyScript ;
use Josantonius Asset Elements HeadScript ;
new BodyScript (src: ' foo.js ' , async: true );
new BodyScript (src: ' bar.js ' , type: ' text/javascript ' );
new HeadScript (src: ' https://example.com/foo.js ' , type: ' module ' );
new HeadScript (src: ' https://example.com/bar.js ' , defer: true );
new Link (href: ' https://example.com/foo.css ' , rel: ' stylesheet ' );
new Link (href: ' https://example.com/bar.css ' , rel: ' stylesheet ' , media: ' all ' ); page.html
< ?php
use JosantoniusAssetAsset;
$asset = new Asset();
? >
< html >
< head >
< ?= $asset- > outputLinks() ? >
< ?= $asset- > outputHeadScripts() ? >
</ head >
< body >
< ?= $asset- > outputBodyScripts() ? >
</ body >
</ html >ผลลัพธ์:
< html >
< head >
< link href =" https://example.com/foo.css " rel =" stylesheet " >
< link href =" https://example.com/bar.css " rel =" stylesheet " media =" all " >
< script src =" https://example.com/foo.js " type =" module " > </ script >
< script defer src =" https://example.com/bar.js " > </ script >
</ head >
< body >
< script async src =" foo.js " > </ script >
< script src =" bar.js " type =" text/javascript " > </ script >
</ body >
</ html > index.php
use Josantonius Asset Facades Asset ;
Asset:: addBodyScript (src: ' foo.js ' , async: true );
Asset:: addBodyScript (src: ' bar.js ' , type: ' text/javascript ' );
Asset:: addHeadScript (src: ' https://example.com/foo.js ' , type: ' module ' );
Asset:: addHeadScript (src: ' https://example.com/bar.js ' , defer: true );
Asset:: addLink (href: ' https://example.com/foo.css ' , rel: ' stylesheet ' );
Asset:: addLink (href: ' https://example.com/bar.css ' , rel: ' stylesheet ' , media: ' all ' ); page.html
< ?php
use JosantoniusAssetFacadesAsset;
? >
< html >
< head >
< ?= Asset::outputLinks() ? >
< ?= Asset::outputHeadScripts() ? >
</ head >
< body >
< ?= Asset::outputBodyScripts() ? >
</ body >
</ html >ผลลัพธ์:
< html >
< head >
< link href =" https://example.com/foo.css " rel =" stylesheet " >
< link href =" https://example.com/bar.css " rel =" stylesheet " media =" all " >
< script src =" https://example.com/foo.js " type =" module " > </ script >
< script defer src =" https://example.com/bar.js " > </ script >
</ head >
< body >
< script async src =" foo.js " > </ script >
< script src =" bar.js " type =" text/javascript " > </ script >
</ body >
</ html > ในการเรียกใช้การทดสอบคุณเพียงแค่ต้องการนักแต่งเพลงและดำเนินการดังต่อไปนี้:
git clone https://github.com/josantonius/php-asset.git cd php-asset composer installเรียกใช้การทดสอบหน่วยด้วย phpunit:
composer phpunitเรียกใช้การทดสอบมาตรฐานรหัสด้วย PHPCS:
composer phpcsเรียกใช้การทดสอบเครื่องตรวจจับ Mess Mess เพื่อตรวจจับความไม่สอดคล้องกันในรูปแบบรหัส:
composer phpmdเรียกใช้การทดสอบก่อนหน้าทั้งหมด:
composer tests <script> การเปลี่ยนแปลงโดยละเอียดสำหรับแต่ละรุ่นจะถูกบันทึกไว้ในบันทึกย่อ
โปรดตรวจสอบให้แน่ใจว่าได้อ่านคู่มือการสนับสนุนก่อนที่จะทำการร้องขอการดึงเริ่มการสนทนาหรือรายงานปัญหา
ขอบคุณผู้มีส่วนร่วมทุกคน!
หากโครงการนี้ช่วยให้คุณลดเวลาในการพัฒนาคุณสามารถสนับสนุนฉันเพื่อสนับสนุนงานโอเพนซอร์สของฉัน?
ที่เก็บนี้ได้รับใบอนุญาตภายใต้ใบอนุญาต MIT
ลิขสิทธิ์© 2016- ปัจจุบัน Josantonius