├── README.md
├── bin
└── openkvk
├── composer.json
├── composer.lock
└── src
└── OpenKvk
├── Client.php
└── Command
├── GetByKvkCommand.php
├── GetByNameCommand.php
└── GetBySbiCommand.php
/README.md:
--------------------------------------------------------------------------------
1 | # OpenKVK Client library + commandline utility
2 |
3 | This repository contains a simple PHP client for the [www.openkvk.nl](http://www.openkvk.nl) API.
4 |
5 | ## How to use it as a library
6 |
7 | Simply include the library through composer:
8 |
9 | "linkorb/openkvk": "dev-master"
10 |
11 | After this, you can instantiate and use the client as follows:
12 |
13 | // Instantiate the client
14 | $client = new \OpenKvk\Client();
15 |
16 | // Get data by Kvk nr
17 | $csv = $client->getByKvk("24365015");
18 |
19 | // Convert into a PHP array
20 | $data = $client->csvToArray($csv);
21 |
22 | // Output array
23 | print_r($data); // Outputs array by key/value
24 |
25 | ## How to use it as a command line utility
26 |
27 | The included `bin/openkvk` command is based on the Symfony Console component
28 |
29 | Example usage:
30 |
31 | bin/openkvk # output available options
32 | bin/openkvk openkvk:getbykvk 24365015 # get info by kvk number
33 | bin/openkvk openkvk:getbyname "LinkORB" # get info by companyname
34 | bin/openkvk openkvk:getbysbi 85.59.2 # get info by SBI (85592 = business training and education)
35 |
36 | ## Resources
37 |
38 | * [OpenKVK website](https://openkvk.nl/)
39 | * [SBI Codes - English](http://www.kvk.nl/download/SBI_2008_Engels_tcm14-195658.pdf)
40 |
41 | ## Brought to you by the LinkORB Engineering team
42 |
43 | 
44 | Check out our other projects at [linkorb.com/engineering](http://www.linkorb.com/engineering).
45 |
46 | Btw, we're hiring!
47 |
48 |
--------------------------------------------------------------------------------
/bin/openkvk:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 | setCatchExceptions(true);
11 | $application->add(new \OpenKvk\Command\GetByKvkCommand());
12 | $application->add(new \OpenKvk\Command\GetByNameCommand());
13 | $application->add(new \OpenKvk\Command\GetBySbiCommand());
14 | $application->run();
15 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "linkorb/openkvk",
3 | "description": "OpenKVK library and commmand-line tools",
4 | "homepage": "http://www.github.com/linkorb/openkvk-php",
5 | "keywords": ["kvk", "nederland", "chamberofcommerce", "api"],
6 | "type": "library",
7 | "minimum-stability": "dev" ,
8 | "require": {
9 | "symfony/console": "~2.4"
10 | },
11 | "autoload": {
12 | "psr-0": {
13 | "OpenKvk\\": "src/"
14 | }
15 | },
16 | "bin": ["bin/openkvk"]
17 | }
18 |
--------------------------------------------------------------------------------
/composer.lock:
--------------------------------------------------------------------------------
1 | {
2 | "_readme": [
3 | "This file locks the dependencies of your project to a known state",
4 | "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
5 | ],
6 | "hash": "08160ae539ab1233b7deaa700b7bbd21",
7 | "packages": [
8 | {
9 | "name": "symfony/console",
10 | "version": "2.4.x-dev",
11 | "target-dir": "Symfony/Component/Console",
12 | "source": {
13 | "type": "git",
14 | "url": "https://github.com/symfony/Console.git",
15 | "reference": "3c1496ae96d24ccc6c340fcc25f71d7a1ab4c12c"
16 | },
17 | "dist": {
18 | "type": "zip",
19 | "url": "https://api.github.com/repos/symfony/Console/zipball/3c1496ae96d24ccc6c340fcc25f71d7a1ab4c12c",
20 | "reference": "3c1496ae96d24ccc6c340fcc25f71d7a1ab4c12c",
21 | "shasum": ""
22 | },
23 | "require": {
24 | "php": ">=5.3.3"
25 | },
26 | "require-dev": {
27 | "symfony/event-dispatcher": "~2.1"
28 | },
29 | "suggest": {
30 | "symfony/event-dispatcher": ""
31 | },
32 | "type": "library",
33 | "extra": {
34 | "branch-alias": {
35 | "dev-master": "2.4-dev"
36 | }
37 | },
38 | "autoload": {
39 | "psr-0": {
40 | "Symfony\\Component\\Console\\": ""
41 | }
42 | },
43 | "notification-url": "https://packagist.org/downloads/",
44 | "license": [
45 | "MIT"
46 | ],
47 | "authors": [
48 | {
49 | "name": "Fabien Potencier",
50 | "email": "fabien@symfony.com"
51 | },
52 | {
53 | "name": "Symfony Community",
54 | "homepage": "http://symfony.com/contributors"
55 | }
56 | ],
57 | "description": "Symfony Console Component",
58 | "homepage": "http://symfony.com",
59 | "time": "2013-11-27 09:10:40"
60 | }
61 | ],
62 | "packages-dev": [
63 |
64 | ],
65 | "aliases": [
66 |
67 | ],
68 | "minimum-stability": "dev",
69 | "stability-flags": {
70 | "symfony/console": 20
71 | },
72 | "platform": [
73 |
74 | ],
75 | "platform-dev": [
76 |
77 | ]
78 | }
79 |
--------------------------------------------------------------------------------
/src/OpenKvk/Client.php:
--------------------------------------------------------------------------------
1 | responseFormat = $format;
21 | break;
22 | }
23 | }
24 |
25 | public function doQuery($query, $format = null)
26 | {
27 | $query = str_replace("\n", " ", $query);
28 | if (!$format) {
29 | $format = $this->responseFormat;
30 | }
31 |
32 | $url = $this->baseurl . '/' . $format . '/' . rawurlencode($query);
33 | $ch = curl_init($url);
34 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
35 | curl_setopt($ch, CURLOPT_HEADER, 0);
36 | $data = curl_exec($ch);
37 | curl_close($ch);
38 | return $data;
39 | }
40 |
41 | public function getByKvk($kvknr)
42 | {
43 | $data = $this->doQuery(sprintf("SELECT * FROM kvk WHERE kvks = '%s' LIMIT 1;", $kvknr));
44 | return $data;
45 | }
46 |
47 | public function getByName($name, $limit = 10)
48 | {
49 | $name=strtolower($name);
50 | $data = $this->doQuery(sprintf("SELECT * FROM kvk WHERE bedrijfsnaam ILIKE '%%%s%%' LIMIT %d ;", $name, $limit));
51 | return $data;
52 | }
53 |
54 | public function getBySbi($sbi)
55 | {
56 | $data = $this->doQuery(
57 | sprintf(
58 | "SELECT * FROM kvk
59 | JOIN kvk_sbi ON kvk_sbi.kvk = kvk.kvk
60 | WHERE code = '%s'
61 | AND isnull(status);"
62 | , $sbi
63 | )
64 | );
65 | return $data;
66 | }
67 |
68 | public function csvToArray($csv)
69 | {
70 | $lines = explode("\n", $csv);
71 | $head = str_getcsv(array_shift($lines), ',', '"');
72 | $array = array();
73 | foreach ($lines as $line) {
74 | if (trim($line)!='') {
75 | $array[] = array_combine($head, str_getcsv($line));
76 | }
77 | }
78 | return $array;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/OpenKvk/Command/GetByKvkCommand.php:
--------------------------------------------------------------------------------
1 | setName('openkvk:getbykvk')
18 | ->setDescription('Get info by kvk nr')
19 | ->addArgument(
20 | 'kvknr',
21 | InputArgument::REQUIRED,
22 | 'KVK Number'
23 | )
24 | ->addOption(
25 | 'format',
26 | null,
27 | InputOption::VALUE_REQUIRED,
28 | 'Format'
29 | );
30 | }
31 |
32 | protected function execute(InputInterface $input, OutputInterface $output)
33 | {
34 | $kvknr = $input->getArgument('kvknr');
35 | $client = new OpenKvkClient();
36 | $format = $input->getOption('format');
37 | if ($format!='') {
38 | $client->setResponseFormat($format);
39 | }
40 | $data = $client->getByKvk($kvknr);
41 | echo($data);
42 | //echo "Results: " . count($data) . "\n";
43 | return;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/OpenKvk/Command/GetByNameCommand.php:
--------------------------------------------------------------------------------
1 | setName('openkvk:getbyname')
18 | ->setDescription('Get info by company name')
19 | ->addArgument(
20 | 'name',
21 | InputArgument::REQUIRED,
22 | 'Company name'
23 | )
24 | ->addOption(
25 | 'format',
26 | null,
27 | InputOption::VALUE_REQUIRED,
28 | 'Format'
29 | );
30 | }
31 |
32 | protected function execute(InputInterface $input, OutputInterface $output)
33 | {
34 | $name = $input->getArgument('name');
35 | $client = new OpenKvkClient();
36 | $format = $input->getOption('format');
37 | if ($format!='') {
38 | $client->setResponseFormat($format);
39 | }
40 | $data = $client->getByName($name);
41 | echo $data;
42 | //echo "Results: " . count($data) . "\n";
43 | return;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/OpenKvk/Command/GetBySbiCommand.php:
--------------------------------------------------------------------------------
1 | setName('openkvk:getbysbi')
18 | ->setDescription('Test request')
19 | ->addArgument(
20 | 'sbi',
21 | InputArgument::REQUIRED,
22 | 'SBI'
23 | )
24 | ->addOption(
25 | 'format',
26 | null,
27 | InputOption::VALUE_REQUIRED,
28 | 'Format'
29 | );
30 | }
31 |
32 | protected function execute(InputInterface $input, OutputInterface $output)
33 | {
34 | $sbi = $input->getArgument('sbi');
35 | $client = new OpenKvkClient();
36 | $format = $input->getOption('format');
37 | if ($format!='') {
38 | $client->setResponseFormat($format);
39 | }
40 | $data = $client->getBySbi($sbi);
41 | echo $data;
42 | //echo "Results: " . count($data) . "\n";
43 | return;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------