1 | <?php |
||
21 | final class JsynExtractor |
||
22 | { |
||
23 | /** |
||
24 | * @var string |
||
25 | * |
||
26 | * Content of the JSYN File |
||
27 | */ |
||
28 | private $jsyn; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | * |
||
33 | * SQL Syntax to use for script generation |
||
34 | */ |
||
35 | private $sqlSyntax; |
||
36 | |||
37 | /** |
||
38 | * @param $jsynFile string | PathUtil |
||
39 | * @param $sqlSyntax string |
||
40 | */ |
||
41 | public function __construct($jsynFile, $sqlSyntax) |
||
42 | { |
||
43 | self::setJsynFile($jsynFile); |
||
44 | self::setSqlSyntax($sqlSyntax); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * @param $jsynFile string | PathUtil |
||
49 | * |
||
50 | * Setter function for the jsonFile global property |
||
51 | * |
||
52 | * @return void |
||
53 | */ |
||
54 | public function setJsynFile($jsynFile) |
||
55 | { |
||
56 | $this->jsyn = json_decode(file_get_contents($jsynFile)); |
||
57 | |||
58 | if (isset($this->sqlSyntax)) { |
||
59 | $sqlSyntax = $this->sqlSyntax; |
||
60 | <<<<<<< HEAD |
||
61 | if (!isset($this->jsyn->$sqlSyntax)) { |
||
62 | ======= |
||
63 | if (!isset($this->jsyn->$sqlSyntax)){ |
||
64 | >>>>>>> 4842a8f3c157a08b4e970aaaefdcc71fbe6b6c13 |
||
65 | $sqlSyntax = "default"; |
||
66 | } |
||
67 | $this->jsyn = $this->jsyn->$sqlSyntax; |
||
68 | } |
||
69 | |||
70 | return; |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @param $sqlSyntax string |
||
75 | * |
||
76 | * Setter function for the sqlSyntax global property |
||
77 | * |
||
78 | * @return void |
||
79 | */ |
||
80 | public function setSqlSyntax($sqlSyntax) |
||
81 | { |
||
82 | $this->sqlSyntax = $sqlSyntax; |
||
83 | |||
84 | if (isset($this->jsyn->$sqlSyntax)) { |
||
85 | $this->jsyn = $this->jsyn->$sqlSyntax; |
||
86 | } else { |
||
87 | $sqlSyntax ="default"; |
||
88 | $this->jsyn = $this->jsyn->$sqlSyntax; |
||
89 | } |
||
90 | else { |
||
91 | $sqlSyntax ="default"; |
||
92 | $this->jsyn = $this->jsyn->$sqlSyntax; |
||
93 | } |
||
94 | |||
95 | return; |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * @return array |
||
100 | */ |
||
101 | public function getJsyn() |
||
102 | { |
||
103 | return $this->jsyn; |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * Performs extraction of the appropriate sql syntax |
||
108 | * fromthe supplied jsyn file. |
||
109 | * |
||
110 | * @return void |
||
111 | */ |
||
112 | public function formatJsyn() |
||
113 | { |
||
114 | for ($i = 0; $i < count($this->jsyn); ++$i) { |
||
115 | if (strpos($this->jsyn[$i], '[') === 0 || strpos($this->jsyn[$i], '{') === (int) 0) { |
||
116 | $this->jsyn[$i] = strtolower($this->jsyn[$i]); |
||
117 | } else { |
||
118 | $this->jsyn[$i] = strtoupper($this->jsyn[$i]); |
||
135 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.