Download the PHP package phoenixrvd/oda without Composer
On this page you can find all versions of the php package phoenixrvd/oda. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download phoenixrvd/oda
More information about phoenixrvd/oda
Files in phoenixrvd/oda
Package oda
Short Description API-Package for simplify access from Data-Block of an object, without implementing from getters and setters.
License mit
Informations about the package oda
Object Data Accessor (ODA)
- Features
- Installation
- Basics
- IDE-Helper
- Standard-Accessoren
- Eigene-Accessoren
- Beispiel
- Hinweis
- Testing
- Copyright and license
Features
- Vereinfacht das Nutzen von Datenhaltungsobjekten.
- Erhöht die Lesbarkeit von Quellcode, durch das Minimieren von LOC.
- Standardisiert DAO-Schicht mit einem kleinem Package, ohne große Frameworks.
Installation
Bei der Installation ist Composer vorausgesetzt.
Basics
Angenommen, braucht man ein ein Objekt, welches genau 2 Datenfelder hat (foo und bar).
Deklariert man Standard-Methoden, wird das Objekt wie Folgt aussehen:
Hätte man nicht 2 sondern 10 Properties, wird das Object gleich um 300 LOC länger.
Nutzt man das Packet, bekommt man gleiche Funktionalität wesentlich kompakter. Auch wenn anzahl von Datenfelder wächst, vergrößert man nicht den Code-Basis.
Im Beispiel Unten ist vorheriges Objekt umgeschrieben:
IDE-Helper
Damit die IDE auch alle Objekt-Methoden kennt und man Autovervollständigung nutzen kann, sollte man die Methoden in der Klasse-Signatur festlegen.
Es ist aber immer noch kompakter als vorher.
Standard-Accessoren
Standard-Präfixes:
Präfix | Beschreibung |
---|---|
get | Gibt Wert eines Feldes zurück |
set | Setzt Wert eines Feldes |
is(value) | Prüftob Wert exakt dem Parameter entspricht (Vergleich mit ) |
has | Prüft ob das Objekt ein Feld für Daten enthält (Equivalent: ) |
asJSON | Gibt Wert eines Feldes als formatiertes JSON-String zurück. |
Eigene-Accessoren
Manchmal braucht man, dass bestimmte Felder eines Objektes formatiert zurückgegeben werden.
Z.b. ist Unix-Timestamp, man braucht es aber als RFC822-Datum.
Im Bespiel ist beschrieben, wie man der API ein date - Accessor beibringt. Damit wird voll automatisch Unix-Timestamp nach Datum konvertieren und man es mit überall verwenden kann.
Beispiel
-
Accessor-Klasse anlegen
-
Trait für Wiederverwendbarkeit anlegen
-
Eigenes Trait an Stelle von Standard-Trait im Object verwenden.
- Einfach die Methode aufrufen
Hinweis
Projekte, die auf sehr hohe Leistung ausgelegt sind, sollten auf die Methodik generell verzichten. Diskussion dazu findet man hier.
Testing
Copyright and license
Code released under the MIT License.