2017 © Pedro PelĂĄez
 

library id

Data types for swedish social security and corporation id numbers

image

byrokrat/id

Data types for swedish social security and corporation id numbers

  • Friday, July 20, 2018
  • by hanneskod
  • Repository
  • 3 Watchers
  • 9 Stars
  • 9,143 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 7 Versions
  • 6 % Grown

The README.md

byrokrat, (*1)

Personal Identity

Packagist Version Build Status Quality Score, (*2)

Data types for swedish personal identity and corporation id numbers., (*3)

Installation

composer require byrokrat/id

Usage

use byrokrat\id\PersonalId;
use byrokrat\id\IdInterface;

$id = new PersonalId('940323-2383');

// outputs 940323-2383
echo $id;

// outputs 940323-2383
echo $id->format(IdInterface::FORMAT_10_DIGITS);

// outputs 199403232383
echo $id->format(IdInterface::FORMAT_12_DIGITS);

// outputs 940323
echo $id->format('ymd');

// outputs something like 25
echo $id->getAge();

// outputs 1 (true)
echo $id->isFemale();
use byrokrat\id\OrganizationId;
use byrokrat\id\IdInterface;

$id = new OrganizationId('835000-0892');

// outputs 835000-0892
echo $id->format(IdInterface::FORMAT_10_DIGITS);

// outputs 008350000892
echo $id->format(IdInterface::FORMAT_12_DIGITS);

// outputs 1 (true)
echo $id->isSexUndefined();

// outputs 1 (true)
echo $id->isNonProfit();

Class hierarchy

Creating ID objects

Creating ID objects can be complicated., (*4)

  • 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., (*5)

use byrokrat\id\PersonalIdFactory;
use byrokrat\id\CoordinationIdFactory;

$factory = new PersonalIdFactory(new CoordinationIdFactory);

$id = $factory->createId('940323-2383');

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., (*6)

The following factories are included:, (*7)

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., (*8)

, (*9)

use byrokrat\id\PersonalIdFactory;

$factory = new PersonalIdFactory;

// Year interpreted as 2010 as parsing is done 2020
$young = $factory->createId('1001012382', new \DateTime('20200101'));

// Year interpreted as 1910 as parsing is done 1990
$older = $factory->createId('1001012382', new \DateTime('19900101'));

// outputs 2010
echo $young->format('Y');

// outputs 1910
echo $older->format('Y');

Specifying parse date also affects what delimiter is used., (*10)

, (*11)

use byrokrat\id\PersonalIdFactory;

$factory = new PersonalIdFactory;

// Delimiter is '+' as parsing is done in 2050
$id = $factory->createId('194001079120', new \DateTime('20500101'));

// outputs 400107+9120
echo $id;

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)., (*12)

echo $id->format($formatStr);

If you need to format a large number of ids a formatter object can be created., (*13)

use byrokrat\id\Formatter\Formatter;
use byrokrat\id\PersonalId;

$formatter = new Formatter('y');

// outputs 82
echo $formatter->format(new PersonalId('940323-2383'));

Formatting tokens

Characters that are not formatting tokens are returned as they are by the formatter., (*14)

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:, (*15)

Symfony Bundle

To use as validation rules in your Symfony project see the third party package IdentityNumberValidatorBundle., (*16)

The Versions

20/07 2018

dev-master

9999999-dev https://github.com/byrokrat/id

Data types for swedish social security and corporation id numbers

  Sources   Download

WTFPL Unlicense

The Requires

  • php >=7.1

 

The Development Requires

by Hannes ForsgÄrd

id personnummer organisationsnummer personal id social security number corporation id

20/07 2018

2.0.0

2.0.0.0 https://github.com/byrokrat/id

Data types for swedish social security and corporation id numbers

  Sources   Download

Unlicense

The Requires

  • php >=7.1

 

by Hannes ForsgÄrd

id personnummer organisationsnummer personal id social security number corporation id

20/07 2018

2.0.x-dev

2.0.9999999.9999999-dev https://github.com/byrokrat/id

Data types for swedish social security and corporation id numbers

  Sources   Download

Unlicense

The Requires

  • php >=7.1

 

The Development Requires

by Hannes ForsgÄrd

id personnummer organisationsnummer personal id social security number corporation id

20/12 2017

1.1.0

1.1.0.0 https://github.com/byrokrat/id

Data types for swedish social security and corporation id numbers

  Sources   Download

Unlicense

The Requires

  • php >=5.5

 

The Development Requires

by Hannes ForsgÄrd

id personnummer organisationsnummer personal id social security number corporation id

18/08 2016

1.0.2

1.0.2.0 https://github.com/byrokrat/id

Data types for swedish social security and corporation id numbers

  Sources   Download

WTFPL

The Requires

 

by Hannes ForsgÄrd

id personnummer organisationsnummer personal id social security number corporation id

04/05 2016

1.0.1

1.0.1.0 https://github.com/byrokrat/id

Data types for swedish social security and corporation id numbers

  Sources   Download

WTFPL

The Requires

 

by Hannes ForsgÄrd

id personnummer organisationsnummer personal id social security number corporation id

27/01 2015

1.0.0

1.0.0.0 https://github.com/byrokrat/id

Data types for swedish social security and corporation id numbers

  Sources   Download

WTFPL

The Requires

 

by Hannes ForsgÄrd

id personnummer organisationsnummer personal id social security number corporation id