Identity
Identity is a composer package to validate, parse, format and extract various information from national identity numbers., (*1)
Current implementations:
* Swedish personnummer/organisationsnummer
* Danish personnummer/CPR-nummer
* Finnish henkilötunnus/personbeteckning
* Norwegian fĂždselsnummer, (*2)
Installation
To add this package as a dependency to your project, simply add a dependency on komakino/identity to your project's composer.json file., (*3)
{
"require": {
"komakino/identity": "*"
}
}
Usage
use Komakino\Identity\National\SwedishIdentity;
use Komakino\Identity\National\DanishIdentity;
$swedishIdentity = new SwedishIdentity('011017-2721');
$danishIdentity = new DanishIdentity('170583-7315');
Common methods
Upon construction, the number is parsed and validated., (*4)
If number does not comply to the allowed input formats of the implementation, an IdentityInvalidFormatException will be thrown., (*5)
Public properties
-
bool $valid, (*6)
- The validity of the identity number
-
mixed **getters**, (*7)
- All number properties are accessible as properties on the instance
Public methods
-
array listProperties(), (*8)
- Returns all number properties
-
bool hasProperty(string $property), (*9)
- Checks if the identity's implementation has a property
-
string __toString(), (*10)
- Output the formatted identity number
Static methods
-
static array parse(string $number), (*11)
- Creates an instance and returns all number properties
-
static bool validate(string $number), (*12)
- Creates an instance and returns the validity of the number
-
static string format(string $number), (*13)
- Output the formatted identity number
Swedish personnummer/organisationsnummer
0110172721
011017-2721
011017+2721
200110172721
20011017-2721
20011017+2721
011017-2721, (*14)
Number properties
-
type
-
century
- Sources for century:
- Provided in number as OOxxxxxx-xxxx
- The separator is a +, which denotes a person is over 100
- By logical guessing. Pseudo:
year > current_year ? 19 : 20
-
year
-
month
-
day
-
centuryHint
-
locality
-
county
- Only available for people born before 1990
-
number
-
gender
-
checkdigit
-
birthday
-
temporary
- If the number is of a temporary nature
Danish personnummer/CPR-nummer
170583-7315, (*15)
Number properties
-
century
- Calculated from year and centuryHint
-
day
-
month
-
year
-
centuryHint
-
sequence
-
gender
-
birthday
Finnish personnummer/CPR-nummer
311280-888Y, (*16)
Number properties
-
century
-
day
-
month
-
year
-
centuryHint
-
number
-
checkdigit
-
gender
-
birthday
Norwegian fĂždselsnummer
17058332143, (*17)
Number properties
-
century
- Calculated from year and number
-
day
-
month
-
year
-
number
-
checkdigits
-
gender
-
birthday
-
D-number
-
bool Whether or not this is a D-number. Temporary number provided to immigrants etc.
-
H-number
-
bool Whether or not this is a H-number. Temporary number used by health care etc.
Changelog
v1.3.0
- Will now throw an exception if number does'nt comply to the implementations allowed input format.
v1.2.1
- Fixed issues with parsing zeros.
v1.2.0
- Added implementation for Norwegian fĂždselsnummer
v1.1.0
- Added implementation for Finnish henkilötunnus/personbeteckning
v1.0.0
- Initial public release
- Added implementation for Swedish personnummer/organisationsnummer
- Added implementation for Danish personnummer/CPR-nummer