mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-04 01:01:41 +09:00
Add Context::setCorsPolicy() method #2287
This commit is contained in:
parent
eb5dd18659
commit
ff41a14237
1 changed files with 26 additions and 0 deletions
|
|
@ -473,6 +473,32 @@ class Context
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set CORS policy for the current request.
|
||||
*
|
||||
* @param string $origin Origin to allow, or '*'
|
||||
* @param array $methods
|
||||
* @param array $headers
|
||||
* @param int $max_age
|
||||
* @return void
|
||||
*/
|
||||
public static function setCorsPolicy(string $origin = '*', array $methods = [], array $headers = [], int $max_age = 0): void
|
||||
{
|
||||
header('Access-Control-Allow-Origin: ' . $origin);
|
||||
if (count($methods))
|
||||
{
|
||||
header('Access-Control-Allow-Methods: ' . implode(', ', $methods));
|
||||
}
|
||||
if (count($headers))
|
||||
{
|
||||
header('Access-Control-Allow-Headers: ' . implode(', ', $headers));
|
||||
}
|
||||
if ($max_age > 0)
|
||||
{
|
||||
header('Access-Control-Max-Age: ' . $max_age);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the database information
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue