Wat heb jij vandaag geprogrammeerd? 2.0

Gestart doorNielsba792 reacties10.961 weergaven

793 berichten · pagina 8 van 53

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Codeblok (voorbeeld.php):

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


/*
PageViewer
- Dylan
*/

namespace ExcellentCode;

final class PageViewer {
protected $_path, $_config;
public function __construct($path = "404", $config) {
if(count($config["pages"]) == 0) throw new Exception("No pages defined");
$this->_path = $path;
$this->_config = $config;
$this->_lookUp();
}


protected function _lookUp() {
if(isset($this->_config["pages"][$this->_path])) {
if(is_array($this->_config["pages"][$this->_path]) &&
isset($this->_config["pages"][$this->_path]["controller"]) &&
isset($this->_config["pages"][$this->_path]["url"])) {
if(file_exists(ABS_PATH . "/controllers/{$this->_config["pages"][$this->_path]["controller"]}.php") &&
is_readable(ABS_PATH . "/controllers/{$this->_config["pages"][$this->_path]["controller"]}.php")) {
require_once(ABS_PATH . "/controllers/{$this->_config["pages"][$this->_path]["controller"]}.php");
$controller = "ExcellentCodeControllers" . $this->_config["pages"][$this->_path]["controller"];
$controller = new $controller();
$controller->renderTemplate($this->_config["pages"][$this->_path]["url"]);
return;
}

include_once(ABS_PATH . "/pages/404.html");
return;
return;
}
else {
$page = (isset($this->_config["pages"][$this->_path]["url"]) ?
$this->_config["pages"][$this->_path]["url"] :
$this->_config["pages"][$this->_path]
);

if(file_exists(ABS_PATH . "/pages/{$page}") &&
is_readable(ABS_PATH . "/pages/{$page}")
) {

include_once(ABS_PATH . "/pages/{$page}");
return;
}
}
}

include_once(ABS_PATH . "/pages/404.html");
return;
}
}


Codeblok (voorbeeld.php):

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


/*
- controller class
dylan
*/


namespace ExcellentCode;

interface ControllerInterface {
public function setModels();
}


abstract class Controller {
public $models;

final public function __construct() {
if(method_exists($this, "__begin")) $this->__begin();
$this->setModels();
}


final protected function set($key, $val) {
$this->models[$key] = $val;
}


final public function renderTemplate($templateFile) {
if(file_exists(ABS_PATH . "/pages/{$templateFile}") &&
is_readable(ABS_PATH . "/pages/{$templateFile}")) {
$content = file_get_contents(ABS_PATH . "/pages/{$templateFile}");
foreach ($this->models as $key => $value) {
$content = str_replace("{{".$key."}}", $value, $content);
}


echo $content;
}
}
}
0
Stef

Lid

Berichten
10.150
Reputatie
2
Punten
0,00
Lid sinds
Laatst gezien
Dylan schreef:
Codeblok (voorbeeld.php):
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


/*
PageViewer
- Dylan
*/

namespace ExcellentCode;

final class PageViewer {
protected $_path, $_config;
public function __construct($path = "404", $config) {
if(count($config["pages"]) == 0) throw new Exception("No pages defined");
$this->_path = $path;
$this->_config = $config;
$this->_lookUp();
}


protected function _lookUp() {
if(isset($this->_config["pages"][$this->_path])) {
if(is_array($this->_config["pages"][$this->_path]) &&
isset($this->_config["pages"][$this->_path]["controller"]) &&
isset($this->_config["pages"][$this->_path]["url"])) {
if(file_exists(ABS_PATH . "/controllers/{$this->_config["pages"][$this->_path]["controller"]}.php") &&
is_readable(ABS_PATH . "/controllers/{$this->_config["pages"][$this->_path]["controller"]}.php")) {
require_once(ABS_PATH . "/controllers/{$this->_config["pages"][$this->_path]["controller"]}.php");
$controller = "ExcellentCodeControllers" . $this->_config["pages"][$this->_path]["controller"];
$controller = new $controller();
$controller->renderTemplate($this->_config["pages"][$this->_path]["url"]);
return;
}

include_once(ABS_PATH . "/pages/404.html");
return;
return;
}
else {
$page = (isset($this->_config["pages"][$this->_path]["url"]) ?
$this->_config["pages"][$this->_path]["url"] :
$this->_config["pages"][$this->_path]
);

if(file_exists(ABS_PATH . "/pages/{$page}") &&
is_readable(ABS_PATH . "/pages/{$page}")
) {

include_once(ABS_PATH . "/pages/{$page}");
return;
}
}
}

include_once(ABS_PATH . "/pages/404.html");
return;
}
}


Codeblok (voorbeeld.php):

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


/*
- controller class
dylan
*/


namespace ExcellentCode;

interface ControllerInterface {
public function setModels();
}


abstract class Controller {
public $models;

final public function __construct() {
if(method_exists($this, "__begin")) $this->__begin();
$this->setModels();
}


final protected function set($key, $val) {
$this->models[$key] = $val;
}


final public function renderTemplate($templateFile) {
if(file_exists(ABS_PATH . "/pages/{$templateFile}") &&
is_readable(ABS_PATH . "/pages/{$templateFile}")) {
$content = file_get_contents(ABS_PATH . "/pages/{$templateFile}");
foreach ($this->models as $key => $value) {
$content = str_replace("{{".$key."}}", $value, $content);
}


echo $content;
}
}
}

worshippyworshippyworshippy
0
Berichten
3.001
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Dylan schreef:
Spoiler tonen
Codeblok (voorbeeld.php):
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


/*
PageViewer
- Dylan
*/

namespace ExcellentCode;

final class PageViewer {
protected $_path, $_config;
public function __construct($path = "404", $config) {
if(count($config["pages"]) == 0) throw new Exception("No pages defined");
$this->_path = $path;
$this->_config = $config;
$this->_lookUp();
}


protected function _lookUp() {
if(isset($this->_config["pages"][$this->_path])) {
if(is_array($this->_config["pages"][$this->_path]) &&
isset($this->_config["pages"][$this->_path]["controller"]) &&
isset($this->_config["pages"][$this->_path]["url"])) {
if(file_exists(ABS_PATH . "/controllers/{$this->_config["pages"][$this->_path]["controller"]}.php") &&
is_readable(ABS_PATH . "/controllers/{$this->_config["pages"][$this->_path]["controller"]}.php")) {
require_once(ABS_PATH . "/controllers/{$this->_config["pages"][$this->_path]["controller"]}.php");
$controller = "ExcellentCodeControllers" . $this->_config["pages"][$this->_path]["controller"];
$controller = new $controller();
$controller->renderTemplate($this->_config["pages"][$this->_path]["url"]);
return;
}

include_once(ABS_PATH . "/pages/404.html");
return;
return;
}
else {
$page = (isset($this->_config["pages"][$this->_path]["url"]) ?
$this->_config["pages"][$this->_path]["url"] :
$this->_config["pages"][$this->_path]
);

if(file_exists(ABS_PATH . "/pages/{$page}") &&
is_readable(ABS_PATH . "/pages/{$page}")
) {

include_once(ABS_PATH . "/pages/{$page}");
return;
}
}
}

include_once(ABS_PATH . "/pages/404.html");
return;
}
}


Codeblok (voorbeeld.php):

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


/*
- controller class
dylan
*/


namespace ExcellentCode;

interface ControllerInterface {
public function setModels();
}


abstract class Controller {
public $models;

final public function __construct() {
if(method_exists($this, "__begin")) $this->__begin();
$this->setModels();
}


final protected function set($key, $val) {
$this->models[$key] = $val;
}


final public function renderTemplate($templateFile) {
if(file_exists(ABS_PATH . "/pages/{$templateFile}") &&
is_readable(ABS_PATH . "/pages/{$templateFile}")) {
$content = file_get_contents(ABS_PATH . "/pages/{$templateFile}");
foreach ($this->models as $key => $value) {
$content = str_replace("{{".$key."}}", $value, $content);
}


echo $content;
}
}
}


[c]namespace ExcellentCode;[/c] emo
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Wat bugfixes voor de nieuwe update voor Treinenweb die net online staat. Nu ook met live gegevens van rijdende treinen yummie
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
@Dylan

Config arrays in je class injecteren is een anti-pattern.
0
Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Raoul schreef:
@Dylan

Config arrays in je class injecteren is een anti-pattern.
$GLOBAS dan?
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Dylan schreef:
Eerdere citaten tonen
Raoul schreef:
Config arrays in je class injecteren is een anti-pattern.

$GLOBAS dan?
Dat is nog slechter emo Doe zoiets:

[COLOR= #0000BB]<?php[/COLOR]

interface PageRepository [COLOR= #007700]{[/COLOR]
  [URL="http://www.php.net/public"]public[/URL] [COLOR= #007700]function[/COLOR] getPage[COLOR= #007700]([/COLOR][COLOR= #0000BB]$name[/COLOR][COLOR= #007700]);
}[/COLOR]

[URL="http://www.php.net/class"]class[/URL] FilePageRepository implements PageRepository [COLOR= #007700]{[/COLOR]
  [URL="http://www.php.net/public"]public[/URL] [COLOR= #007700]function[/COLOR] getPage[COLOR= #007700]([/COLOR][COLOR= #0000BB]$name[/COLOR][COLOR= #007700]) {[/COLOR]
    [URL="http://www.php.net/return"]return[/URL] [URL="http://www.php.net/file_get_contents"]file_get_contents[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$name[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]// simplified[/COLOR]
  [COLOR= #007700]}
}[/COLOR]

[URL="http://www.php.net/class"]class[/URL] PageViewer [COLOR= #007700]{[/COLOR]
  [URL="http://www.php.net/private"]private[/URL] [COLOR= #0000BB]$repo[/COLOR][COLOR= #007700];[/COLOR]

  [URL="http://www.php.net/public"]public[/URL] [COLOR= #007700]function[/COLOR] __construct[COLOR= #007700]([/COLOR]PageRepository [COLOR= #0000BB]$repo[/COLOR][COLOR= #007700]) {[/COLOR]
    [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]repo [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$repo[/COLOR][COLOR= #007700];
  }[/COLOR]

  [URL="http://www.php.net/public"]public[/URL] [COLOR= #007700]function[/COLOR] renderPage[COLOR= #007700]([/COLOR][COLOR= #0000BB]$page[/COLOR][COLOR= #007700]) {[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]repo[COLOR= #007700]->[/COLOR]getPage[COLOR= #007700]([/COLOR][COLOR= #0000BB]$name[/COLOR][COLOR= #007700]);
  }
}[/COLOR]


Je pageviewer support nu in één klap files, pages van een DB, ...!

Dit heet het repository pattern. En als je serieus OO gaat gebruiken, bekijk een aantal patterns.
0
Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
@Raoul zou ik doen
Afbeelding

alleen nog dat poppetje wat opgehangen wordtemo
0
Berichten
279
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Een Licensed hosting provider Teamspeak 3

Moet aleen nog kleine bug fixen maken en die testen smile

- opgelost moest server query uithebben en ook slot edit log edit en file transfere.

Aangezien op vps dingen alle poorten openstaan. < beter ook voor die poorten ?
0
Berichten
1.533
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Een programma voor http://scrsha.re/, ben niet tevreden met die Quick Navigation view, wil daar iets anders maar heb geen idee wat.
Afbeelding
0
Berichten
20.364
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Joeryy schreef:
Een programma voor http://scrsha.re/, ben niet tevreden met die Quick Navigation view, wil daar iets anders maar heb geen idee wat.

Afbeelding
Het zou mooier zijn als je uppercase letters dikgedrukt maakt
0
Berichten
5.957
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ik heb de server structuur van mijn webapp http://anondraw.com helemaal aangepast zodat het nu op meerdere servers runt en dus kan scalen als er heel veel mensen op komen.

Dat zorgt ook voor een betere seperation of concerns (player server, realtime socket.io server en de loadbalancer zijn nu mooi apart).

Code staat op github: https://github.com/Squarific/drawtogether2/ voor de mensen die eens willen kijken hoe ik het doe.
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Zitten stoeien met nginx, in plaats van dat ik dacht dat hij met sites-enabled en sites-available werkte, bleek dus volgens nginx.conf dat het gewoon een sub.domain.com.conf is aah
Voortaan de configuratie checken ipv aannames doen... aah
0
Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
om 15, 10 en 5 min:
Afbeelding

om 15, 10 en 5 min:
Afbeelding

mijn eerste c# project.. DONE
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