moin dedlfix,
Ok ich schreibs doch hier. Ich hab mal ein pseudo Datentyp Interface erstellt
class DTDatabase {
public $driver, $name, $host, $user, $password, $options;
public function __construct( string $driver, string $name, string $host, string $user, string $password, array $options ) {
$this->driver = $driver;
$this->name = $name;
$this->host = $host;
$this->user = $user;
$this->password = $password;
$this->options = $options;
}
}
class Database {
private $dns, $user, $password, $options;
public function __construct( DTDatabase $db ) {
$this->dns = "{$db->driver}:dbname={$db->dbname};host={$db->host}";
$this->user = $db->user;
$this->password = $db->password;
$this->options = $db->options;
}
/* Datatype Database */
$tdb = new DTDatabase( 'mysql', 'cortex', 'localhost', 'root', '', [] );
$db = new Database( $tdb );
Dieses Konstrukt bringt meines erachtens Vorteile eines Datentyp Interface.
- die parameter sind obligat
- Kapselung
kommt die Art auch in Frameworka Anwendung?
vlg MB