
번역 : 스페인어
쿠키 처리를 위한 PHP 라이브러리입니다.
운영 체제: 리눅스.
PHP 버전: 8.1 | 8.2 | 8.3.
이 확장을 설치하는 기본 방법은 Composer를 사용하는 것입니다.
php cookie 라이브러리를 설치하려면 다음을 수행하세요.
composer require josantonius/cookie사용할 수 있는 전체 소스 코드를 다운로드 하려는 경우 이전 명령은 필요한 파일만 설치합니다.
composer require josantonius/cookie --prefer-sourceGit을 사용하여 전체 저장소를 복제 할 수도 있습니다.
git clone https://github.com/josantonius/php-cookie.git JosantoniusCookieCookie
쿠키 옵션을 설정합니다:
/**
* Cookie options:
*
* domain: Domain for which the cookie is available.
* expires: The time the cookie will expire.
* httpOnly: If cookie will only be available through the HTTP protocol.
* path: Path for which the cookie is available.
* raw: If cookie will be sent as a raw string.
* sameSite: Enforces the use of a Lax or Strict SameSite policy.
* secure: If cookie will only be available through the HTTPS protocol.
*
* These settings will be used to create and delete cookies.
*
* @throws CookieException if $sameSite value is wrong.
*
* @see https://www.php.net/manual/en/datetime.formats.php for date formats.
* @see https://www.php.net/manual/en/function.setcookie.php for more information.
*/
public function __construct(
private string $ domain = '' ,
private int | string | DateTime $ expires = 0 ,
private bool $ httpOnly = false ,
private string $ path = ' / ' ,
private bool $ raw = false ,
private null | string $ sameSite = null ,
private bool $ secure = false
);이름으로 쿠키를 설정합니다.
/**
* @throws CookieException if headers already sent.
* @throws CookieException if failure in date/time string analysis.
*/
public function set(
string $ name ,
mixed $ value ,
null | int | string | DateTime $ expires = null
): void ;한 번에 여러 쿠키를 설정합니다.
/**
* If cookies exist they are replaced, if they do not exist they are created.
*
* @throws CookieException if headers already sent.
*/
public function replace(
array $ data ,
null | int | string | DateTime $ expires = null
): void ;이름으로 쿠키를 가져옵니다.
/**
* Optionally defines a default value when the cookie does not exist.
*/
public function get( string $ name , mixed $ default = null ): mixed ;모든 쿠키를 가져옵니다.
public function all(): array ;쿠키가 있는지 확인하십시오.
public function has( string $ name ): bool ;이름으로 쿠키를 삭제하고 해당 값을 반환합니다.
/**
* Optionally defines a default value when the cookie does not exist.
*
* @throws CookieException if headers already sent.
*/
public function pull( string $ name , mixed $ default = null ): mixed ;이름별로 쿠키를 삭제합니다.
/**
* @throws CookieException if headers already sent.
* @throws CookieException if failure in date/time string analysis.
*/
public function remove( string $ name ): void ; JosantoniusCookieFacadesCookie
쿠키 옵션을 설정합니다:
/**
* Cookie options:
*
* domain: Domain for which the cookie is available.
* expires: The time the cookie will expire.
* httpOnly: If cookie will only be available through the HTTP protocol.
* path: Path for which the cookie is available.
* raw: If cookie will be sent as a raw string.
* sameSite: Enforces the use of a Lax or Strict SameSite policy.
* secure: If cookie will only be available through the HTTPS protocol.
*
* These settings will be used to create and delete cookies.
*
* @throws CookieException if $sameSite value is wrong.
*
* @see https://www.php.net/manual/en/datetime.formats.php for date formats.
* @see https://www.php.net/manual/en/function.setcookie.php for more information.
*/
public static function options(
string $ domain = '' ,
int | string | DateTime $ expires = 0 ,
bool $ httpOnly = false ,
string $ path = ' / ' ,
bool $ raw = false ,
null | string $ sameSite = null ,
bool $ secure = false
): void ;이름으로 쿠키를 설정합니다.
/**
* @throws CookieException if headers already sent.
* @throws CookieException if failure in date/time string analysis.
*/
public static function set(
string $ name ,
mixed $ value ,
null | int | string | DateTime $ expires = null
): void ;한 번에 여러 쿠키를 설정합니다.
/**
* If cookies exist they are replaced, if they do not exist they are created.
*
* @throws CookieException if headers already sent.
*/
public static function replace(
array $ data ,
null | int | string | DateTime $ expires = null
): void ;이름으로 쿠키를 가져옵니다.
/**
* Optionally defines a default value when the cookie does not exist.
*/
public static function get( string $ name , mixed $ default = null ): mixed ;모든 쿠키를 가져옵니다.
public static function all(): array ;쿠키가 있는지 확인하십시오.
public static function has( string $ name ): bool ;이름으로 쿠키를 삭제하고 해당 값을 반환합니다.
/**
* Optionally defines a default value when the cookie does not exist.
*
* @throws CookieException if headers already sent.
*/
public static function pull( string $ name , mixed $ default = null ): mixed ;이름별로 쿠키를 삭제합니다.
/**
* @throws CookieException if headers already sent.
* @throws CookieException if failure in date/time string analysis.
*/
public static function remove( string $ name ): void ; use Josantonius Cookie Exceptions CookieException ;이 라이브러리의 사용 예:
use Josantonius Cookie Cookie ;
$ cookie = new Cookie (); use Josantonius Cookie Facades Cookie ;
Cookie:: options (); use Josantonius Cookie Cookie ;
$ cookie = new Cookie (
domain: ' example.com ' ,
expires: time () + 3600 ,
httpOnly: true ,
path: ' /foo ' ,
raw: true ,
sameSite: ' Strict ' ,
secure: true ,
); use Josantonius Cookie Facades Cookie ;
Cookie:: options (
expires: ' now +1 hour ' ,
httpOnly: true ,
); use Josantonius Cookie Cookie ;
$ cookie = new Cookie ();
$ cookie -> set ( ' foo ' , ' bar ' ); use Josantonius Cookie Facades Cookie ;
Cookie:: set ( ' foo ' , ' bar ' ); use Josantonius Cookie Cookie ;
$ cookie = new Cookie ();
$ cookie -> set ( ' foo ' , ' bar ' , time () + 3600 ); use Josantonius Cookie Facades Cookie ;
Cookie:: set ( ' foo ' , ' bar ' , new DateTime ( ' now +1 hour ' )); use Josantonius Cookie Cookie ;
$ cookie = new Cookie ();
$ cookie -> replace ([
' foo ' => ' bar ' ,
' bar ' => ' foo '
]); use Josantonius Cookie Facades Cookie ;
Cookie:: replace ([
' foo ' => ' bar ' ,
' bar ' => ' foo '
], time () + 3600 ); use Josantonius Cookie Cookie ;
$ cookie = new Cookie ();
$ cookie -> replace ([
' foo ' => ' bar ' ,
' bar ' => ' foo '
], time () + 3600 ); use Josantonius Cookie Facades Cookie ;
Cookie:: replace ([
' foo ' => ' bar ' ,
' bar ' => ' foo '
], time () + 3600 ); use Josantonius Cookie Cookie ;
$ cookie = new Cookie ();
$ cookie -> get ( ' foo ' ); // null if the cookie does not exist use Josantonius Cookie Facades Cookie ;
Cookie:: get ( ' foo ' ); // null if the cookie does not exist use Josantonius Cookie Cookie ;
$ cookie = new Cookie ();
$ cookie -> get ( ' foo ' , false ); // false if cookie does not exist use Josantonius Cookie Facades Cookie ;
Cookie:: get ( ' foo ' , false ); // false if cookie does not exist use Josantonius Cookie Cookie ;
$ cookie = new Cookie ();
$ cookie -> all (); use Josantonius Cookie Facades Cookie ;
Cookie:: all (); use Josantonius Cookie Cookie ;
$ cookie = new Cookie ();
$ cookie -> has ( ' foo ' ); use Josantonius Cookie Facades Cookie ;
Cookie:: has ( ' foo ' ); use Josantonius Cookie Cookie ;
$ cookie = new Cookie ();
$ cookie -> pull ( ' foo ' ); // null if attribute does not exist use Josantonius Cookie Facades Cookie ;
Cookie:: pull ( ' foo ' ); // null if attribute does not exist use Josantonius Cookie Cookie ;
$ cookie = new Cookie ();
$ cookie -> pull ( ' foo ' , false ); // false if attribute does not exist use Josantonius Cookie Facades Cookie ;
Cookie:: pull ( ' foo ' , false ); // false if attribute does not exist use Josantonius Cookie Cookie ;
$ cookie = new Cookie ();
$ cookie -> remove ( ' foo ' ); use Josantonius Cookie Facades Cookie ;
Cookie:: remove ( ' foo ' ); 이 라이브러리의 여러 메소드에 사용되는 만료 매개변수는 int|string|DateTime 유형을 허용합니다.
Integers 0을 제외한 유닉스 시간으로 처리됩니다.
Strings 날짜/시간 형식으로 처리됩니다. 자세한 내용은 지원되는 날짜 및 시간 형식을 참조하세요.
$ cookie = new Cookie (
expires: ' 2016-12-15 +1 day '
);이는 다음과 유사합니다:
$ cookie = new Cookie (
expires: new DateTime ( ' 2016-12-15 +1 day ' )
); DateTime 객체는 Unix 시간을 얻는 데 사용됩니다.
만료 매개변수가 set 또는 replace 메소드에서 사용되는 경우 쿠키 옵션에 설정된 만료 값 대신 해당 매개변수가 사용됩니다.
$ cookie = new Cookie (
expires: ' now +1 minute '
);
$ cookie -> set ( ' foo ' , ' bar ' ); // Expires in 1 minute
$ cookie -> set ( ' bar ' , ' foo ' , ' now +8 days ' ); // Expires in 8 days
$ cookie -> replace ([ ' foo ' => ' bar ' ]); // Expires in 1 minute
$ cookie -> replace ([ ' foo ' => ' bar ' ], time () + 3600 ); // Expires in 1 hour 옵션에 전달된 만료 매개 변수가 날짜/시간 문자열인 경우 옵션을 설정할 때가 아니라 set 또는 replace 메서드를 사용할 때 형식이 지정됩니다.
$ cookie = new Cookie (
expires: ' now +1 minute ' , // It will not be formatted as unix time yet
);
$ cookie -> set ( ' foo ' , ' bar ' ); // It is will formatted now and expires in 1 minute 테스트를 실행하려면 작곡가가 필요하고 다음을 실행해야 합니다.
git clone https://github.com/josantonius/php-cookie.git cd php-cookie composer installPHPUnit을 사용하여 단위 테스트를 실행합니다.
composer phpunitPHPCS를 사용하여 코드 표준 테스트를 실행합니다.
composer phpcsPHP Mess Detector 테스트를 실행하여 코드 스타일의 불일치를 감지합니다.
composer phpmd이전 테스트를 모두 실행합니다.
composer tests 각 릴리스에 대한 자세한 변경 사항은 릴리스 노트에 설명되어 있습니다.
끌어오기 요청을 하기 전에 기여 가이드를 읽고 토론을 시작하거나 문제를 보고하십시오.
모든 기여자에게 감사드립니다! ❤️
이 프로젝트가 귀하의 개발 시간을 줄이는 데 도움이 된다면, 저의 오픈 소스 작업을 지원하도록 후원해 주실 수 있습니까?
이 저장소는 MIT 라이선스에 따라 라이선스가 부여됩니다.
저작권 © 2016-현재, Josantonius