KentekenAPI.php

Gesponsorde koppelingen

PHP script bestanden

  1. KentekenAPI.php

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php

Class KentekenAPI {

    protected $api = 'http://rdw.almere.pilod.nl/kentekens/%s';
    protected $properties;

    public function __construct($license = null) {

        $url = sprintf( $this->api, self::validate($license) );
        $data = $this->sendRequest($url);

        $this->properties = json_decode($data, true);
        $this->properties = self::convertToObject($this->properties);

    }


    public function __get($key) {

        if( isset($this->properties->resource) && array_key_exists($key, $this->properties->resource) ) {
            return $this->properties->resource->$key;
        }


        return null;

    }


    public function all() {
        return $this->properties->resource;
    }


    protected function sendRequest($url) {

        $curl = curl_init();

        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_URL, $url);

        return curl_exec($curl);

    }


    static protected function convertToObject($array) {

        $object = new stdClass();

        foreach($array as $key => $value) {

            if(is_array($value)) {
                $value = self::convertToObject($value);
            }


            $object->$key = $value;

        }


        return $object;

    }


    public function error() {
        return (isset($this->properties->error->message)) ? $this->properties->error->message : false;
    }


    static protected function validate($string = null) {
        return preg_replace('/[^a-zA-Z0-9]+/', '', $string);
    }

}

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.