[GRATIS] Config class PHP

Gestart doorJenner18 reacties22 weergaven

19 berichten · pagina 1 van 2

Jenner

Lid · Topicstarter

Berichten
1.544
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hier is gratis en voor niets een config class die ik zelf altijd gebruik in mijn eigen projecten. Ik vind hem zelf zeer aan te raden. Vooral omdat je dieper kunt zoeken in je configuraties.

Opties: (En tevens voorbeeld pagina)

[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #FF8000]//Verplicht voor het laden van de configuratie files.[/COLOR]
[URL="http://www.php.net/define"]define[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]BASEPATH[/COLOR][COLOR= #007700],[/COLOR] [URL="http://www.php.net/dirname"]dirname[/URL][COLOR= #007700]([/COLOR]__FILE__[COLOR= #007700]).[/COLOR][COLOR= #DD0000]/[/COLOR][COLOR= #007700]);[/COLOR]

[COLOR= #FF8000]//Hij kan een configuratie bestand laden.[/COLOR]
Config[COLOR= #007700]::[/COLOR]load[COLOR= #007700]([/COLOR][COLOR= #DD0000]dir/file.php[/COLOR][COLOR= #007700]);[/COLOR]

[COLOR= #FF8000]//Hij zoekt dieper in de configuratie array doormiddel van puntjes tussen de partjes.
//Deze variabele staat dus in self::$config[db][host][/COLOR]
Config[COLOR= #007700]::[/COLOR]get[COLOR= #007700]([/COLOR][COLOR= #DD0000]db.host[/COLOR][COLOR= #007700]);[/COLOR]

[COLOR= #FF8000]//Hij kan variabele definered ook in diepere lagen.[/COLOR]
Config[COLOR= #007700]:[/COLOR]SMILEYYYYYYYYYYYBEGIN[COLOR= #007700]:[/COLOR]set[COLOR= #007700]([/COLOR][COLOR= #DD0000]db.username[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]MijnGebruikersnaam[/COLOR][COLOR= #007700]);[/COLOR]

[COLOR= #FF8000]//Hij kan kijken of de variabele bestaat.[/COLOR]
Config[COLOR= #007700]::[/COLOR]exist[COLOR= #007700]([/COLOR][COLOR= #DD0000]db.host[/COLOR][COLOR= #007700]);[/COLOR]

[COLOR= #FF8000]//Hij kan en configuratie variabele verwijderen[/COLOR]
Config[COLOR= #007700]::[/COLOR]remove[COLOR= #007700]([/COLOR][COLOR= #DD0000]db.database[/COLOR][COLOR= #007700]);[/COLOR]

[COLOR= #FF8000]//Je kan zo diep kijken als je wilt.[/COLOR]
Config[COLOR= #007700]::[/COLOR]get[COLOR= #007700]([/COLOR][COLOR= #DD0000]hoi.test.test2.blup.jenner.nooo.neenee.quit.tada[/COLOR][COLOR= #007700]);[/COLOR]
?>


Graag feedback van wat er kan verbeteren. (Of Engelse fouten, want mijn Engels is niet mijn sterkste ding emo)

De code:
De exception die ik aanroep is eigenlijk heel simpel. Deze plaats je gewoon in klikexception.php
Spoiler tonen
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/class"]class[/URL] KlikjesException extends Exception [COLOR= #007700]{ }[/COLOR]
?>
Dan heb je een voorbeeld configuratie bestand: (In het voorbeeld dus dir/file.php)
Spoiler tonen
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/return"]return[/URL] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]([/COLOR]
    [COLOR= #DD0000]db[/COLOR] [COLOR= #007700]=>[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]([/COLOR]
        [COLOR= #DD0000]hostname[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000]localhost[/COLOR][COLOR= #007700],[/COLOR]
        [COLOR= #DD0000]username[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000]username[/COLOR][COLOR= #007700],[/COLOR]
        [COLOR= #DD0000]password[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000]password[/COLOR][COLOR= #007700],[/COLOR]
        [COLOR= #DD0000]database[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000]database[/COLOR]
    [COLOR= #007700])
);[/COLOR]
?>
En tot slot de echte class:
Spoiler tonen
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #FF8000]/**
 * The config class for saving configs
 *
 * @author Jan Erik van Woerden <info@janerik.eu>
 * @copyright Jan Erik van Woerden 2012
 * @version 1.0
 */[/COLOR]
[URL="http://www.php.net/class"]class[/URL] Config [COLOR= #007700]{[/COLOR]

    [COLOR= #FF8000]/**
     * Save all the config
     *
     * @var array
     */[/COLOR]
    [URL="http://www.php.net/private"]private[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #0000BB]$config[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]();[/COLOR]
    
    
    [COLOR= #FF8000]/**
     * Get a config variable
     *
     * @param string $string The search string
     * @return mixed The return of the config.
     */[/COLOR]
    [URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] get[COLOR= #007700]([/COLOR][COLOR= #0000BB]$string[/COLOR] [COLOR= #007700]=[/COLOR] false[COLOR= #007700]) {[/COLOR]
    
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/empty"]empty[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$string[/COLOR][COLOR= #007700]))[/COLOR]
            [URL="http://www.php.net/return"]return[/URL] self[COLOR= #007700]:[/COLOR][COLOR= #007700]:[/COLOR][COLOR= #0000BB]$config[/COLOR][COLOR= #007700];[/COLOR]
    
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]( ![/COLOR] self[COLOR= #007700]::[/COLOR]exist[COLOR= #007700]([/COLOR][COLOR= #0000BB]$string[/COLOR][COLOR= #007700]))[/COLOR]
            throw [COLOR= #007700]new[/COLOR] KlikjesException[COLOR= #007700]([/COLOR][COLOR= #DD0000]The search variable doesn	 exist.[/COLOR][COLOR= #007700]);[/COLOR]
        
        [COLOR= #0000BB]$current[/COLOR] [COLOR= #007700]=[/COLOR] self[COLOR= #007700]:[/COLOR][COLOR= #007700]:[/COLOR][COLOR= #0000BB]$config[/COLOR][COLOR= #007700];[/COLOR]
        
        [URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR]self[COLOR= #007700]::[/COLOR]_stripSearch[COLOR= #007700]([/COLOR][COLOR= #0000BB]$string[/COLOR][COLOR= #007700]) as[/COLOR] [COLOR= #0000BB]$part[/COLOR][COLOR= #007700]) {[/COLOR]
            [COLOR= #0000BB]$current[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$current[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]$part[/COLOR][COLOR= #007700]];
        }[/COLOR]
        
        [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$current[/COLOR][COLOR= #007700];
    
    }[/COLOR]
    
    
    [COLOR= #FF8000]/**
     * Set a config variable
     *
     * @param string $string The search string
     * @param mixed $value The value you want to put into the config
     * @return mixed The return of the config.
     */[/COLOR]
    [URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] set[COLOR= #007700]([/COLOR][COLOR= #0000BB]$string[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$value[/COLOR][COLOR= #007700]) {[/COLOR]
    
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]( ![/COLOR] [URL="http://www.php.net/is_string"]is_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$string[/COLOR][COLOR= #007700]))[/COLOR]
            throw [COLOR= #007700]new[/COLOR] KlikjesException[COLOR= #007700]([/COLOR][COLOR= #DD0000]The search variable isn	 a string.[/COLOR][COLOR= #007700]);[/COLOR]
            
        [COLOR= #0000BB]$current[/COLOR] [COLOR= #007700]= &[/COLOR] self[COLOR= #007700]:[/COLOR][COLOR= #007700]:[/COLOR][COLOR= #0000BB]$config[/COLOR][COLOR= #007700];[/COLOR]
        
        [URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR]self[COLOR= #007700]::[/COLOR]_stripSearch[COLOR= #007700]([/COLOR][COLOR= #0000BB]$string[/COLOR][COLOR= #007700]) as[/COLOR] [COLOR= #0000BB]$part[/COLOR][COLOR= #007700]) {[/COLOR]
        
            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]( ![/COLOR] [URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$current[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]$part[/COLOR][COLOR= #007700]]) || ![/COLOR] [URL="http://www.php.net/is_array"]is_array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$current[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]$part[/COLOR][COLOR= #007700]]))[/COLOR]
                [COLOR= #0000BB]$current[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]$part[/COLOR][COLOR= #007700]] =[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]();[/COLOR]
            
            [COLOR= #0000BB]$current[/COLOR] [COLOR= #007700]= &[/COLOR] [COLOR= #0000BB]$current[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]$part[/COLOR][COLOR= #007700]];
        
        }[/COLOR]
        
        [COLOR= #0000BB]$current[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$value[/COLOR][COLOR= #007700];
    
    }[/COLOR]
    
    
    [COLOR= #FF8000]/**
     * Does the config variable exist?
     *
     * @param string $string The search string
     * @return bool True when exist
     */[/COLOR]
    [URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] exist[COLOR= #007700]([/COLOR][COLOR= #0000BB]$string[/COLOR][COLOR= #007700]) {[/COLOR]
    
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]( ![/COLOR] [URL="http://www.php.net/is_string"]is_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$string[/COLOR][COLOR= #007700]))[/COLOR]
            throw [COLOR= #007700]new[/COLOR] KlikjesException[COLOR= #007700]([/COLOR][COLOR= #DD0000]The search variable isn	 a string.[/COLOR][COLOR= #007700]);[/COLOR]
            
        [COLOR= #0000BB]$current[/COLOR] [COLOR= #007700]=[/COLOR] self[COLOR= #007700]:[/COLOR][COLOR= #007700]:[/COLOR][COLOR= #0000BB]$config[/COLOR][COLOR= #007700];[/COLOR]
        
        [URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR]self[COLOR= #007700]::[/COLOR]_stripSearch[COLOR= #007700]([/COLOR][COLOR= #0000BB]$string[/COLOR][COLOR= #007700]) as[/COLOR] [COLOR= #0000BB]$part[/COLOR][COLOR= #007700]) {[/COLOR]
        
            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/is_array"]is_array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$current[/COLOR][COLOR= #007700]) &&[/COLOR] [URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$current[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]$part[/COLOR][COLOR= #007700]])) {[/COLOR]
                [COLOR= #0000BB]$current[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$current[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]$part[/COLOR][COLOR= #007700]];
            }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
                [URL="http://www.php.net/return"]return[/URL] false[COLOR= #007700];
            }
        
        }[/COLOR]
        
        [URL="http://www.php.net/return"]return[/URL] true[COLOR= #007700];
    
    }[/COLOR]
    
    
    [COLOR= #FF8000]/**
     * Remove a config variable
     *
     * @param string $string The search string
     * @return void
     */[/COLOR]
    [URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] remove[COLOR= #007700]([/COLOR][COLOR= #0000BB]$string[/COLOR][COLOR= #007700]) {[/COLOR]
    
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]( ![/COLOR] self[COLOR= #007700]::[/COLOR]exist[COLOR= #007700]([/COLOR][COLOR= #0000BB]$string[/COLOR][COLOR= #007700]))[/COLOR]
            throw [COLOR= #007700]new[/COLOR] KlikjesException[COLOR= #007700]([/COLOR][COLOR= #DD0000]The search variable doesn	 exist.[/COLOR][COLOR= #007700]);[/COLOR]
        
        [COLOR= #0000BB]$current[/COLOR] [COLOR= #007700]=[/COLOR] self[COLOR= #007700]:[/COLOR][COLOR= #007700]:[/COLOR][COLOR= #0000BB]$config[/COLOR][COLOR= #007700];[/COLOR]
        
        [URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR]self[COLOR= #007700]::[/COLOR]_stripSearch[COLOR= #007700]([/COLOR][COLOR= #0000BB]$string[/COLOR][COLOR= #007700]) as[/COLOR] [COLOR= #0000BB]$part[/COLOR][COLOR= #007700]) {[/COLOR]
            [COLOR= #0000BB]$current[/COLOR] [COLOR= #007700]= &[/COLOR] [COLOR= #0000BB]$current[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]$part[/COLOR][COLOR= #007700]];
        }[/COLOR]
        
        [URL="http://www.php.net/unset"]unset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$current[/COLOR][COLOR= #007700]);
    
    }[/COLOR]
    
    
    [COLOR= #FF8000]/**
     * Load manual a config file
     * 
     * @param string $file The file you want to load. (Basepath is defined in BASEPATH)
     * @param string|bool $variable In witch variable do you want to put your config?
     * @return mixed The return of the loaded file
     */[/COLOR]
    [URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] manualLoad[COLOR= #007700]([/COLOR][COLOR= #0000BB]$file[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$variable[/COLOR] [COLOR= #007700]=[/COLOR] false[COLOR= #007700]) {[/COLOR]
    
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]( ![/COLOR] [URL="http://www.php.net/is_string"]is_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$file[/COLOR][COLOR= #007700]) || ![/COLOR] [URL="http://www.php.net/file_exists"]file_exists[/URL][COLOR= #007700]([/COLOR]BASEPATH[COLOR= #007700].[/COLOR][COLOR= #0000BB]$file[/COLOR][COLOR= #007700]))[/COLOR]
            throw [COLOR= #007700]new[/COLOR] KlikjesException[COLOR= #007700]([/COLOR][COLOR= #DD0000]The config file didn	 exist. ([/COLOR][COLOR= #007700].[/COLOR]BASEPATH[COLOR= #007700].[/COLOR][COLOR= #0000BB]$file[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000])[/COLOR][COLOR= #007700]);[/COLOR]
            
        [COLOR= #0000BB]$content[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/require"]require[/URL][COLOR= #007700]([/COLOR]BASEPATH[COLOR= #007700].[/COLOR][COLOR= #0000BB]$file[/COLOR][COLOR= #007700]);[/COLOR]
        
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]( ![/COLOR] [URL="http://www.php.net/empty"]empty[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$variable[/COLOR][COLOR= #007700]) && ![/COLOR] [URL="http://www.php.net/is_string"]is_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$variable[/COLOR][COLOR= #007700]))[/COLOR]
            throw [COLOR= #007700]new[/COLOR] KlikjesException[COLOR= #007700]([/COLOR][COLOR= #DD0000]The config variable isn	 a string.[/COLOR][COLOR= #007700]);[/COLOR]
            
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]( ![/COLOR] [URL="http://www.php.net/empty"]empty[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$variable[/COLOR][COLOR= #007700])) {[/COLOR]
            self[COLOR= #007700]:[/COLOR]SMILEYYYYYYYYYYYBEGIN[COLOR= #007700]:[/COLOR]set[COLOR= #007700]([/COLOR][COLOR= #0000BB]$variable[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$content[/COLOR][COLOR= #007700]);
        }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
            self[COLOR= #007700]:[/COLOR][COLOR= #007700]:[/COLOR][COLOR= #0000BB]$config[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array_merge"]array_merge[/URL][COLOR= #007700]([/COLOR]self[COLOR= #007700]::[/COLOR]get[COLOR= #007700](),[/COLOR] [COLOR= #0000BB]$content[/COLOR][COLOR= #007700]);
        }[/COLOR]
        
        [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$content[/COLOR][COLOR= #007700];
    
    }[/COLOR]
    
    
    [COLOR= #FF8000]/**
     * Calls the manualLoad, but add as $variable the filename
     *
     * @param string $file The file you want to load. (Basepath is defined in BASEPATH)
     * @return mixed The return of the loaded file
     */[/COLOR]
    [URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] load[COLOR= #007700]([/COLOR][COLOR= #0000BB]$file[/COLOR][COLOR= #007700]) {[/COLOR]
    
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]( ![/COLOR] [URL="http://www.php.net/is_string"]is_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$file[/COLOR][COLOR= #007700]) || ![/COLOR] [URL="http://www.php.net/file_exists"]file_exists[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$file[/COLOR][COLOR= #007700]));[/COLOR]
            throw [COLOR= #007700]new[/COLOR] KlikjesException[COLOR= #007700]([/COLOR][COLOR= #DD0000]The config file didn	 exist.[/COLOR][COLOR= #007700]);[/COLOR]
            
        [COLOR= #0000BB]$filename[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/basename"]basename[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$file[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000].php[/COLOR][COLOR= #007700]);[/COLOR]
        [COLOR= #0000BB]$configdir[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]config/[/COLOR][COLOR= #007700];[/COLOR]
        
        
        [URL="http://www.php.net/return"]return[/URL] self[COLOR= #007700]::[/COLOR]manualLoad[COLOR= #007700]([/COLOR][COLOR= #0000BB]$configdir[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$file[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$filename[/COLOR][COLOR= #007700]);
    
    }[/COLOR]
    
    
    [COLOR= #FF8000]/**
     * Split the search string in parts
     *
     * @param string $string The string you want to split
     * @return array The parts
     */[/COLOR]
    [URL="http://www.php.net/protected"]protected[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] _stripSearch[COLOR= #007700]([/COLOR][COLOR= #0000BB]$string[/COLOR][COLOR= #007700]) {[/COLOR]
        [COLOR= #0000BB]$parts[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/explode"]explode[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000].[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$string[/COLOR][COLOR= #007700]);[/COLOR]
        [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$parts[/COLOR][COLOR= #007700];
    }

}[/COLOR]
?>
0
Berichten
9.953
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Handig en netjes, mijn complimenten! biggrin
0
Janm

Lid

Berichten
6.170
Reputatie
1
Punten
0,00
Lid sinds
Laatst gezien
Bedankt biggrin
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Moet dit niet naar webwereld emo
0
Jenner

Lid · Topicstarter

Berichten
1.544
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Vriendje schreef:
Moet dit niet naar webwereld emo
Plop, waar denk je dat het staat dan? smile
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Mijn foutje, issie al
0
Jenner

Lid · Topicstarter

Berichten
1.544
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Janm schreef:
Bedankt biggrin
Alsjeblieft wink
Sebastiaanh schreef:
Handig en netjes, mijn complimenten! biggrin
Bedankt smile Nog opmerkingen of verbeter puntjes? smile
0
Berichten
1.631
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Heb je paar voorbeelden van hoe je die functies gebruikt?
0
Jenner

Lid · Topicstarter

Berichten
1.544
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Wouterp schreef:
Heb je paar voorbeelden van hoe je die functies gebruikt?
Als je bijvoorbeeld een database config pagina hebt in directory: config/db.php

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/return"]return[/URL] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]([/COLOR]
    [COLOR= #DD0000]hostname[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000]localhost[/COLOR][COLOR= #007700],[/COLOR]
    [COLOR= #DD0000]username[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000]username[/COLOR][COLOR= #007700],[/COLOR]
    [COLOR= #DD0000]password[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000]password[/COLOR][COLOR= #007700],[/COLOR]
    [COLOR= #DD0000]database[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000]datanase[/COLOR]
[COLOR= #007700]);[/COLOR]
?>


Voorbeeld: (In gewoon index.php)

[COLOR= #0000BB]<?php[/COLOR]
Config[COLOR= #007700]::[/COLOR]load[COLOR= #007700]([/COLOR][COLOR= #DD0000]config/db.php[/COLOR][COLOR= #007700]);[/COLOR]

[COLOR= #FF8000]//De geladen configuratie zet hij standaard in de filename dus in dit geval zet hij alle variabele van
// config/db.php in de variabele db. En die kun je zo opvragen:[/COLOR]
[COLOR= #0000BB]$db[/COLOR] [COLOR= #007700]= new[/COLOR] MySQLi[COLOR= #007700]([/COLOR]Config[COLOR= #007700]::[/COLOR]get[COLOR= #007700]([/COLOR][COLOR= #DD0000]db.hostname[/COLOR][COLOR= #007700]),[/COLOR] Config[COLOR= #007700]::[/COLOR]get[COLOR= #007700]([/COLOR][COLOR= #DD0000]db.username[/COLOR][COLOR= #007700]),[/COLOR] Config[COLOR= #007700]::[/COLOR]get[COLOR= #007700]([/COLOR][COLOR= #DD0000]db.password[/COLOR][COLOR= #007700]),[/COLOR] Config[COLOR= #007700]::[/COLOR]get[COLOR= #007700]([/COLOR][COLOR= #DD0000]db.database[/COLOR][COLOR= #007700]));
?[/COLOR]
0
Berichten
1.631
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Oke en daarvoor is het hele script?
0
Jenner

Lid · Topicstarter

Berichten
1.544
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Wouterp schreef:
Oke en daarvoor is het hele script?
Als je het script gaat onderzoeken zul je erachter dat ik bijna niks onnodig is. Zoals bovenin als voorbeeld is aangeven. Die functies zitten er in. En volgens mij hebben ze allemaal een goede reden om te bestaan yummie
0
Janm

Lid

Berichten
6.170
Reputatie
1
Punten
0,00
Lid sinds
Laatst gezien
Wouterp schreef:
Oke en daarvoor is het hele script?
Commentaar kun je eruit halen, scheeld veel regels. wink
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Waarom een exceptionclass aanmaken zonder iets erin? Kan je net zo goed gewoon Exception() gebruiken.
0
Jenner

Lid · Topicstarter

Berichten
1.544
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Rik schreef:
Waarom een exceptionclass aanmaken zonder iets erin? Kan je net zo goed gewoon Exception() gebruiken.
In dit geval is het nutteloos, maar als je eenmaal grotere websites bouwt is het soms handiger om verschillende exceptions te maken. Bv eentje voor db, eentje voor auth class. Alles ten behoeve van de overzichtelijkheid, maar in dit geval nutteloos wink
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Dus als ik het goed begrijp kan je hiermee variables aanmaken, verwijderen, aanpassen en een bestand inladen... lijkt me nogal nutteloos.
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren