Download the PHP package byrokrat/id without Composer
On this page you can find all versions of the php package byrokrat/id. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package id
Short Description Data types for swedish personal identity and corporation id numbers
License Unlicense
Homepage https://github.com/byrokrat/id
Informations about the package id
Personal Identity
Data types for swedish personal identity and corporation id numbers.
Installation
Usage
Class hierarchy
IdInterface
The base interface. Look here for a complete API reference.PersonalId
The identification number of a swedish individual (personnummer).CoordinationId
Identifier for non-citizens (samordningsnummer).FakeId
Replacement usable when a person must have an id, but is not registered with the swedish authorities.
OrganizationId
Identifies a swedish company or organization (organisationsnummer).NullId
Null object implementation.
Creating ID objects
Creating ID objects can be complicated.
- A personal id can be a coordination id, if the individual identified is not a swedish citizen.
- A corporation id can be a personal id if the corporation is registered with a single individual (egenföretagare).
- A single individual company can use a coordination id if the individual is not a swedish citizen.
- At times you may wish to process persons without a valid swedish personal id,
using the
FakeId
implementation.
To solve these difficulties a decoratable set of factories is included. Create a factory with the abilities you need by chaining factory objects at creation time.
In this example the factory will first try to create a PersonalId
, if this fails
it will try to create a CoordinationId
, if this fails it will throw an Exception.
The following factories are included:
PersonalIdFactory
CoordinationIdFactory
FakeIdFactory
OrganizationIdFactory
NullIdFactory
FailingIdFactory
Controlling the delimiter and century of ids containing dates
In order to controll the computation of dates you may specify at what time parsing takes place by passing a datetime object.
Specifying parse date also affects what delimiter is used.
Formatting
Ids can be printed in custom formats using the format()
method, where $formatStr
is a mix of format tokens and non-formatting characters (for a list of formatting
tokens se below).
If you need to format a large number of ids a formatter object can be created.
Formatting tokens
Characters that are not formatting tokens are returned as they are by the formatter.
Token | Description |
---|---|
C |
Century, 2 digits (00 if not applicable) |
S |
Part of serial number before delimiter, 6 digits |
- |
Date and control string delimiter (- or +) |
s |
Part of serial number after delimiter, 3 digits |
k |
Check digit |
X |
Sex, F, M or O (empty if not applicable) |
L |
Legal form (empty if not applicable) |
B |
Birth county (empty if not applicable) |
\ |
Escape the following character |
The following tokens are only valid for ids containing a date | |
A |
Current age |
Year | |
Y |
A full numeric representation of a year, 4 digits |
y |
A two digit representation of a year |
Month | |
m |
Numeric representation of a month, with leading zeros, 2 digits |
n |
Numeric representation of a month, without leading zeros, 1 through 12 |
F |
A full textual representation of a month, such as January or March |
M |
A short textual representation of a month, three letters, Jan through Dec |
t |
Number of days in the given month 28 through 31 |
Week | |
W |
ISO-8601 week number of year, weeks starting on Monday |
Day | |
d |
Day of the month, 2 digits with leading zeros |
j |
Day of the month without leading zeros, 1 to 31 |
l |
(lowercase 'L') A full textual representation of the day of the week |
D |
A textual representation of a day, three letters Mon through Sun |
w |
Numeric representation of the day of the week 0 (for Sunday) through 6 |
N |
ISO-8601 numeric representation of the day of the week 1 (for Monday) through 7 |
z |
The day of the year (starting from 0), 0 through 365 |
Definitions
Swedish sources on the construction and usage of id numbers:
Symfony Bundle
To use as validation rules in your Symfony project see the third party package IdentityNumberValidatorBundle.