forked from ezsystems/EzSystemsPrivacyCookieBundle
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ezsystems#3 from clash82/better
EZP-24231: As a Developer I would like to have more abstract structure...
- Loading branch information
Showing
9 changed files
with
185 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
/** | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
|
||
namespace EzSystems\PrivacyCookieBundle\Banner; | ||
|
||
class Banner | ||
{ | ||
/** | ||
* Banner caption. | ||
* | ||
* @var string | ||
*/ | ||
public $caption; | ||
|
||
/** | ||
* Text linked to the policy page. | ||
* | ||
* @var string | ||
*/ | ||
public $learnMoreText; | ||
|
||
/** | ||
* URL to the detailled cookies & privacy legacy page. | ||
* | ||
* @var string | ||
*/ | ||
public $policyPageUrl; | ||
|
||
/** | ||
* Name of the cookie used to store the user's choice. | ||
* | ||
* @var string | ||
*/ | ||
public $cookieName; | ||
|
||
/** | ||
* Cookie validity duration, in days. | ||
* | ||
* @var int | ||
*/ | ||
public $cookieValidity; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
/** | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
|
||
namespace EzSystems\PrivacyCookieBundle\Banner; | ||
|
||
interface BannerFactory | ||
{ | ||
/** | ||
* Builds the privacy cookie banner object, using any kind of data source. | ||
* | ||
* @return \EzSystems\PrivacyCookieBundle\Banner\Banner | ||
*/ | ||
public static function build(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
/** | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
|
||
namespace EzSystems\PrivacyCookieBundle\Banner; | ||
|
||
use \EzSystems\PrivacyCookieBundle\Banner\Banner; | ||
|
||
class BannerOptions | ||
{ | ||
/** | ||
* Map banner options. | ||
* | ||
* @param array $options | ||
* @param \EzSystems\PrivacyCookieBundle\Banner\Banner $banner | ||
* @return array | ||
*/ | ||
public function map(array $options, Banner $banner) | ||
{ | ||
$bannerOptions = get_object_vars($banner); | ||
|
||
$validatedOptions = array(); | ||
foreach ($bannerOptions as $name => $value) | ||
{ | ||
$validatedOptions[$name] = empty($options[$name]) ? $value : $options[$name]; | ||
} | ||
|
||
return $validatedOptions; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
/** | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
|
||
namespace EzSystems\PrivacyCookieBundle\Factory; | ||
|
||
use EzSystems\PrivacyCookieBundle\Banner\Banner; | ||
use EzSystems\PrivacyCookieBundle\Banner\BannerFactory; | ||
|
||
class ConfigurationBasedBannerFactory implements BannerFactory | ||
{ | ||
public static function build(array $configuration = array()) | ||
{ | ||
$banner = new Banner(); | ||
|
||
$banner->cookieName = $configuration['cookie_name']; | ||
$banner->cookieValidity = $configuration['cookie_validity']; | ||
$banner->caption = $configuration['banner_caption']; | ||
$banner->learnMoreText = $configuration['banner_link_text']; | ||
$banner->policyPageUrl = $configuration['banner_link_url']; | ||
|
||
return $banner; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
parameters: | ||
# how many days banner should be hidden when user accepts policy? | ||
ez_privacy_cookie.days: 365 | ||
|
||
# name to be used to store cookie status | ||
ez_privacy_cookie.cookie_name: "privacyCookieAccepted" | ||
# banner description | ||
ez_privacy_cookie.banner_caption: "Cookies help us create a good experience. By using our website, you agree to our use of cookies." | ||
# banner policy link caption | ||
ez_privacy_cookie.banner_link_text: "Learn more" | ||
# banner policy address | ||
ez_privacy_cookie.banner_link_url: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,31 @@ | ||
parameters: | ||
ez_privacy_cookie_twig_extension: EzSystems\PrivacyCookieBundle\Twig\PrivacyCookieTwigExtension | ||
ez_privacy_cookie.banner_factory.class: \EzSystems\PrivacyCookieBundle\Banner\BannerFactory | ||
ez_privacy_cookie.configuration_banner_factory.class: EzSystems\PrivacyCookieBundle\Factory\ConfigurationBasedBannerFactory | ||
ez_privacy_cookie.banner_options.class: EzSystems\PrivacyCookieBundle\Banner\BannerOptions | ||
|
||
services: | ||
ez_privacy_cookie.banner_options: | ||
class: %ez_privacy_cookie.banner_options.class% | ||
|
||
ez_privacy_cookie.twig.extension: | ||
class: %ez_privacy_cookie_twig_extension% | ||
arguments: | ||
- @service_container | ||
- %ez_privacy_cookie.cookie_name% | ||
- %ez_privacy_cookie.days% | ||
- @ez_privacy_cookie.banner_options | ||
- @ez_privacy_cookie.banner_factory | ||
tags: | ||
- { name: twig.extension } | ||
|
||
ez_privacy_cookie.banner_factory: | ||
class: %ez_privacy_cookie.banner_factory.class% | ||
alias: ez_privacy_cookie.configuration_banner_factory | ||
|
||
ez_privacy_cookie.configuration_banner_factory: | ||
class: %ez_privacy_cookie.configuration_banner_factory.class% | ||
factory: ["%ez_privacy_cookie.configuration_banner_factory.class%", build] | ||
arguments: | ||
- cookie_name: %ez_privacy_cookie.cookie_name% | ||
cookie_validity: %ez_privacy_cookie.days% | ||
banner_caption: %ez_privacy_cookie.banner_caption% | ||
banner_link_text: %ez_privacy_cookie.banner_link_text% | ||
banner_link_url: %ez_privacy_cookie.banner_link_url% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters