Skip to content

Commit dfc852d

Browse files
committed
third version
1 parent 082936d commit dfc852d

File tree

8 files changed

+491
-92
lines changed

8 files changed

+491
-92
lines changed

README.md

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ A ticket system.
6666
.... 📜 ~~TicketDao.php~~
6767

6868
📁 repo
69+
.... 📜 AbstractTicketsRepo.php (generated by genrepo.php)
70+
71+
.... 📜 ExampleTicketBase.php (generated by genrepo.php)
72+
6973
.... 📜 TicketsRepo.php (generated by genrepo.php)
7074

7175
📁 factory
@@ -101,7 +105,7 @@ And here some puritans could claim:
101105
102106
![](https://i.pinimg.com/originals/9a/aa/52/9aaa521195c5b2f30e3164e371128927.jpg)
103107

104-
And lets me explain something. There is nothing wrong with the use of global. If something must be used or accessed everywhere, then it makes a sense that this something is global. What are we skipping with global? Dependency injection, containers, and whatnot! The use of global is bad if we use GLOBAL for variables or objects that they must not be shared globally, for example, local variables. So the use of global is not as absolute. Only sith think in absolute We could use globally if it is used correctly. The 100% ban on the use of GLOBAL it's silly, and it's religion.
108+
And lets me explain something. There is nothing wrong with the use of global. If something must be used or accessed everywhere, then it makes a sense that this something is global. What are we skipping with global? Dependency injection, containers, and whatnot! The use of global is bad if we use GLOBAL for variables or objects that they must not be shared globally, for example, local variables. So the use of global is not as absolute. Only Sith think in absolute 😁 We could use globally if it is used correctly. The 100% ban on the use of GLOBAL it's silly, and it's religion.
105109

106110

107111

@@ -153,31 +157,31 @@ Or using a GUI
153157

154158
## 3-step Creation of the Repository Layer
155159

156-
The repository layer .
160+
The repository layer.
157161

158162
In the root folder, let's create and execute the next code:
159163

160164
📜 /genrepo.php
161165

166+
It calls a simple method but this method is quite verbose and long.
167+
162168
```php
163169
<?php
164170
include "app/app.php";
165171

166-
pdoOne()->log=3;
167-
pdoOne()->render();
172+
$errors=pdoOne()->generateAllClasses(
173+
['tickets'=>'TicketsRepo'] // table->class repository
174+
,'ExampleTicketBase' // base class (for the database
175+
,'eftec\exampleticket\repo' //namespace of the class repository
176+
,__DIR__.'/repo' // folder of the class repository
177+
);
168178
```
169179

170-
The method render create an interface visual
171-
172-
![](docs/gui.jpg)
173-
174-
We want to create a new class. So let's select all the information, database, user, password, etc. For input, write down our table (**tickets**). And for output, selects the operation **classcode**
180+
Now, this method creates the next files
175181

176-
For namespace use the next one: **eftec\exampleticket\repo** that matches with the psr-4 and folder.
177-
178-
In the text area called **log**, it will generate a PHP code. Copy it and write a new file.
179-
180-
* 📜 /repo/TicketsRepo.php
182+
* 📜 /repo/TicketsRepo.php **But only if the file does not exist!!**. If you want to replace it, then you must delete it manually (or set the argument **$forced** of the method **generateAllClasses()** to **true**). Why? The concept of this class is it could be edited, so if we modify this class, then the changes are keep even if we rebuild all the repositories.
183+
* 📜 /repo/AbstractTicketsRepo.php It is the class contains all the definitions of the table tickets.
184+
* 📜 /repo/ExampleTicketBase.php This class is common to all tables
181185

182186
Finally, you can delete 📜 /genrepo.php (optionally)
183187

@@ -287,32 +291,18 @@ We use our global function database(). It uses prepared-statement (hence the Col
287291

288292
* function list() This method returns all tickets from the database. If the operation fails, then we store a message (inside the validation class).
289293

290-
291-
```php
292-
public static function list() {
293-
try {
294-
$tickets = pdoOne()->select('*')
295-
->from('Tickets')
296-
->toList(); // select * from tickets
297-
} catch (\Exception $e) {
298-
valid()->addMessage('ERRORINSERT','Unable to list. '.pdoOne()->lastError(),'error');
299-
$tickets=[];
300-
}
301-
return $tickets;
302-
}
303-
```
304-
305294
### Considerations
306295

307-
* What if the database is down?. Then it will stop the execution of any code.
296+
* What if the database is down?. Then it will stop the execution of our code.
308297
* What if the operation fails?. Then it will store an error message.
309298
* What if the user enters a malicious code?. The library uses prepared-statement, so the code is safe from malicious entries. For example: if the name of the ticket is O'hara, the system will work correctly.
310299

311300
So the security and stability of the system are ensured.
312301

313302
## 6 step - Views
314-
Since we are using the library BladeOne, then we could use views (instead of duct & taping the html+php inside the same class.
303+
Since we are using the library **BladeOne**, then we could use views (instead of duct & taping the html+php inside the same class.
315304
In our case, we will use two views (for insert and list)
305+
316306
* 📜 /views/ticket/index
317307
It is part of the view: (without using eftec/BladeOneHtml)
318308
```php
@@ -430,7 +420,7 @@ https://github.com/jorgecc/ExampleTicketPHP
430420

431421
## How much minimalist is our code?
432422

433-
* 32 PHP files (including libraries and examples).
423+
* 34 PHP files (including libraries and examples).
434424
* 7000 lines of code (including lines of code of our libraries).
435425
* Our code (excluding libraries and views) are 166 lines of code. :-3
436426

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"require": {
1818
"eftec/bladeone": "^3.43",
19-
"eftec/pdoone": "^1.37",
19+
"eftec/pdoone": "^2.0",
2020
"eftec/routeone": "^1.13",
2121
"eftec/validationone": "^1.23.2",
2222
"eftec/cacheone": "^1.4.2",

controller/TicketController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static function IndexActionPost($id = "", $idparent = "", $event = "") {
2424
if (valid()->messageList->errorcount === 0) {
2525
if (TicketsRepo::insert($ticket)) {
2626
// ticket inserted correctly, let's go to the list
27-
header('Location: ../../Ticket/List');
27+
header('Location: ../Ticket/List');
2828
exit();
2929
}
3030
echo blade()->run('ticket.list', ['tickets' => $ticket]);

genrepo.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
<?php
22

33
include "app/app.php";
4+
echo "<h1>Compiling repository classes</h1>";
45

56
pdoOne()->log=3;
6-
pdoOne()->render();
7+
$errors=pdoOne()->generateAllClasses(
8+
['tickets'=>'TicketsRepo'] // table->class repository
9+
,'ExampleTicketBase' // base class (for the database
10+
,'eftec\exampleticket\repo' //namespace of the class repository
11+
,__DIR__.'/repo' // folder of the class repository
12+
);
13+
14+
var_dump($errors);

0 commit comments

Comments
 (0)