-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f0cb914
commit 36246aa
Showing
18 changed files
with
497 additions
and
83 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,62 @@ | ||
<?php | ||
|
||
namespace CodeZero\BrowserLocale\Filters; | ||
|
||
use CodeZero\BrowserLocale\Locale; | ||
|
||
class CombinedFilter implements Filter | ||
{ | ||
/** | ||
* The filtered results. | ||
* | ||
* @var array | ||
*/ | ||
protected $filtered; | ||
|
||
/** | ||
* Filter the locales. | ||
* | ||
* @param array $locales | ||
* | ||
* @return array | ||
*/ | ||
public function filter(array $locales) | ||
{ | ||
$this->filtered = []; | ||
|
||
foreach ($locales as $locale) { | ||
$this->filterLocale($locale); | ||
} | ||
|
||
return $this->filtered; | ||
} | ||
|
||
/** | ||
* Filter the given Locale. | ||
* | ||
* @param \CodeZero\BrowserLocale\Locale $locale | ||
* | ||
* @return void | ||
*/ | ||
protected function filterLocale(Locale $locale) | ||
{ | ||
$language = substr($locale->locale, 0, 2); | ||
|
||
$this->addLocale($locale->locale); | ||
$this->addLocale($language); | ||
} | ||
|
||
/** | ||
* Add a locale to the results array. | ||
* | ||
* @param string $locale | ||
* | ||
* @return void | ||
*/ | ||
protected function addLocale($locale) | ||
{ | ||
if ( ! in_array($locale, $this->filtered)) { | ||
$this->filtered[] = $locale; | ||
} | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace CodeZero\BrowserLocale\Filters; | ||
|
||
class CountryFilter extends PropertyFilter implements Filter | ||
{ | ||
/** | ||
* Filter the locales. | ||
* | ||
* @param array $locales | ||
* | ||
* @return array | ||
*/ | ||
public function filter(array $locales) | ||
{ | ||
return $this->filterByProperty($locales, 'country'); | ||
} | ||
} |
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,15 @@ | ||
<?php | ||
|
||
namespace CodeZero\BrowserLocale\Filters; | ||
|
||
interface Filter | ||
{ | ||
/** | ||
* Filter the locales. | ||
* | ||
* @param array $locales | ||
* | ||
* @return array | ||
*/ | ||
public function filter(array $locales); | ||
} |
Oops, something went wrong.