Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from netlogix/feature/psr-2
Browse files Browse the repository at this point in the history
[TASK] Reformat code to PSR-2
  • Loading branch information
stephanschuler committed Mar 29, 2016
2 parents feacaa1 + 6431688 commit 218d733
Show file tree
Hide file tree
Showing 3 changed files with 280 additions and 260 deletions.
145 changes: 74 additions & 71 deletions Classes/Netlogix/Cors/Http/Component/CorsComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,87 +15,90 @@
/**
* HTTP component sending CORS (Access-Control-Allow-*) headers.
*/
class CorsComponent implements ComponentInterface {
class CorsComponent implements ComponentInterface
{

/**
* @var array
*/
protected $options;
/**
* @var array
*/
protected $options;

/**
* @param array $options
*/
public function __construct(array $options = array()) {
$this->options = $options;
}
/**
* @param array $options
*/
public function __construct(array $options = array())
{
$this->options = $options;
}

/**
* If this one is no CORS, this component let pass the request.
* In case of CORS requests, either the allow headers are sent or the
* AccessDeniedException is thrown.
*
* @param ComponentContext $componentContext
* @return void
*/
public function handle(ComponentContext $componentContext) {
static $possibleMethods = array('GET', 'POST', 'OPTIONS', 'DELETE', 'PUT');
/**
* If this one is no CORS, this component let pass the request.
* In case of CORS requests, either the allow headers are sent or the
* AccessDeniedException is thrown.
*
* @param ComponentContext $componentContext
* @return void
*/
public function handle(ComponentContext $componentContext)
{
static $possibleMethods = array('GET', 'POST', 'OPTIONS', 'DELETE', 'PUT');

$corsService = new CorsService();
$corsService = new CorsService();

/**
* allowedMethods
*/
if (isset($this->options['allowedMethods']) && is_array($this->options['allowedMethods'])) {
$configuredMethods = $this->options['allowedMethods'];
$configuredMethods = array_map('strtoupper', $configuredMethods);
$configuredMethods = array_filter($configuredMethods, function($method) use ($possibleMethods) {
return in_array($method, $possibleMethods);
});
$corsService->setAllowedMethods($configuredMethods);
}
/**
* allowedMethods
*/
if (isset($this->options['allowedMethods']) && is_array($this->options['allowedMethods'])) {
$configuredMethods = $this->options['allowedMethods'];
$configuredMethods = array_map('strtoupper', $configuredMethods);
$configuredMethods = array_filter($configuredMethods, function ($method) use ($possibleMethods) {
return in_array($method, $possibleMethods);
});
$corsService->setAllowedMethods($configuredMethods);
}

/**
* allowedOrigins
*/
$configuredOrigins = array();
if (isset($this->options['allowedOrigins']) && is_array($this->options['allowedOrigins'])) {
$configuredOrigins = array_values($this->options['allowedOrigins']);
} elseif (isset($this->options['allowedOrigins']) && is_string($this->options['allowedOrigins'])) {
$configuredOrigins = Arrays::trimExplode(',', $this->options['allowedOrigins']);
}
$corsService->setAllowedOrigins($configuredOrigins);
/**
* allowedOrigins
*/
$configuredOrigins = array();
if (isset($this->options['allowedOrigins']) && is_array($this->options['allowedOrigins'])) {
$configuredOrigins = array_values($this->options['allowedOrigins']);
} elseif (isset($this->options['allowedOrigins']) && is_string($this->options['allowedOrigins'])) {
$configuredOrigins = Arrays::trimExplode(',', $this->options['allowedOrigins']);
}
$corsService->setAllowedOrigins($configuredOrigins);

/**
* allowedHeaders
*/
$configuredHeaders = array();
if (isset($this->options['allowedHeaders']) && is_array($this->options['allowedHeaders'])) {
$configuredHeaders = array_values($this->options['allowedHeaders']);
} elseif (isset($this->options['allowedHeaders']) && is_string($this->options['allowedHeaders'])) {
$configuredHeaders = Arrays::trimExplode(',', $this->options['allowedHeaders']);
}
$corsService->setAllowedHeaders($configuredHeaders);
/**
* allowedHeaders
*/
$configuredHeaders = array();
if (isset($this->options['allowedHeaders']) && is_array($this->options['allowedHeaders'])) {
$configuredHeaders = array_values($this->options['allowedHeaders']);
} elseif (isset($this->options['allowedHeaders']) && is_string($this->options['allowedHeaders'])) {
$configuredHeaders = Arrays::trimExplode(',', $this->options['allowedHeaders']);
}
$corsService->setAllowedHeaders($configuredHeaders);

/**
* allowCredentials
*/
if (isset($this->options['allowCredentials']) && $this->options['allowCredentials']) {
$corsService->setAllowCredentials(TRUE);
} else {
$corsService->setAllowCredentials(FALSE);
}
/**
* allowCredentials
*/
if (isset($this->options['allowCredentials']) && $this->options['allowCredentials']) {
$corsService->setAllowCredentials(true);
} else {
$corsService->setAllowCredentials(false);
}

/**
* maxAge
*/
if (isset($this->options['maxAge']) && $this->options['maxAge']) {
$corsService->setMaxAge(intval($this->options['maxAge']));
} else {
$corsService->setMaxAge(600);
}
/**
* maxAge
*/
if (isset($this->options['maxAge']) && $this->options['maxAge']) {
$corsService->setMaxAge(intval($this->options['maxAge']));
} else {
$corsService->setMaxAge(600);
}

$corsService->sendHeaders();
$corsService->sendHeaders();

}
}

}
Loading

0 comments on commit 218d733

Please sign in to comment.