Permalink
Browse files

Shift Validate_SE to own repo

  • Loading branch information...
1 parent 308a23d commit 947ea964e47ba0e09695bd3ac61fd68494b87caa @CloCkWeRX CloCkWeRX committed Dec 9, 2011
Showing with 0 additions and 262 deletions.
  1. +0 −101 Validate/SE.php
  2. +0 −81 package_SE.xml
  3. +0 −37 tests/validate_SE_counties.phpt
  4. +0 −43 tests/validate_SE_postalcodes.phpt
View
101 Validate/SE.php
@@ -1,101 +0,0 @@
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4: */
-/**
- * Methods for validation in Sweden
- *
- * PHP Version 5
- *
- * This source file is subject to the New BSD license, That is bundled
- * with this package in the file LICENSE, and is available through
- * the world-wide-web at
- * http://www.opensource.org/licenses/bsd-license.php
- * If you did not receive a copy of the new BSDlicense and are unable
- * to obtain it through the world-wide-web, please send a note to
- * pajoye@php.net so we can mail you a copy immediately.
- *
- * @category Validate
- * @package Validate_SE
- * @author Christian Weiske <cweiske@php.net>
- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
- * @version SVN: $Id: DE.php 242590 2007-09-16 17:35:37Z kguest $
- * @link http://pear.php.net/package/Validate_DE
- */
-
-/**
- * Data validation class for Sweden
- *
- * This class provides methods to validate:
- * - Postal code
- *
- * @category Validate
- * @package Validate_SE
- * @author Christian Weiske <cweiske@php.net>
- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: @package_version@
- * @link http://pear.php.net/package/Validate_DE
- */
-class Validate_SE
-{
- /**
- * Validate a Swedish postcode.
- *
- * @param string $postcode postcode to validate
- * @param bool $strong optional; strong checks (e.g. against a list of
- * postcodes) (not implemented)
- *
- * @return bool true if postcode is ok, false otherwise
- *
- * http://en.wikipedia.org/wiki/Postal_codes_in_Sweden
- */
- public static function postalCode($postcode, $strong = false)
- {
- return (bool)preg_match('/^[0-9]{3}[ ]?[0-9]{2}$/', $postcode);
- }
-
- /**
- * Validate a Swedish county.
- *
- * http://en.wikipedia.org/wiki/Counties_of_Sweden
- *
- * @param string $name County to validate
- * @param bool $return If true, return name of county as string
- *
- * @return mixed True if county exists, or county name if $return is true.
- *
- * http://en.wikipedia.org/wiki/Postal_codes_in_Sweden
- */
- public function county($name, $return=false)
- {
- $counties = array(
- "AB" => "Stockholms län",
- "C" => "Uppsala län",
- "D" => "Södermanlands län",
- "E" => "Östergötlands län",
- "F" => "Jönköpings län",
- "G" => "Kronobergs län",
- "H" => "Kalmar län",
- "I" => "Gotlands län",
- "K" => "Blekinge län",
- "M" => "Skåne län",
- "N" => "Hallands län",
- "O" => "Västra Götalands län",
- "S" => "Värmlands län",
- "T" => "Örebro län",
- "U" => "Västmanlands län",
- "W" => "Dalarnas län",
- "X" => "Gävleborgs län",
- "Y" => "Västernorrlands län",
- "Z" => "Jämtlands län",
- "AC" => "Västerbottens län",
- "BD" => "Norrbottens län");
-
- $exists = array_key_exists(strtoupper($name), $counties);
-
- if (!$exists || !$return ) {
- return $exists;
- } else {
- return $counties[strtoupper($name)];
- }
- }
-}
-?>
View
81 package_SE.xml
@@ -1,81 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<package packagerversion="1.6.1"
- version="2.0"
- xmlns="http://pear.php.net/dtd/package-2.0"
- xmlns:tasks="http://pear.php.net/dtd/tasks-1.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd"
->
- <name>Validate_SE</name>
- <channel>pear.php.net</channel>
- <summary>Validation class for Sweden</summary>
- <description>Package containes locale validation for Sweden such as:
- * Postal Code
- </description>
-
- <lead>
- <name>Christian Weiske</name>
- <user>cweiske</user>
- <email>cweiske@php.net</email>
- <active>yes</active>
- </lead>
-
- <date>2010-08-04</date>
-
- <version>
- <release>0.1.0</release>
- <api>0.1.0</api>
- </version>
-
- <stability>
- <release>alpha</release>
- <api>alpha</api>
- </stability>
-
- <license uri="http://www.opensource.org/licenses/bsd-license.php">New BSD</license>
-
- <notes>
- - First version with postal code validation
- </notes>
- <contents>
- <dir name="/">
- <file name="Validate/SE.php" role="php">
- <tasks:replace from="@package_version@" to="version" type="package-info" />
- </file>
- <file name="tests/validate_SE_postalcodes.phpt" role="test" />
- </dir>
- </contents>
-
- <dependencies>
- <required>
- <php>
- <min>5.2.0</min>
- </php>
- <pearinstaller>
- <min>1.8.0</min>
- </pearinstaller>
- </required>
- </dependencies>
-
- <phprelease />
-
- <changelog>
-
- <release>
- <version>
- <release>0.1.0</release>
- <api>0.1.0</api>
- </version>
- <stability>
- <release>alpha</release>
- <api>alpha</api>
- </stability>
- <date>2010-08-04</date>
- <license uri="http://www.opensource.org/licenses/bsd-license.php">New BSD</license>
- <notes>
- - Initial release
- </notes>
- </release>
-
- </changelog>
-</package>
View
37 tests/validate_SE_counties.phpt
@@ -1,37 +0,0 @@
---TEST--
-Test Swedish counties
---FILE--
-<?php
-$noYes = array('NO', 'YES');
-if (is_file(dirname(__FILE__) . '/../Validate/SE.php')) {
- require_once dirname(__FILE__) . '/../Validate/SE.php';
-} else {
- require_once 'Validate/SE.php';
-}
-
-
-$counties = array(
- 'XX',//no
- 'AB',//ok
- 'ab'//ok
-);
-
-foreach ($counties as $county) {
- echo "{$county}: "
- . $noYes[
- Validate_SE::county($county)
- ] . "\n";
-}
-// County O With Return value
-echo Validate_SE::county('O', true);
-echo "\n";
-// County O With Return value
-$doesNotExist = Validate_SE::county('NOT_THERE', true);
-var_dump($doesNotExist);
-
---EXPECT--
-XX: NO
-AB: YES
-ab: YES
-Västra Götalands län
-bool(false)
View
43 tests/validate_SE_postalcodes.phpt
@@ -1,43 +0,0 @@
---TEST--
-Test swedish postal codes
---FILE--
-<?php
-$noYes = array('NO', 'YES');
-if (is_file(dirname(__FILE__) . '/../Validate/SE.php')) {
- require_once dirname(__FILE__) . '/../Validate/SE.php';
-} else {
- require_once 'Validate/SE.php';
-}
-
-
-$postalCodes = array(
- 12345,//ok
- 92382,//ok
- '923 82',//ok
- '92 382',//no
- 'a123',//no
- '923Z3',//no
- 1234,//no
- 123,//no
- 12,//no
- 1,//no
-);
-
-foreach ($postalCodes as $postalCode) {
- echo "{$postalCode}: "
- . $noYes[
- Validate_SE::postalCode($postalCode)
- ] . "\n";
-}
-
---EXPECT--
-12345: YES
-92382: YES
-923 82: YES
-92 382: NO
-a123: NO
-923Z3: NO
-1234: NO
-123: NO
-12: NO
-1: NO

0 comments on commit 947ea96

Please sign in to comment.