bhenk/msdata

About

Basic implementation of Data Object and Data Access Object for MySql database.

msData is written in PHP
tested against PHP-version 8.2
tested against MySql version 8.0.32

Source code: https://github.com/bhenk/msdata-d

Copyright © 2023 by henk van den berg
License: Apache 2.0
Version: 1.0.3

Usage

Installation

composer require bhenk/msdata

Configuration

See MysqlConnector

Persist your data

Creation of tables

Data types string, int, bool and float, when used in Entities will be converted to proper database types automatically. Caveat: String is converted to VARCHAR(255). If your strings are larger you’ll have to override the method AbstractDao::getCreateTableStatement and provide your own.

Simple Data Objects

msData is on purpose kept simple. There will be one table for each Data Object. Data Objects have only primitive types: string, int, bool and float. Extend Entity, create a constructor for all your Data Object fields, generate getters and setters and you’re basically done. The corresponding Data Access Object needs only implementing of two methods: AbstractDao::getDataObjectName and AbstractDao::getTableName.

Complexity in your business layer

Mixes of different entities is foreseen to take place in your business layer. For instance PersonWithAddress(es) is a mix of the Data Objects PersonDo and (one or more) AddressDo. Objects like Date, Time, DateTime etc. are represented in your Data Objects as strings, or other primitive types, though they may be represented in the database with appropriate types and queried as such, and in your business layer again as DateTimeImmutable(s) etc.

Relations

The Data Access Object AbstractJoinDao and Data Object Join can be used to express many-to-many relationships, based on a join-table with foreign keys. Below is a complete diagram covering database, data-layer and business-layer.

Many-to-many relationship over 3 layers

Business Objects (Bo’s) are created by their corresponding Store Object. Store Objects rely on their Data Access Object (Dao) to materialize the type of Bo. Bo’s have a dependency on their Relations Object which in turn has a dependency on the opposite Store Object, in order to materialize the opposite ends of the relation. Relations Objects may have lazy methods to fetch their (Join) Data Objects and related Bo’s, in order to keep database traffic at a minimum.

After a Store Object has persisted a Bo, it calls on the Relations Object to persist the relations.

A Relations Object may keep track of more than one type of relation, so Bo’s can have multiple relations to multiple other Bo-types. For each type of relation the Relations Object than has distinguished Dao’s and Do’s, backed by separate join tables.

Although there are no objections to complete symmetry, adding and removing of relations is often done from one side only, while the other side has readonly methods on their Relations Object. So for instance a Person can add and remove Addresses, while from the Address Object you can only obtain which Persons are living or working there.

api-docs

msdata

abc

Depends on

Dependency invoked by

connector

AbstractDao

Interfaces and abstract implementations of Data Objects and Data Access Objects

AbstractDao

namespace

bhenk\msdata\abc

predicates

Abstract

known subclasses

AbstractJoinDao | NodeDao | PersonDao | UserDao

Data Access Object with basic functionality

In most cases subclasses only need to implement getDataObjectName and getTableName. If getCreateTableStatement is not sufficient override that method as well.

This class expects Entities that subclass other Entity implementations to have parent-first in their __construct() and toArray() functions, i.e.:

class A extends Entity

class B extends A

In their __construct() and toArray() functions, properties/parameters have the order:

ID, {props of A}, {props of B}

Methods
AbstractDao::dropTable

predicates

public

Drop table if it exists

Tries to drop the table with the name returned by AbstractDao::getTableName.

public function dropTable(): bool
return bool - true on success, even if table does not exist, false on failure
throws Exception

AbstractDao::createTable

predicates

public

Create a table in the database

The statement used is the one from getCreateTableStatement.

public function createTable(
      Parameter #0 [ <optional> bool $drop = false ]
 ): int
param bool $drop - Drop (if exists) table with same name before create
return int - count of executed statements
throws Exception - code 200

AbstractDao::getTableName

predicates

public | abstract

Get the name of the table that will store the Entities this class provides access to

public abstract function getTableName(): string
return string - name of table reserved for DO

AbstractDao::getCreateTableStatement

predicates

public

Produces a minimal CreateTableStatement

CREATE TABLE IF NOT EXISTS `%table_name%`
(
     `ID`                INT NOT NULL AUTO_INCREMENT,
     `%int_prop%`        INT,
     `%string_prop%`     VARCHAR(255),
     `%bool_prop%`       BOOLEAN,
     `%float_prop%`      FLOAT,
     PRIMARY KEY (`ID`)
);

In the above %xyz% is placeholder for table name or property name. Notice that string type parameters have a limited length of 255 characters.

Subclasses may override. The table MUST have the same name as the one returned by the method getTableName.

public function getCreateTableStatement(): string
return string - the CREATE TABLE sql

AbstractDao::getDataObjectName

predicates

public | abstract

Get the fully qualified classname of the Entity this class provides access to

public abstract function getDataObjectName(): string
return string - fully qualified classname

AbstractDao::insert

predicates

public

Insert the given Entity

With param $insertID set to false (this is the default), the ID of the Entity (if any) will be ignored. Returns an Entity equal to the given Entity with the new ID.

In order to be able to reconstruct a table, the ID of the Entity can be inserted as well. Set param $insertID to true to achieve this.

public function insert(
      Parameter #0 [ <required> bhenk\msdata\abc\Entity $entity ]
      Parameter #1 [ <optional> bool $insertID = false ]
 ): Entity
param Entity $entity - Entity to insert
param bool $insertID - should the primary key ID also be inserted
return Entity - new Entity, equal to given one, with new ID
throws Exception - code 201

AbstractDao::insertBatch

predicates

public

Insert the Entities from the given array

The ID of the Entities (if any) will be ignored. Returns an array of Entities equal to the given Entities with new IDs and ID as array key. This default behaviour can be altered by providing a closure that receives each inserted entity and decides what key will be returned:

$func = function(Entity $entity): int {
    return  $entity->getID();
};

In order to be able to reconstruct a table, the ID of the Entities can be inserted as well. Set param $insertID to true to achieve this.

public function insertBatch(
      Parameter #0 [ <required> array $entity_array ]
      Parameter #1 [ <optional> ?Closure $func = NULL ]
      Parameter #2 [ <optional> bool $insertID = false ]
 ): array
param array $entity_array - array of Entities to insert
param ?Closure $func - function to assign key in the returned array
param bool $insertID - should the primary key ID also be inserted
return array - array of Entities with new IDs
throws Exception - code 201

AbstractDao::update

predicates

public

Update the given Entity

public function update(
      Parameter #0 [ <required> bhenk\msdata\abc\Entity $entity ]
 ): int
param Entity $entity - persisted Entity to update
return int - rows affected: 1 for success, 0 for failure
throws Exception - code 202

AbstractDao::updateBatch

predicates

public

Update the Entities in the given array

public function updateBatch(
      Parameter #0 [ <required> array $entity_array ]
 ): int
param array $entity_array - array of persisted Entities to update
return int - rows affected
throws Exception - code 202

AbstractDao::delete

predicates

public

Delete the row with the given ID

public function delete(
      Parameter #0 [ <required> int $ID ]
 ): int
param int $ID - the ID to delete
return int - rows affected: 1 for success, 0 if ID was not present
throws Exception - code 203

AbstractDao::deleteBatch

predicates

public

Delete rows with the given IDs

public function deleteBatch(
      Parameter #0 [ <required> array $ids ]
 ): int
param array $ids - array with IDs of persisted entities
return int - affected rows
throws Exception - code 203

AbstractDao::select

predicates

public

Fetch the Entity with the given ID

public function select(
      Parameter #0 [ <required> int $ID ]
 ): ?Entity
param int $ID - the ID to fetch
return ?Entity - Entity with given ID or null if not present
throws Exception - code 204

AbstractDao::selectBatch

predicates

public

Select Entities with the given IDs

The returned Entity[] array has Entity IDs as keys.

public function selectBatch(
      Parameter #0 [ <required> array $ids ]
 ): array
param array $ids - array of IDs of persisted Entities
return array - array of Entities or empty array if none found
throws Exception - code 204

AbstractDao::deleteWhere

predicates

public

Delete Entity rows with a where-clause

DELETE FROM %table_name% WHERE %expression%
public function deleteWhere(
      Parameter #0 [ <required> string $where_clause ]
 ): int
param string $where_clause - expression
return int - rows affected
throws Exception - code 203

AbstractDao::selectWhere

predicates

public

Select Entities with a where-clause

SELECT FROM %table_name% WHERE %expression% LIMIT %offset%, %limit%;

The optional param $func receives selected Entities and can decide what key the Entity will have in the returned Entity[] array. Default: the returned Entity[] array has Entity IDs as keys.

$func = function(Entity $entity): int {
    return  $entity->getID();
};
public function selectWhere(
      Parameter #0 [ <required> string $where_clause ]
      Parameter #1 [ <optional> int $offset = 0 ]
      Parameter #2 [ <optional> int $limit = bhenk\msdata\abc\PHP_INT_MAX ]
      Parameter #3 [ <optional> ?Closure $func = NULL ]
 ): array
param string $where_clause - expression
param int $offset - offset of the first row to return
param int $limit - the maximum number of rows to return
param ?Closure $func - if given decides which keys the returned array will have
return array - array of Entities or empty array if none found
throws Exception - code 204

AbstractDao::selectSql

predicates

public

Select Entities with a sql statement

The optional param $func receives selected Entities and can decide what key the Entity will have in the returned Entity[] array. Default: the returned Entity[] array has Entity IDs as keys.

$func = function(Entity $entity): int {
    return  $entity->getID();
};

If the param $sql selects not all fields from the designated table or selects from tables other than the designated, the result is unpredictable.

public function selectSql(
      Parameter #0 [ <required> string $sql ]
      Parameter #1 [ <optional> ?Closure $func = NULL ]
 ): array
param string $sql - sql selecting all fields from designated table
param ?Closure $func - if given decides which keys the returned array will have
return array - array of Entities or empty array if none found
throws Exception

AbstractDao::execute

predicates

public

Execute the given query

public function execute(
      Parameter #0 [ <required> string $sql ]
 ): array|bool
param string $sql
return array | bool - result rows in array; bool if result is boolean
throws Exception

Sat, 01 Jul 2023 13:02:22 +0000

AbstractJoinDao

namespace

bhenk\msdata\abc

predicates

Abstract

extends

AbstractDao

hierarchy

AbstractJoinDao -> AbstractDao

known subclasses

JoinDao

Abstract Dao for a join table

The corresponding Data Object is envisaged to extend Join.

symmetric join relation

The relationship is symmetric.

A Join with the field $deleted set to true will be deleted on any call to AbstractJoinDao::updateLeftJoin or AbstractJoinDao::updateRightJoin.


Methods
AbstractJoinDao::selectLeft

predicates

public

Select on left hand foreign key

public function selectLeft(
      Parameter #0 [ <required> int $fk_left ]
 ): array
param int $fk_left - left hand foreign key
return array - with right hand IDs as key
throws Exception

AbstractJoinDao::selectRight

predicates

public

Select on right hand foreign key

public function selectRight(
      Parameter #0 [ <required> int $fk_right ]
 ): array
param int $fk_right - right hand foreign key
return array - with left hand IDs as key
throws Exception

AbstractJoinDao::updateLeftJoin

predicates

public

Update Joins with a common FK_LEFT

This method deletes deleted Joins; updates existing Joins and inserts new Joins.

Side effect: the common param $fk_left will be set on all Joins.

public function updateLeftJoin(
      Parameter #0 [ <required> int $fk_left ]
      Parameter #1 [ <required> array $joins ]
 ): array
param int $fk_left - common left hand foreign key
param array $joins - Joins to update
return array - Updated Joins, array key is FK_RIGHT
throws Exception

AbstractJoinDao::updateRightJoin

predicates

public

Update Joins with a common FK_RIGHT

This method deletes deleted Joins; updates existing Joins and inserts new Joins.

Side effect: the common param $fk_right will be set on all Joins.

public function updateRightJoin(
      Parameter #0 [ <required> int $fk_right ]
      Parameter #1 [ <required> array $joins ]
 ): array
param int $fk_right - common right hand foreign key
param array $joins - Joins to update
return array - Updated Joins, array key is FK_LEFT
throws Exception

AbstractJoinDao::dropTable

predicates

public

inherited from

AbstractDao::dropTable

Drop table if it exists

Tries to drop the table with the name returned by AbstractDao::getTableName.

public function dropTable(): bool
return bool - true on success, even if table does not exist, false on failure
throws Exception

AbstractJoinDao::createTable

predicates

public

inherited from

AbstractDao::createTable

Create a table in the database

The statement used is the one from getCreateTableStatement.

public function createTable(
      Parameter #0 [ <optional> bool $drop = false ]
 ): int
param bool $drop - Drop (if exists) table with same name before create
return int - count of executed statements
throws Exception - code 200

AbstractJoinDao::getTableName

predicates

public | abstract

inherited from

AbstractDao::getTableName

Get the name of the table that will store the Entities this class provides access to

public abstract function getTableName(): string
return string - name of table reserved for DO

AbstractJoinDao::getCreateTableStatement

predicates

public

inherited from

AbstractDao::getCreateTableStatement

Produces a minimal CreateTableStatement

CREATE TABLE IF NOT EXISTS `%table_name%`
(
     `ID`                INT NOT NULL AUTO_INCREMENT,
     `%int_prop%`        INT,
     `%string_prop%`     VARCHAR(255),
     `%bool_prop%`       BOOLEAN,
     `%float_prop%`      FLOAT,
     PRIMARY KEY (`ID`)
);

In the above %xyz% is placeholder for table name or property name. Notice that string type parameters have a limited length of 255 characters.

Subclasses may override. The table MUST have the same name as the one returned by the method getTableName.

public function getCreateTableStatement(): string
return string - the CREATE TABLE sql

AbstractJoinDao::getDataObjectName

predicates

public | abstract

inherited from

AbstractDao::getDataObjectName

Get the fully qualified classname of the Entity this class provides access to

public abstract function getDataObjectName(): string
return string - fully qualified classname

AbstractJoinDao::insert

predicates

public

inherited from

AbstractDao::insert

Insert the given Entity

With param $insertID set to false (this is the default), the ID of the Entity (if any) will be ignored. Returns an Entity equal to the given Entity with the new ID.

In order to be able to reconstruct a table, the ID of the Entity can be inserted as well. Set param $insertID to true to achieve this.

public function insert(
      Parameter #0 [ <required> bhenk\msdata\abc\Entity $entity ]
      Parameter #1 [ <optional> bool $insertID = false ]
 ): Entity
param Entity $entity - Entity to insert
param bool $insertID - should the primary key ID also be inserted
return Entity - new Entity, equal to given one, with new ID
throws Exception - code 201

AbstractJoinDao::insertBatch

predicates

public

inherited from

AbstractDao::insertBatch

Insert the Entities from the given array

The ID of the Entities (if any) will be ignored. Returns an array of Entities equal to the given Entities with new IDs and ID as array key. This default behaviour can be altered by providing a closure that receives each inserted entity and decides what key will be returned:

$func = function(Entity $entity): int {
    return  $entity->getID();
};

In order to be able to reconstruct a table, the ID of the Entities can be inserted as well. Set param $insertID to true to achieve this.

public function insertBatch(
      Parameter #0 [ <required> array $entity_array ]
      Parameter #1 [ <optional> ?Closure $func = NULL ]
      Parameter #2 [ <optional> bool $insertID = false ]
 ): array
param array $entity_array - array of Entities to insert
param ?Closure $func - function to assign key in the returned array
param bool $insertID - should the primary key ID also be inserted
return array - array of Entities with new IDs
throws Exception - code 201

AbstractJoinDao::update

predicates

public

inherited from

AbstractDao::update

Update the given Entity

public function update(
      Parameter #0 [ <required> bhenk\msdata\abc\Entity $entity ]
 ): int
param Entity $entity - persisted Entity to update
return int - rows affected: 1 for success, 0 for failure
throws Exception - code 202

AbstractJoinDao::updateBatch

predicates

public

inherited from

AbstractDao::updateBatch

Update the Entities in the given array

public function updateBatch(
      Parameter #0 [ <required> array $entity_array ]
 ): int
param array $entity_array - array of persisted Entities to update
return int - rows affected
throws Exception - code 202

AbstractJoinDao::delete

predicates

public

inherited from

AbstractDao::delete

Delete the row with the given ID

public function delete(
      Parameter #0 [ <required> int $ID ]
 ): int
param int $ID - the ID to delete
return int - rows affected: 1 for success, 0 if ID was not present
throws Exception - code 203

AbstractJoinDao::deleteBatch

predicates

public

inherited from

AbstractDao::deleteBatch

Delete rows with the given IDs

public function deleteBatch(
      Parameter #0 [ <required> array $ids ]
 ): int
param array $ids - array with IDs of persisted entities
return int - affected rows
throws Exception - code 203

AbstractJoinDao::select

predicates

public

inherited from

AbstractDao::select

Fetch the Entity with the given ID

public function select(
      Parameter #0 [ <required> int $ID ]
 ): ?Entity
param int $ID - the ID to fetch
return ?Entity - Entity with given ID or null if not present
throws Exception - code 204

AbstractJoinDao::selectBatch

predicates

public

inherited from

AbstractDao::selectBatch

Select Entities with the given IDs

The returned Entity[] array has Entity IDs as keys.

public function selectBatch(
      Parameter #0 [ <required> array $ids ]
 ): array
param array $ids - array of IDs of persisted Entities
return array - array of Entities or empty array if none found
throws Exception - code 204

AbstractJoinDao::deleteWhere

predicates

public

inherited from

AbstractDao::deleteWhere

Delete Entity rows with a where-clause

DELETE FROM %table_name% WHERE %expression%
public function deleteWhere(
      Parameter #0 [ <required> string $where_clause ]
 ): int
param string $where_clause - expression
return int - rows affected
throws Exception - code 203

AbstractJoinDao::selectWhere

predicates

public

inherited from

AbstractDao::selectWhere

Select Entities with a where-clause

SELECT FROM %table_name% WHERE %expression% LIMIT %offset%, %limit%;

The optional param $func receives selected Entities and can decide what key the Entity will have in the returned Entity[] array. Default: the returned Entity[] array has Entity IDs as keys.

$func = function(Entity $entity): int {
    return  $entity->getID();
};
public function selectWhere(
      Parameter #0 [ <required> string $where_clause ]
      Parameter #1 [ <optional> int $offset = 0 ]
      Parameter #2 [ <optional> int $limit = bhenk\msdata\abc\PHP_INT_MAX ]
      Parameter #3 [ <optional> ?Closure $func = NULL ]
 ): array
param string $where_clause - expression
param int $offset - offset of the first row to return
param int $limit - the maximum number of rows to return
param ?Closure $func - if given decides which keys the returned array will have
return array - array of Entities or empty array if none found
throws Exception - code 204

AbstractJoinDao::selectSql

predicates

public

inherited from

AbstractDao::selectSql

Select Entities with a sql statement

The optional param $func receives selected Entities and can decide what key the Entity will have in the returned Entity[] array. Default: the returned Entity[] array has Entity IDs as keys.

$func = function(Entity $entity): int {
    return  $entity->getID();
};

If the param $sql selects not all fields from the designated table or selects from tables other than the designated, the result is unpredictable.

public function selectSql(
      Parameter #0 [ <required> string $sql ]
      Parameter #1 [ <optional> ?Closure $func = NULL ]
 ): array
param string $sql - sql selecting all fields from designated table
param ?Closure $func - if given decides which keys the returned array will have
return array - array of Entities or empty array if none found
throws Exception

AbstractJoinDao::execute

predicates

public

inherited from

AbstractDao::execute

Execute the given query

public function execute(
      Parameter #0 [ <required> string $sql ]
 ): array|bool
param string $sql
return array | bool - result rows in array; bool if result is boolean
throws Exception

Sat, 01 Jul 2023 13:02:23 +0000

DataTypes

namespace

bhenk\msdata\abc

predicates

Final | Enum

implements

UnitEnum | BackedEnum

Convertor for PHP-types to database-types


Constants
DataTypes::string

predicates

public | enum case

PHP string converts to database type VARCHAR(255)

enum(bhenk\msdata\abc\DataTypes::string)

DataTypes::int

predicates

public | enum case

PHP int converts to database type INT

enum(bhenk\msdata\abc\DataTypes::int)

DataTypes::bool

predicates

public | enum case

PHP bool converts to database type BOOLEAN

enum(bhenk\msdata\abc\DataTypes::bool)

DataTypes::float

predicates

public | enum case

PHP float converts to database type FLOAT

enum(bhenk\msdata\abc\DataTypes::float)

Methods
DataTypes::fromName

predicates

public | static

Get the database-type for the given PHP-type

public static function fromName(
      Parameter #0 [ <required> string $name ]
 ): string
param string $name - PHP-type name
return string - database-type name

DataTypes::cases

predicates

public | static

implements

UnitEnum::cases

public static function cases(): array
return array

DataTypes::from

predicates

public | static

implements

BackedEnum::from

public static function from(
      Parameter #0 [ <required> string|int $value ]
 ): static
param string | int $value
return static

DataTypes::tryFrom

predicates

public | static

implements

BackedEnum::tryFrom

public static function tryFrom(
      Parameter #0 [ <required> string|int $value ]
 ): ?static
param string | int $value
return ?static

Sat, 01 Jul 2023 13:02:23 +0000

Entity

namespace

bhenk\msdata\abc

predicates

Cloneable | Instantiable

implements

EntityInterface | Stringable

known subclasses

Join | NodeDo | UserDo

Basic implementation of a data object


Constructor
Entity::__construct

predicates

public | constructor

Construct a new Entity

public function __construct(
      Parameter #0 [ <optional> ?int $ID = NULL ]
 )
param ?int $ID - the ID of the newly created Entity or null if it has no ID

Methods
Entity::clone

predicates

public

implements

EntityInterface::clone

@inheritdoc

Create an Entity that equals this Entity

The newly created Entity gets the given ID or no ID if param $ID is null.

param int | null $ID
return Entity

@inheritdoc from method EntityInterface::clone

public function clone(
      Parameter #0 [ <optional> ?int $ID = NULL ]
 ): Entity
param ?int $ID
return Entity - Entity, similar to this one, with the given ID

Entity::toArray

predicates

public

implements

EntityInterface::toArray

@inheritdoc

Express the properties of this Entity in an array

The returned array should be in such order that it can be fet to the static method EntityInterface::fromArray.

return array - array with properties of this Entity

@inheritdoc from method EntityInterface::toArray

public function toArray(): array
return array - array with properties

Entity::getParents

predicates

public

Get the (Reflection) parents of this Entity in reverse order

class A extends Entity

class B extends A

returned array = [Entity-Reflection, A-Reflection, B-Reflection]
public function getParents(): array
return array - array with ReflectionClass parents and this Entity

Entity::fromArray

predicates

public | static

implements

EntityInterface::fromArray

Create a new Entity

The order of the given array should be parent-first, i.e.:

class A extends Entity

class B extends A

In __construct(), toArray() and fromArray() functions, properties/parameters have the order:

ID, {props of A}, {props of B}

@inheritdoc

Create a new Entity from an array of properties

The given array should have the same order as the one gotten from EntityInterface::toArray.

param array $arr - property array
return Entity - newly created Entity with the given properties

@inheritdoc from method EntityInterface::fromArray

public static function fromArray(
      Parameter #0 [ <required> array $arr ]
 ): static
param array $arr - array with properties
return static - Entity object

Entity::isSame

predicates

public

implements

EntityInterface::isSame

@inheritdoc

Test is same function

The given Entity is similar to this Entity if all properties, including ID, are equal.

param Entity $other - Entity to test
return bool - true if all properties, including ID, are equal, false otherwise

@inheritdoc from method EntityInterface::isSame

public function isSame(
      Parameter #0 [ <required> bhenk\msdata\abc\Entity $other ]
 ): bool
param Entity $other
return bool

Entity::equals

predicates

public

implements

EntityInterface::equals

@inheritdoc

Test equals function

The given Entity equals this Entity if all properties, except ID, are equal.

param Entity $other - Entity to test
return bool - true if all properties are equal, false otherwise

@inheritdoc from method EntityInterface::equals

public function equals(
      Parameter #0 [ <required> bhenk\msdata\abc\Entity $other ]
 ): bool
param Entity $other
return bool

Entity::getID

predicates

public

implements

EntityInterface::getID

@inheritdoc

Get the ID of this Entity or null if it has no ID

return int | null - ID of this Entity or null

@inheritdoc from method EntityInterface::getID

public function getID(): ?int
return ?int

Entity::__toString

predicates

public

implements

Stringable::__toString

String representation of this Entity

public function __toString(): string
return string - representing this Entity

Sat, 01 Jul 2023 13:02:23 +0000

EntityInterface

namespace

bhenk\msdata\abc

predicates

Abstract | Interface

implements

Stringable

known implementations

Entity | Join | NodeDo | PersonDo | UserDo

Definition of a basic data object


Methods
EntityInterface::fromArray

predicates

public | static | abstract

Create a new Entity from an array of properties

The given array should have the same order as the one gotten from EntityInterface::toArray.

public static abstract function fromArray(
      Parameter #0 [ <required> array $arr ]
 ): Entity
param array $arr - property array
return Entity - newly created Entity with the given properties

EntityInterface::getID

predicates

public | abstract

Get the ID of this Entity or null if it has no ID

public abstract function getID(): ?int
return ?int - ID of this Entity or null

EntityInterface::toArray

predicates

public | abstract

Express the properties of this Entity in an array

The returned array should be in such order that it can be fet to the static method EntityInterface::fromArray.

public abstract function toArray(): array
return array - array with properties of this Entity

EntityInterface::clone

predicates

public | abstract

Create an Entity that equals this Entity

The newly created Entity gets the given ID or no ID if param $ID is null.

public abstract function clone(
      Parameter #0 [ <optional> ?int $ID = NULL ]
 ): Entity
param ?int $ID
return Entity

EntityInterface::equals

predicates

public | abstract

Test equals function

The given Entity equals this Entity if all properties, except ID, are equal.

public abstract function equals(
      Parameter #0 [ <required> bhenk\msdata\abc\Entity $other ]
 ): bool
param Entity $other - Entity to test
return bool - true if all properties are equal, false otherwise

EntityInterface::isSame

predicates

public | abstract

Test is same function

The given Entity is similar to this Entity if all properties, including ID, are equal.

public abstract function isSame(
      Parameter #0 [ <required> bhenk\msdata\abc\Entity $other ]
 ): bool
param Entity $other - Entity to test
return bool - true if all properties, including ID, are equal, false otherwise

EntityInterface::__toString

predicates

public | abstract

public abstract function __toString(): string
return string

Sat, 01 Jul 2023 13:02:23 +0000

Join

namespace

bhenk\msdata\abc

predicates

Cloneable | Instantiable

implements

Stringable | EntityInterface

extends

Entity

hierarchy

Join -> Entity

A basic Entity for a join function

Join can be used when expressing a many-to-many relation


Constructor
Join::__construct

predicates

public | constructor

Constructs a new Join

public function __construct(
      Parameter #0 [ <optional> ?int $ID = NULL ]
      Parameter #1 [ <optional> ?int $FK_LEFT = NULL ]
      Parameter #2 [ <optional> ?int $FK_RIGHT = NULL ]
      Parameter #3 [ <optional> bool $deleted = false ]
 )
param ?int $ID - ID of this Join
param ?int $FK_LEFT - the left hand foreign key
param ?int $FK_RIGHT - the right hand foreign key
param bool $deleted - false on this location

Methods
Join::getFkLeft

predicates

public

Get the left hand foreign key

public function getFkLeft(): ?int
return ?int

Join::setFkLeft

predicates

public

Set the left hand foreign key

public function setFkLeft(
      Parameter #0 [ <required> ?int $FK_LEFT ]
 ): void
param ?int $FK_LEFT
return void

Join::getFkRight

predicates

public

Get the right hand foreign key

public function getFkRight(): ?int
return ?int

Join::setFkRight

predicates

public

Set the right hand foreign key

public function setFkRight(
      Parameter #0 [ <required> ?int $FK_RIGHT ]
 ): void
param ?int $FK_RIGHT
return void

Join::isDeleted

predicates

public

Get whether this join-relation is deleted

public function isDeleted(): bool
return bool

Join::setDeleted

predicates

public

Sets whether this join-relation is deleted

public function setDeleted(
      Parameter #0 [ <required> bool $deleted ]
 ): void
param bool $deleted
return void

Join::clone

predicates

public

implements

EntityInterface::clone

inherited from

Entity::clone

@inheritdoc

Create an Entity that equals this Entity

The newly created Entity gets the given ID or no ID if param $ID is null.

param int | null $ID
return Entity

@inheritdoc from method EntityInterface::clone

public function clone(
      Parameter #0 [ <optional> ?int $ID = NULL ]
 ): Entity
param ?int $ID
return Entity - Entity, similar to this one, with the given ID

Join::toArray

predicates

public

implements

EntityInterface::toArray

inherited from

Entity::toArray

@inheritdoc

Express the properties of this Entity in an array

The returned array should be in such order that it can be fet to the static method EntityInterface::fromArray.

return array - array with properties of this Entity

@inheritdoc from method EntityInterface::toArray

public function toArray(): array
return array - array with properties

Join::getParents

predicates

public

inherited from

Entity::getParents

Get the (Reflection) parents of this Entity in reverse order

class A extends Entity

class B extends A

returned array = [Entity-Reflection, A-Reflection, B-Reflection]
public function getParents(): array
return array - array with ReflectionClass parents and this Entity

Join::fromArray

predicates

public | static

implements

EntityInterface::fromArray

inherited from

Entity::fromArray

Create a new Entity

The order of the given array should be parent-first, i.e.:

class A extends Entity

class B extends A

In __construct(), toArray() and fromArray() functions, properties/parameters have the order:

ID, {props of A}, {props of B}

@inheritdoc

Create a new Entity from an array of properties

The given array should have the same order as the one gotten from EntityInterface::toArray.

param array $arr - property array
return Entity - newly created Entity with the given properties

@inheritdoc from method EntityInterface::fromArray

public static function fromArray(
      Parameter #0 [ <required> array $arr ]
 ): static
param array $arr - array with properties
return static - Entity object

Join::isSame

predicates

public

implements

EntityInterface::isSame

inherited from

Entity::isSame

@inheritdoc

Test is same function

The given Entity is similar to this Entity if all properties, including ID, are equal.

param Entity $other - Entity to test
return bool - true if all properties, including ID, are equal, false otherwise

@inheritdoc from method EntityInterface::isSame

public function isSame(
      Parameter #0 [ <required> bhenk\msdata\abc\Entity $other ]
 ): bool
param Entity $other
return bool

Join::equals

predicates

public

implements

EntityInterface::equals

inherited from

Entity::equals

@inheritdoc

Test equals function

The given Entity equals this Entity if all properties, except ID, are equal.

param Entity $other - Entity to test
return bool - true if all properties are equal, false otherwise

@inheritdoc from method EntityInterface::equals

public function equals(
      Parameter #0 [ <required> bhenk\msdata\abc\Entity $other ]
 ): bool
param Entity $other
return bool

Join::getID

predicates

public

implements

EntityInterface::getID

inherited from

Entity::getID

@inheritdoc

Get the ID of this Entity or null if it has no ID

return int | null - ID of this Entity or null

@inheritdoc from method EntityInterface::getID

public function getID(): ?int
return ?int

Join::__toString

predicates

public

implements

Stringable::__toString

inherited from

Entity::__toString

String representation of this Entity

public function __toString(): string
return string - representing this Entity

Sat, 01 Jul 2023 13:02:23 +0000


Sat, 01 Jul 2023 13:02:22 +0000

connector

Database connectors

MysqlConnector

namespace

bhenk\msdata\connector

predicates

Cloneable | Instantiable

Static wrapper around a mysqli instance

Convenience class for a mysqli connection and configuration. Configuration options can be expressed in a configuration file. The configuration file can be set with the method MysqlConnector::setConfigFile or you can rely on auto-finding of the file.

If relying on auto-finding of configuration, this class will look for a configuration file with the name msd_config.php in a directory with the name config. The config directory should be a child of an ancestor directory of this code base:

{ancestor directory}/config/msd_config.php

The configuration file should return configuration options as an array:

<?php

return [
    "hostname" => {string},     // required
    "username" => {string},     // required
    "password" => {string},     // required
    "database" => {string},     // required
    "port" => {int},            // optional, default 3306
    "persistent" => {bool},     // optional, default true
    "use_parameterized_queries" => {bool} // optional, default true
];

A connection via libmysqlclient will not allow binding parameters in execute and produce the following error:

ArgumentCountError: Binding parameters in execute is not supported with libmysqlclient

In that case set use_parameterized_queries to false.

A third method of setting the configuration is by programmatically calling MysqlConnector::setConfiguration with the appropriate array, like shown above.


Constants
MysqlConnector::CONFIG_DIR

predicates

public

Name of the directory where a configuration file is expected

string(6) "config"

MysqlConnector::CONFIG_FILE

predicates

public

Name of the expected configuration file

string(14) "msd_config.php"

Methods
MysqlConnector::get

predicates

public | static

Get the singleton instance of this class

public static function get(): MysqlConnector

MysqlConnector::closeConnection

predicates

public | static

Close the connection (if any)

public static function closeConnection(): void
return void

MysqlConnector::getConfigFile

predicates

public

Get the (absolute path to the) configuration file

public function getConfigFile(): string|bool
return string | bool - absolute path to configuration file or false if not set

MysqlConnector::setConfigFile

predicates

public

Set the configuration file

When not using auto-find of configuration, this method must be called before a call to MysqlConnector::getConnector.

public function setConfigFile(
      Parameter #0 [ <required> string|bool $config_file ]
 ): void
param string | bool $config_file - absolute path to a configuration file, or false when returning to auto-find configuration
return void

MysqlConnector::statusInfo

predicates

public

Returns status info

Something like

Uptime: 80984
Threads: 2
Questions: 1327
Slow queries: 0
Opens: 432
Flush tables: 3
Open tables: 274
Queries per second avg: 0.016"
public function statusInfo(): string|bool
return string | bool - a string describing the server status, false if an error occurred
throws Exception

MysqlConnector::getConnector

predicates

public

Get the connector

public function getConnector(): mysqli
return mysqli - connector to database
throws Exception - if connection could not be established, code 100

MysqlConnector::useParameterizedQueries

predicates

public

The value of the configuration option use_parameterized_queries

public function useParameterizedQueries(): bool
return bool - default true
throws Exception

MysqlConnector::getConfiguration

predicates

public

Get the configuration

If configuration not set, the array will be read from the configuration file, either from the configuration file as given with MysqlConnector::setConfigFile or from the auto-find configuration file at

{ancestor directory}/config/msd_config.php
public function getConfiguration(): array
return array - configuration array
throws Exception - if configuration could not be read

MysqlConnector::setConfiguration

predicates

public

Set configuration as an array

see also

MysqlConnector

public function setConfiguration(
      Parameter #0 [ <required> array $configuration ]
 ): void
param array $configuration - configuration as described in comment on this class
return void
throws Exception - if given configuration is not valid

MysqlConnector::connectionInfo

predicates

public

Returns client and server info

Something like

client: mysqlnd 8.2.1
server: 8.0.32
host: 127.0.0.1 via TCP/IP
protocol version: 10
character set: utf8mb4
public function connectionInfo(): string
return string - client and server info
throws Exception

Sat, 01 Jul 2023 13:02:23 +0000


Sat, 01 Jul 2023 13:02:23 +0000

node

Depends on

Dependency invoked by

abc

NodeDao | NodeDo

connector

NodeDao

sql
downloads

Sat, 01 Jul 2023 13:02:23 +0000

NodeDao

namespace

bhenk\msdata\node

predicates

Cloneable | Instantiable

extends

AbstractDao

hierarchy

NodeDao -> AbstractDao


Constants
NodeDao::TABLE_NAME

predicates

public

string(8) "tbl_node"

Methods
NodeDao::getDataObjectName

predicates

public

implements

AbstractDao::getDataObjectName

public function getDataObjectName(): string
return string

NodeDao::getTableName

predicates

public

implements

AbstractDao::getTableName

public function getTableName(): string
return string

NodeDao::selectChildren

predicates

public

public function selectChildren(
      Parameter #0 [ <required> int $ID ]
 ): array
param int $ID
return array

NodeDao::selectGenerationNumbers

predicates

public

public function selectGenerationNumbers(): array
return array

NodeDao::dropTable

predicates

public

inherited from

AbstractDao::dropTable

Drop table if it exists

Tries to drop the table with the name returned by AbstractDao::getTableName.

public function dropTable(): bool
return bool - true on success, even if table does not exist, false on failure
throws Exception

NodeDao::createTable

predicates

public

inherited from

AbstractDao::createTable

Create a table in the database

The statement used is the one from getCreateTableStatement.

public function createTable(
      Parameter #0 [ <optional> bool $drop = false ]
 ): int
param bool $drop - Drop (if exists) table with same name before create
return int - count of executed statements
throws Exception - code 200

NodeDao::getCreateTableStatement

predicates

public

inherited from

AbstractDao::getCreateTableStatement

Produces a minimal CreateTableStatement

CREATE TABLE IF NOT EXISTS `%table_name%`
(
     `ID`                INT NOT NULL AUTO_INCREMENT,
     `%int_prop%`        INT,
     `%string_prop%`     VARCHAR(255),
     `%bool_prop%`       BOOLEAN,
     `%float_prop%`      FLOAT,
     PRIMARY KEY (`ID`)
);

In the above %xyz% is placeholder for table name or property name. Notice that string type parameters have a limited length of 255 characters.

Subclasses may override. The table MUST have the same name as the one returned by the method getTableName.

public function getCreateTableStatement(): string
return string - the CREATE TABLE sql

NodeDao::insert

predicates

public

inherited from

AbstractDao::insert

Insert the given Entity

With param $insertID set to false (this is the default), the ID of the Entity (if any) will be ignored. Returns an Entity equal to the given Entity with the new ID.

In order to be able to reconstruct a table, the ID of the Entity can be inserted as well. Set param $insertID to true to achieve this.

public function insert(
      Parameter #0 [ <required> bhenk\msdata\abc\Entity $entity ]
      Parameter #1 [ <optional> bool $insertID = false ]
 ): Entity
param Entity $entity - Entity to insert
param bool $insertID - should the primary key ID also be inserted
return Entity - new Entity, equal to given one, with new ID
throws Exception - code 201

NodeDao::insertBatch

predicates

public

inherited from

AbstractDao::insertBatch

Insert the Entities from the given array

The ID of the Entity (if any) will be ignored. Returns an array of Entities equal to the given Entities with new IDs and ID as array key. This default behaviour can be altered by providing a closure that receives each inserted entity and decides what key will be returned:

$func = function(Entity $entity): int {
    return  $entity->getID();
};

In order to be able to reconstruct a table, the ID of the Entities can be inserted as well. Set param $insertID to true to achieve this.

public function insertBatch(
      Parameter #0 [ <required> array $entity_array ]
      Parameter #1 [ <optional> ?Closure $func = NULL ]
      Parameter #2 [ <optional> bool $insertID = false ]
 ): array
param array $entity_array - array of Entities to insert
param ?Closure $func - function to assign key in the returned array
param bool $insertID - should the primary key ID also be inserted
return array - array of Entities with new IDs
throws Exception - code 201

NodeDao::update

predicates

public

inherited from

AbstractDao::update

Update the given Entity

public function update(
      Parameter #0 [ <required> bhenk\msdata\abc\Entity $entity ]
 ): int
param Entity $entity - persisted Entity to update
return int - rows affected: 1 for success, 0 for failure
throws Exception - code 202

NodeDao::updateBatch

predicates

public

inherited from

AbstractDao::updateBatch

Update the Entities in the given array

public function updateBatch(
      Parameter #0 [ <required> array $entity_array ]
 ): int
param array $entity_array - array of persisted Entities to update
return int - rows affected
throws Exception - code 202

NodeDao::delete

predicates

public

inherited from

AbstractDao::delete

Delete the row with the given ID

public function delete(
      Parameter #0 [ <required> int $ID ]
 ): int
param int $ID - the ID to delete
return int - rows affected: 1 for success, 0 if ID was not present
throws Exception - code 203

NodeDao::deleteBatch

predicates

public

inherited from

AbstractDao::deleteBatch

Delete rows with the given IDs

public function deleteBatch(
      Parameter #0 [ <required> array $ids ]
 ): int
param array $ids - array with IDs of persisted entities
return int - affected rows
throws Exception - code 203

NodeDao::select

predicates

public

inherited from

AbstractDao::select

Fetch the Entity with the given ID

public function select(
      Parameter #0 [ <required> int $ID ]
 ): ?Entity
param int $ID - the ID to fetch
return ?Entity - Entity with given ID or null if not present
throws Exception - code 204

NodeDao::selectBatch

predicates

public

inherited from

AbstractDao::selectBatch

Select Entities with the given IDs

The returned Entity[] array has Entity IDs as keys.

public function selectBatch(
      Parameter #0 [ <required> array $ids ]
 ): array
param array $ids - array of IDs of persisted Entities
return array - array of Entities or empty array if none found
throws Exception - code 204

NodeDao::deleteWhere

predicates

public

inherited from

AbstractDao::deleteWhere

Delete Entity rows with a where-clause

DELETE FROM %table_name% WHERE %expression%
public function deleteWhere(
      Parameter #0 [ <required> string $where_clause ]
 ): int
param string $where_clause - expression
return int - rows affected
throws Exception - code 203

NodeDao::selectWhere

predicates

public

inherited from

AbstractDao::selectWhere

Select Entities with a where-clause

SELECT FROM %table_name% WHERE %expression% LIMIT %offset%, %limit%;

The optional param $func receives selected Entities and can decide what key the Entity will have in the returned Entity[] array. Default: the returned Entity[] array has Entity IDs as keys.

$func = function(Entity $entity): int {
    return  $entity->getID();
};
public function selectWhere(
      Parameter #0 [ <required> string $where_clause ]
      Parameter #1 [ <optional> int $offset = 0 ]
      Parameter #2 [ <optional> int $limit = bhenk\msdata\abc\PHP_INT_MAX ]
      Parameter #3 [ <optional> ?Closure $func = NULL ]
 ): array
param string $where_clause - expression
param int $offset - offset of the first row to return
param int $limit - the maximum number of rows to return
param ?Closure $func - if given decides which keys the returned array will have
return array - array of Entities or empty array if none found
throws Exception - code 204

NodeDao::selectSql

predicates

public

inherited from

AbstractDao::selectSql

Select Entities with a sql statement

The optional param $func receives selected Entities and can decide what key the Entity will have in the returned Entity[] array. Default: the returned Entity[] array has Entity IDs as keys.

$func = function(Entity $entity): int {
    return  $entity->getID();
};

If the param $sql selects not all fields from the designated table or selects from tables other than the designated, the result is unpredictable.

public function selectSql(
      Parameter #0 [ <required> string $sql ]
      Parameter #1 [ <optional> ?Closure $func = NULL ]
 ): array
param string $sql - sql selecting all fields from designated table
param ?Closure $func - if given decides which keys the returned array will have
return array - array of Entities or empty array if none found
throws Exception

NodeDao::execute

predicates

public

inherited from

AbstractDao::execute

Execute the given query

public function execute(
      Parameter #0 [ <required> string $sql ]
 ): array|bool
param string $sql
return array | bool - result rows in array; bool if result is boolean
throws Exception

Sat, 01 Jul 2023 13:02:23 +0000

NodeDo

namespace

bhenk\msdata\node

predicates

Cloneable | Instantiable

implements

Stringable | EntityInterface

extends

Entity

hierarchy

NodeDo -> Entity


Constructor
NodeDo::__construct

predicates

public | constructor

public function __construct(
      Parameter #0 [ <optional> ?int $ID = NULL ]
      Parameter #1 [ <optional> ?int $parent_id = NULL ]
      Parameter #2 [ <optional> ?string $name = NULL ]
      Parameter #3 [ <optional> ?string $alias = NULL ]
      Parameter #4 [ <optional> ?string $nature = NULL ]
      Parameter #5 [ <optional> bool $public = true ]
      Parameter #6 [ <optional> float $estimate = 0.0 ]
 )
param ?int $ID
param ?int $parent_id
param ?string $name
param ?string $alias
param ?string $nature
param bool $public
param float $estimate

Methods
NodeDo::getParentId

predicates

public

public function getParentId(): ?int
return ?int

NodeDo::setParentId

predicates

public

public function setParentId(
      Parameter #0 [ <required> ?int $parent_id ]
 ): void
param ?int $parent_id
return void

NodeDo::getName

predicates

public

public function getName(): ?string
return ?string

NodeDo::setName

predicates

public

public function setName(
      Parameter #0 [ <required> ?string $name ]
 ): void
param ?string $name
return void

NodeDo::getAlias

predicates

public

public function getAlias(): ?string
return ?string

NodeDo::setAlias

predicates

public

public function setAlias(
      Parameter #0 [ <required> ?string $alias ]
 ): void
param ?string $alias
return void

NodeDo::getNature

predicates

public

public function getNature(): ?string
return ?string

NodeDo::setNature

predicates

public

public function setNature(
      Parameter #0 [ <required> ?string $nature ]
 ): void
param ?string $nature
return void

NodeDo::isPublic

predicates

public

public function isPublic(): bool
return bool

NodeDo::setPublic

predicates

public

public function setPublic(
      Parameter #0 [ <required> bool $public ]
 ): void
param bool $public
return void

NodeDo::getEstimate

predicates

public

public function getEstimate(): float
return float

NodeDo::setEstimate

predicates

public

public function setEstimate(
      Parameter #0 [ <required> float $estimate ]
 ): void
param float $estimate
return void

NodeDo::clone

predicates

public

implements

EntityInterface::clone

inherited from

Entity::clone

@inheritdoc

Create an Entity that equals this Entity

The newly created Entity gets the given ID or no ID if param $ID is null.

param int | null $ID
return Entity

@inheritdoc from method EntityInterface::clone

public function clone(
      Parameter #0 [ <optional> ?int $ID = NULL ]
 ): Entity
param ?int $ID
return Entity - Entity, similar to this one, with the given ID

NodeDo::toArray

predicates

public

implements

EntityInterface::toArray

inherited from

Entity::toArray

@inheritdoc

Express the properties of this Entity in an array

The returned array should be in such order that it can be fet to the static method EntityInterface::fromArray().

return array - array with properties of this Entity

@inheritdoc from method EntityInterface::toArray

public function toArray(): array
return array - array with properties

NodeDo::getParents

predicates

public

inherited from

Entity::getParents

Get the (Reflection) parents of this Entity in reverse order

class A extends Entity

class B extends A

returned array = [Entity-Reflection, A-Reflection, B-Reflection]
public function getParents(): array
return array - array with ReflectionClass parents and this Entity

NodeDo::fromArray

predicates

public | static

implements

EntityInterface::fromArray

inherited from

Entity::fromArray

Create a new Entity

The order of the given array should be parent-first, i.e.:

class A extends Entity

class B extends A

In __construct(), toArray() and fromArray() functions, properties/parameters have the order:

ID, {props of A}, {props of B}

@inheritdoc

Create a new Entity from an array of properties

The given array should have the same order as the one gotten from EntityInterface::toArray().

param array $arr - property array
return Entity - newly created Entity with the given properties

@inheritdoc from method EntityInterface::fromArray

public static function fromArray(
      Parameter #0 [ <required> array $arr ]
 ): static
param array $arr - array with properties
return static - Entity object

NodeDo::isSame

predicates

public

implements

EntityInterface::isSame

inherited from

Entity::isSame

@inheritdoc

Test is same function

The given Entity is similar to this Entity if all properties, including ID, are equal.

param Entity $other - Entity to test
return bool - true if all properties, including ID, are equal, false otherwise

@inheritdoc from method EntityInterface::isSame

public function isSame(
      Parameter #0 [ <required> bhenk\msdata\abc\Entity $other ]
 ): bool
param Entity $other
return bool

NodeDo::equals

predicates

public

implements

EntityInterface::equals

inherited from

Entity::equals

@inheritdoc

Test equals function

The given Entity equals this Entity if all properties, except ID, are equal.

param Entity $other - Entity to test
return bool - true if all properties are equal, false otherwise

@inheritdoc from method EntityInterface::equals

public function equals(
      Parameter #0 [ <required> bhenk\msdata\abc\Entity $other ]
 ): bool
param Entity $other
return bool

NodeDo::getID

predicates

public

implements

EntityInterface::getID

inherited from

Entity::getID

@inheritdoc

Get the ID of this Entity or null if it has no ID

return int | null - ID of this Entity or null

@inheritdoc from method EntityInterface::getID

public function getID(): ?int
return ?int

NodeDo::__toString

predicates

public

implements

Stringable::__toString

inherited from

Entity::__toString

String representation of this Entity

public function __toString(): string
return string - representing this Entity

Sat, 01 Jul 2023 13:02:23 +0000


Sat, 01 Jul 2023 13:02:23 +0000

user

Depends on

Dependency invoked by

abc

PersonDao | UserDao | UserDo

PersonDao

namespace

bhenk\msdata\user

predicates

Cloneable | Instantiable

extends

AbstractDao

hierarchy

PersonDao -> AbstractDao


Methods
PersonDao::getDataObjectName

predicates

public

implements

AbstractDao::getDataObjectName

public function getDataObjectName(): string
return string

PersonDao::getTableName

predicates

public

implements

AbstractDao::getTableName

public function getTableName(): string
return string

PersonDao::dropTable

predicates

public

inherited from

AbstractDao::dropTable

Drop table if it exists

Tries to drop the table with the name returned by AbstractDao::getTableName.

public function dropTable(): bool
return bool - true on success, even if table does not exist, false on failure
throws Exception

PersonDao::createTable

predicates

public

inherited from

AbstractDao::createTable

Create a table in the database

The statement used is the one from getCreateTableStatement.

public function createTable(
      Parameter #0 [ <optional> bool $drop = false ]
 ): int
param bool $drop - Drop (if exists) table with same name before create
return int - count of executed statements
throws Exception - code 200

PersonDao::getCreateTableStatement

predicates

public

inherited from

AbstractDao::getCreateTableStatement

Produces a minimal CreateTableStatement

CREATE TABLE IF NOT EXISTS `%table_name%`
(
     `ID`                INT NOT NULL AUTO_INCREMENT,
     `%int_prop%`        INT,
     `%string_prop%`     VARCHAR(255),
     `%bool_prop%`       BOOLEAN,
     `%float_prop%`      FLOAT,
     PRIMARY KEY (`ID`)
);

In the above %xyz% is placeholder for table name or property name. Notice that string type parameters have a limited length of 255 characters.

Subclasses may override. The table MUST have the same name as the one returned by the method getTableName.

public function getCreateTableStatement(): string
return string - the CREATE TABLE sql

PersonDao::insert

predicates

public

inherited from

AbstractDao::insert

Insert the given Entity

With param $insertID set to false (this is the default), the ID of the Entity (if any) will be ignored. Returns an Entity equal to the given Entity with the new ID.

In order to be able to reconstruct a table, the ID of the Entity can be inserted as well. Set param $insertID to true to achieve this.

public function insert(
      Parameter #0 [ <required> bhenk\msdata\abc\Entity $entity ]
      Parameter #1 [ <optional> bool $insertID = false ]
 ): Entity
param Entity $entity - Entity to insert
param bool $insertID - should the primary key ID also be inserted
return Entity - new Entity, equal to given one, with new ID
throws Exception - code 201

PersonDao::insertBatch

predicates

public

inherited from

AbstractDao::insertBatch

Insert the Entities from the given array

The ID of the Entity (if any) will be ignored. Returns an array of Entities equal to the given Entities with new IDs and ID as array key. This default behaviour can be altered by providing a closure that receives each inserted entity and decides what key will be returned:

$func = function(Entity $entity): int {
    return  $entity->getID();
};

In order to be able to reconstruct a table, the ID of the Entities can be inserted as well. Set param $insertID to true to achieve this.

public function insertBatch(
      Parameter #0 [ <required> array $entity_array ]
      Parameter #1 [ <optional> ?Closure $func = NULL ]
      Parameter #2 [ <optional> bool $insertID = false ]
 ): array
param array $entity_array - array of Entities to insert
param ?Closure $func - function to assign key in the returned array
param bool $insertID - should the primary key ID also be inserted
return array - array of Entities with new IDs
throws Exception - code 201

PersonDao::update

predicates

public

inherited from

AbstractDao::update

Update the given Entity

public function update(
      Parameter #0 [ <required> bhenk\msdata\abc\Entity $entity ]
 ): int
param Entity $entity - persisted Entity to update
return int - rows affected: 1 for success, 0 for failure
throws Exception - code 202

PersonDao::updateBatch

predicates

public

inherited from

AbstractDao::updateBatch

Update the Entities in the given array

public function updateBatch(
      Parameter #0 [ <required> array $entity_array ]
 ): int
param array $entity_array - array of persisted Entities to update
return int - rows affected
throws Exception - code 202

PersonDao::delete

predicates

public

inherited from

AbstractDao::delete

Delete the row with the given ID

public function delete(
      Parameter #0 [ <required> int $ID ]
 ): int
param int $ID - the ID to delete
return int - rows affected: 1 for success, 0 if ID was not present
throws Exception - code 203

PersonDao::deleteBatch

predicates

public

inherited from

AbstractDao::deleteBatch

Delete rows with the given IDs

public function deleteBatch(
      Parameter #0 [ <required> array $ids ]
 ): int
param array $ids - array with IDs of persisted entities
return int - affected rows
throws Exception - code 203

PersonDao::select

predicates

public

inherited from

AbstractDao::select

Fetch the Entity with the given ID

public function select(
      Parameter #0 [ <required> int $ID ]
 ): ?Entity
param int $ID - the ID to fetch
return ?Entity - Entity with given ID or null if not present
throws Exception - code 204

PersonDao::selectBatch

predicates

public

inherited from

AbstractDao::selectBatch

Select Entities with the given IDs

The returned Entity[] array has Entity IDs as keys.

public function selectBatch(
      Parameter #0 [ <required> array $ids ]
 ): array
param array $ids - array of IDs of persisted Entities
return array - array of Entities or empty array if none found
throws Exception - code 204

PersonDao::deleteWhere

predicates

public

inherited from

AbstractDao::deleteWhere

Delete Entity rows with a where-clause

DELETE FROM %table_name% WHERE %expression%
public function deleteWhere(
      Parameter #0 [ <required> string $where_clause ]
 ): int
param string $where_clause - expression
return int - rows affected
throws Exception - code 203

PersonDao::selectWhere

predicates

public

inherited from

AbstractDao::selectWhere

Select Entities with a where-clause

SELECT FROM %table_name% WHERE %expression% LIMIT %offset%, %limit%;

The optional param $func receives selected Entities and can decide what key the Entity will have in the returned Entity[] array. Default: the returned Entity[] array has Entity IDs as keys.

$func = function(Entity $entity): int {
    return  $entity->getID();
};
public function selectWhere(
      Parameter #0 [ <required> string $where_clause ]
      Parameter #1 [ <optional> int $offset = 0 ]
      Parameter #2 [ <optional> int $limit = bhenk\msdata\abc\PHP_INT_MAX ]
      Parameter #3 [ <optional> ?Closure $func = NULL ]
 ): array
param string $where_clause - expression
param int $offset - offset of the first row to return
param int $limit - the maximum number of rows to return
param ?Closure $func - if given decides which keys the returned array will have
return array - array of Entities or empty array if none found
throws Exception - code 204

PersonDao::selectSql

predicates

public

inherited from

AbstractDao::selectSql

Select Entities with a sql statement

The optional param $func receives selected Entities and can decide what key the Entity will have in the returned Entity[] array. Default: the returned Entity[] array has Entity IDs as keys.

$func = function(Entity $entity): int {
    return  $entity->getID();
};

If the param $sql selects not all fields from the designated table or selects from tables other than the designated, the result is unpredictable.

public function selectSql(
      Parameter #0 [ <required> string $sql ]
      Parameter #1 [ <optional> ?Closure $func = NULL ]
 ): array
param string $sql - sql selecting all fields from designated table
param ?Closure $func - if given decides which keys the returned array will have
return array - array of Entities or empty array if none found
throws Exception

PersonDao::execute

predicates

public

inherited from

AbstractDao::execute

Execute the given query

public function execute(
      Parameter #0 [ <required> string $sql ]
 ): array|bool
param string $sql
return array | bool - result rows in array; bool if result is boolean
throws Exception

Sat, 01 Jul 2023 13:02:23 +0000

PersonDo

namespace

bhenk\msdata\user

predicates

Cloneable | Instantiable

implements

EntityInterface | Stringable

extends

UserDo

hierarchy

PersonDo -> UserDo -> Entity


Constructor
PersonDo::__construct

predicates

public | constructor

public function __construct(
      Parameter #0 [ <optional> ?int $ID = NULL ]
      Parameter #1 [ <optional> ?string $first_name = NULL ]
      Parameter #2 [ <optional> ?string $prefixes = NULL ]
      Parameter #3 [ <optional> ?string $last_name = NULL ]
      Parameter #4 [ <optional> ?string $email = NULL ]
      Parameter #5 [ <optional> ?int $knows = NULL ]
 )
param ?int $ID
param ?string $first_name
param ?string $prefixes
param ?string $last_name
param ?string $email
param ?int $knows

Methods
PersonDo::getKnows

predicates

public

public function getKnows(): ?int
return ?int

PersonDo::setKnows

predicates

public

public function setKnows(
      Parameter #0 [ <required> ?int $knows ]
 ): void
param ?int $knows
return void

PersonDo::getFirstName

predicates

public

inherited from

UserDo::getFirstName

public function getFirstName(): ?string
return ?string

PersonDo::setFirstName

predicates

public

inherited from

UserDo::setFirstName

public function setFirstName(
      Parameter #0 [ <required> ?string $first_name ]
 ): void
param ?string $first_name
return void

PersonDo::getPrefixes

predicates

public

inherited from

UserDo::getPrefixes

public function getPrefixes(): ?string
return ?string

PersonDo::setPrefixes

predicates

public

inherited from

UserDo::setPrefixes

public function setPrefixes(
      Parameter #0 [ <required> ?string $prefixes ]
 ): void
param ?string $prefixes
return void

PersonDo::getLastName

predicates

public

inherited from

UserDo::getLastName

public function getLastName(): ?string
return ?string

PersonDo::setLastName

predicates

public

inherited from

UserDo::setLastName

public function setLastName(
      Parameter #0 [ <required> ?string $last_name ]
 ): void
param ?string $last_name
return void

PersonDo::getEmail

predicates

public

inherited from

UserDo::getEmail

public function getEmail(): ?string
return ?string

PersonDo::setEmail

predicates

public

inherited from

UserDo::setEmail

public function setEmail(
      Parameter #0 [ <required> ?string $email ]
 ): void
param ?string $email
return void

PersonDo::clone

predicates

public

implements

EntityInterface::clone

inherited from

Entity::clone

@inheritdoc

Create an Entity that equals this Entity

The newly created Entity gets the given ID or no ID if param $ID is null.

param int | null $ID
return Entity

@inheritdoc from method EntityInterface::clone

public function clone(
      Parameter #0 [ <optional> ?int $ID = NULL ]
 ): Entity
param ?int $ID
return Entity - Entity, similar to this one, with the given ID

PersonDo::toArray

predicates

public

implements

EntityInterface::toArray

inherited from

Entity::toArray

@inheritdoc

Express the properties of this Entity in an array

The returned array should be in such order that it can be fet to the static method EntityInterface::fromArray().

return array - array with properties of this Entity

@inheritdoc from method EntityInterface::toArray

public function toArray(): array
return array - array with properties

PersonDo::getParents

predicates

public

inherited from

Entity::getParents

Get the (Reflection) parents of this Entity in reverse order

class A extends Entity

class B extends A

returned array = [Entity-Reflection, A-Reflection, B-Reflection]
public function getParents(): array
return array - array with ReflectionClass parents and this Entity

PersonDo::fromArray

predicates

public | static

implements

EntityInterface::fromArray

inherited from

Entity::fromArray

Create a new Entity

The order of the given array should be parent-first, i.e.:

class A extends Entity

class B extends A

In __construct(), toArray() and fromArray() functions, properties/parameters have the order:

ID, {props of A}, {props of B}

@inheritdoc

Create a new Entity from an array of properties

The given array should have the same order as the one gotten from EntityInterface::toArray().

param array $arr - property array
return Entity - newly created Entity with the given properties

@inheritdoc from method EntityInterface::fromArray

public static function fromArray(
      Parameter #0 [ <required> array $arr ]
 ): static
param array $arr - array with properties
return static - Entity object

PersonDo::isSame

predicates

public

implements

EntityInterface::isSame

inherited from

Entity::isSame

@inheritdoc

Test is same function

The given Entity is similar to this Entity if all properties, including ID, are equal.

param Entity $other - Entity to test
return bool - true if all properties, including ID, are equal, false otherwise

@inheritdoc from method EntityInterface::isSame

public function isSame(
      Parameter #0 [ <required> bhenk\msdata\abc\Entity $other ]
 ): bool
param Entity $other
return bool

PersonDo::equals

predicates

public

implements

EntityInterface::equals

inherited from

Entity::equals

@inheritdoc

Test equals function

The given Entity equals this Entity if all properties, except ID, are equal.

param Entity $other - Entity to test
return bool - true if all properties are equal, false otherwise

@inheritdoc from method EntityInterface::equals

public function equals(
      Parameter #0 [ <required> bhenk\msdata\abc\Entity $other ]
 ): bool
param Entity $other
return bool

PersonDo::getID

predicates

public

implements

EntityInterface::getID

inherited from

Entity::getID

@inheritdoc

Get the ID of this Entity or null if it has no ID

return int | null - ID of this Entity or null

@inheritdoc from method EntityInterface::getID

public function getID(): ?int
return ?int

PersonDo::__toString

predicates

public

implements

Stringable::__toString

inherited from

Entity::__toString

String representation of this Entity

public function __toString(): string
return string - representing this Entity

Sat, 01 Jul 2023 13:02:23 +0000

UserDao

namespace

bhenk\msdata\user

predicates

Cloneable | Instantiable

extends

AbstractDao

hierarchy

UserDao -> AbstractDao


Methods
UserDao::getDataObjectName

predicates

public

implements

AbstractDao::getDataObjectName

public function getDataObjectName(): string
return string

UserDao::getTableName

predicates

public

implements

AbstractDao::getTableName

public function getTableName(): string
return string

UserDao::dropTable

predicates

public

inherited from

AbstractDao::dropTable

Drop table if it exists

Tries to drop the table with the name returned by AbstractDao::getTableName.

public function dropTable(): bool
return bool - true on success, even if table does not exist, false on failure
throws Exception

UserDao::createTable

predicates

public

inherited from

AbstractDao::createTable

Create a table in the database

The statement used is the one from getCreateTableStatement.

public function createTable(
      Parameter #0 [ <optional> bool $drop = false ]
 ): int
param bool $drop - Drop (if exists) table with same name before create
return int - count of executed statements
throws Exception - code 200

UserDao::getCreateTableStatement

predicates

public

inherited from

AbstractDao::getCreateTableStatement

Produces a minimal CreateTableStatement

CREATE TABLE IF NOT EXISTS `%table_name%`
(
     `ID`                INT NOT NULL AUTO_INCREMENT,
     `%int_prop%`        INT,
     `%string_prop%`     VARCHAR(255),
     `%bool_prop%`       BOOLEAN,
     `%float_prop%`      FLOAT,
     PRIMARY KEY (`ID`)
);

In the above %xyz% is placeholder for table name or property name. Notice that string type parameters have a limited length of 255 characters.

Subclasses may override. The table MUST have the same name as the one returned by the method getTableName.

public function getCreateTableStatement(): string
return string - the CREATE TABLE sql

UserDao::insert

predicates

public

inherited from

AbstractDao::insert

Insert the given Entity

With param $insertID set to false (this is the default), the ID of the Entity (if any) will be ignored. Returns an Entity equal to the given Entity with the new ID.

In order to be able to reconstruct a table, the ID of the Entity can be inserted as well. Set param $insertID to true to achieve this.

public function insert(
      Parameter #0 [ <required> bhenk\msdata\abc\Entity $entity ]
      Parameter #1 [ <optional> bool $insertID = false ]
 ): Entity
param Entity $entity - Entity to insert
param bool $insertID - should the primary key ID also be inserted
return Entity - new Entity, equal to given one, with new ID
throws Exception - code 201

UserDao::insertBatch

predicates

public

inherited from

AbstractDao::insertBatch

Insert the Entities from the given array

The ID of the Entity (if any) will be ignored. Returns an array of Entities equal to the given Entities with new IDs and ID as array key. This default behaviour can be altered by providing a closure that receives each inserted entity and decides what key will be returned:

$func = function(Entity $entity): int {
    return  $entity->getID();
};

In order to be able to reconstruct a table, the ID of the Entities can be inserted as well. Set param $insertID to true to achieve this.

public function insertBatch(
      Parameter #0 [ <required> array $entity_array ]
      Parameter #1 [ <optional> ?Closure $func = NULL ]
      Parameter #2 [ <optional> bool $insertID = false ]
 ): array
param array $entity_array - array of Entities to insert
param ?Closure $func - function to assign key in the returned array
param bool $insertID - should the primary key ID also be inserted
return array - array of Entities with new IDs
throws Exception - code 201

UserDao::update

predicates

public

inherited from

AbstractDao::update

Update the given Entity

public function update(
      Parameter #0 [ <required> bhenk\msdata\abc\Entity $entity ]
 ): int
param Entity $entity - persisted Entity to update
return int - rows affected: 1 for success, 0 for failure
throws Exception - code 202

UserDao::updateBatch

predicates

public

inherited from

AbstractDao::updateBatch

Update the Entities in the given array

public function updateBatch(
      Parameter #0 [ <required> array $entity_array ]
 ): int
param array $entity_array - array of persisted Entities to update
return int - rows affected
throws Exception - code 202

UserDao::delete

predicates

public

inherited from

AbstractDao::delete

Delete the row with the given ID

public function delete(
      Parameter #0 [ <required> int $ID ]
 ): int
param int $ID - the ID to delete
return int - rows affected: 1 for success, 0 if ID was not present
throws Exception - code 203

UserDao::deleteBatch

predicates

public

inherited from

AbstractDao::deleteBatch

Delete rows with the given IDs

public function deleteBatch(
      Parameter #0 [ <required> array $ids ]
 ): int
param array $ids - array with IDs of persisted entities
return int - affected rows
throws Exception - code 203

UserDao::select

predicates

public

inherited from

AbstractDao::select

Fetch the Entity with the given ID

public function select(
      Parameter #0 [ <required> int $ID ]
 ): ?Entity
param int $ID - the ID to fetch
return ?Entity - Entity with given ID or null if not present
throws Exception - code 204

UserDao::selectBatch

predicates

public

inherited from

AbstractDao::selectBatch

Select Entities with the given IDs

The returned Entity[] array has Entity IDs as keys.

public function selectBatch(
      Parameter #0 [ <required> array $ids ]
 ): array
param array $ids - array of IDs of persisted Entities
return array - array of Entities or empty array if none found
throws Exception - code 204

UserDao::deleteWhere

predicates

public

inherited from

AbstractDao::deleteWhere

Delete Entity rows with a where-clause

DELETE FROM %table_name% WHERE %expression%
public function deleteWhere(
      Parameter #0 [ <required> string $where_clause ]
 ): int
param string $where_clause - expression
return int - rows affected
throws Exception - code 203

UserDao::selectWhere

predicates

public

inherited from

AbstractDao::selectWhere

Select Entities with a where-clause

SELECT FROM %table_name% WHERE %expression% LIMIT %offset%, %limit%;

The optional param $func receives selected Entities and can decide what key the Entity will have in the returned Entity[] array. Default: the returned Entity[] array has Entity IDs as keys.

$func = function(Entity $entity): int {
    return  $entity->getID();
};
public function selectWhere(
      Parameter #0 [ <required> string $where_clause ]
      Parameter #1 [ <optional> int $offset = 0 ]
      Parameter #2 [ <optional> int $limit = bhenk\msdata\abc\PHP_INT_MAX ]
      Parameter #3 [ <optional> ?Closure $func = NULL ]
 ): array
param string $where_clause - expression
param int $offset - offset of the first row to return
param int $limit - the maximum number of rows to return
param ?Closure $func - if given decides which keys the returned array will have
return array - array of Entities or empty array if none found
throws Exception - code 204

UserDao::selectSql

predicates

public

inherited from

AbstractDao::selectSql

Select Entities with a sql statement

The optional param $func receives selected Entities and can decide what key the Entity will have in the returned Entity[] array. Default: the returned Entity[] array has Entity IDs as keys.

$func = function(Entity $entity): int {
    return  $entity->getID();
};

If the param $sql selects not all fields from the designated table or selects from tables other than the designated, the result is unpredictable.

public function selectSql(
      Parameter #0 [ <required> string $sql ]
      Parameter #1 [ <optional> ?Closure $func = NULL ]
 ): array
param string $sql - sql selecting all fields from designated table
param ?Closure $func - if given decides which keys the returned array will have
return array - array of Entities or empty array if none found
throws Exception

UserDao::execute

predicates

public

inherited from

AbstractDao::execute

Execute the given query

public function execute(
      Parameter #0 [ <required> string $sql ]
 ): array|bool
param string $sql
return array | bool - result rows in array; bool if result is boolean
throws Exception

Sat, 01 Jul 2023 13:02:23 +0000

UserDo

namespace

bhenk\msdata\user

predicates

Cloneable | Instantiable

implements

Stringable | EntityInterface

extends

Entity

hierarchy

UserDo -> Entity

known subclasses

PersonDo

A simple user

This line has Entity, OutOfBoundsException, Entity 3 links.

A box of roses

with content


Constructor
UserDo::__construct

predicates

public | constructor

public function __construct(
      Parameter #0 [ <optional> ?int $ID = NULL ]
      Parameter #1 [ <optional> ?string $first_name = NULL ]
      Parameter #2 [ <optional> ?string $prefixes = NULL ]
      Parameter #3 [ <optional> ?string $last_name = NULL ]
      Parameter #4 [ <optional> ?string $email = NULL ]
 )
param ?int $ID
param ?string $first_name
param ?string $prefixes
param ?string $last_name
param ?string $email

Methods
UserDo::getFirstName

predicates

public

public function getFirstName(): ?string
return ?string

UserDo::setFirstName

predicates

public

public function setFirstName(
      Parameter #0 [ <required> ?string $first_name ]
 ): void
param ?string $first_name
return void

UserDo::getPrefixes

predicates

public

public function getPrefixes(): ?string
return ?string

UserDo::setPrefixes

predicates

public

public function setPrefixes(
      Parameter #0 [ <required> ?string $prefixes ]
 ): void
param ?string $prefixes
return void

UserDo::getLastName

predicates

public

public function getLastName(): ?string
return ?string

UserDo::setLastName

predicates

public

public function setLastName(
      Parameter #0 [ <required> ?string $last_name ]
 ): void
param ?string $last_name
return void

UserDo::getEmail

predicates

public

public function getEmail(): ?string
return ?string

UserDo::setEmail

predicates

public

public function setEmail(
      Parameter #0 [ <required> ?string $email ]
 ): void
param ?string $email
return void

UserDo::clone

predicates

public

implements

EntityInterface::clone

inherited from

Entity::clone

@inheritdoc

Create an Entity that equals this Entity

The newly created Entity gets the given ID or no ID if param $ID is null.

param int | null $ID
return Entity

@inheritdoc from method EntityInterface::clone

public function clone(
      Parameter #0 [ <optional> ?int $ID = NULL ]
 ): Entity
param ?int $ID
return Entity - Entity, similar to this one, with the given ID

UserDo::toArray

predicates

public

implements

EntityInterface::toArray

inherited from

Entity::toArray

@inheritdoc

Express the properties of this Entity in an array

The returned array should be in such order that it can be fet to the static method EntityInterface::fromArray().

return array - array with properties of this Entity

@inheritdoc from method EntityInterface::toArray

public function toArray(): array
return array - array with properties

UserDo::getParents

predicates

public

inherited from

Entity::getParents

Get the (Reflection) parents of this Entity in reverse order

class A extends Entity

class B extends A

returned array = [Entity-Reflection, A-Reflection, B-Reflection]
public function getParents(): array
return array - array with ReflectionClass parents and this Entity

UserDo::fromArray

predicates

public | static

implements

EntityInterface::fromArray

inherited from

Entity::fromArray

Create a new Entity

The order of the given array should be parent-first, i.e.:

class A extends Entity

class B extends A

In __construct(), toArray() and fromArray() functions, properties/parameters have the order:

ID, {props of A}, {props of B}

@inheritdoc

Create a new Entity from an array of properties

The given array should have the same order as the one gotten from EntityInterface::toArray().

param array $arr - property array
return Entity - newly created Entity with the given properties

@inheritdoc from method EntityInterface::fromArray

public static function fromArray(
      Parameter #0 [ <required> array $arr ]
 ): static
param array $arr - array with properties
return static - Entity object

UserDo::isSame

predicates

public

implements

EntityInterface::isSame

inherited from

Entity::isSame

@inheritdoc

Test is same function

The given Entity is similar to this Entity if all properties, including ID, are equal.

param Entity $other - Entity to test
return bool - true if all properties, including ID, are equal, false otherwise

@inheritdoc from method EntityInterface::isSame

public function isSame(
      Parameter #0 [ <required> bhenk\msdata\abc\Entity $other ]
 ): bool
param Entity $other
return bool

UserDo::equals

predicates

public

implements

EntityInterface::equals

inherited from

Entity::equals

@inheritdoc

Test equals function

The given Entity equals this Entity if all properties, except ID, are equal.

param Entity $other - Entity to test
return bool - true if all properties are equal, false otherwise

@inheritdoc from method EntityInterface::equals

public function equals(
      Parameter #0 [ <required> bhenk\msdata\abc\Entity $other ]
 ): bool
param Entity $other
return bool

UserDo::getID

predicates

public

implements

EntityInterface::getID

inherited from

Entity::getID

@inheritdoc

Get the ID of this Entity or null if it has no ID

return int | null - ID of this Entity or null

@inheritdoc from method EntityInterface::getID

public function getID(): ?int
return ?int

UserDo::__toString

predicates

public

implements

Stringable::__toString

inherited from

Entity::__toString

String representation of this Entity

public function __toString(): string
return string - representing this Entity

Sat, 01 Jul 2023 13:02:23 +0000


Sat, 01 Jul 2023 13:02:23 +0000

zzz

Depends on

Dependency invoked by

abc

JoinDao

JoinDao

namespace

bhenk\msdata\zzz

predicates

Cloneable | Instantiable

extends

AbstractJoinDao

hierarchy

JoinDao -> AbstractJoinDao -> AbstractDao


Methods
JoinDao::getDataObjectName

predicates

public

implements

AbstractDao::getDataObjectName

@inheritdoc

Get the fully qualified classname of the Entity this class provides access to

return string - fully qualified classname

@inheritdoc from method AbstractDao::getDataObjectName

public function getDataObjectName(): string
return string

JoinDao::getTableName

predicates

public

implements

AbstractDao::getTableName

@inheritdoc

Get the name of the table that will store the Entity this class provides access to

return string - name of table reserved for DO

@inheritdoc from method AbstractDao::getTableName

public function getTableName(): string
return string

JoinDao::selectLeft

predicates

public

inherited from

AbstractJoinDao::selectLeft

Select on left hand foreign key

public function selectLeft(
      Parameter #0 [ <required> int $fk_left ]
 ): array
param int $fk_left - left hand foreign key
return array - with right hand IDs as key
throws Exception

JoinDao::selectRight

predicates

public

inherited from

AbstractJoinDao::selectRight

Select on right hand foreign key

public function selectRight(
      Parameter #0 [ <required> int $fk_right ]
 ): array
param int $fk_right - right hand foreign key
return array - with left hand IDs as key
throws Exception

JoinDao::updateLeftJoin

predicates

public

inherited from

AbstractJoinDao::updateLeftJoin

Update Joins with a common FK_LEFT

This method deletes deleted Joins; updates existing Joins and inserts new Joins.

Side effect: the common param $fk_left will be set on all Joins.

public function updateLeftJoin(
      Parameter #0 [ <required> int $fk_left ]
      Parameter #1 [ <required> array $joins ]
 ): array
param int $fk_left - common left hand foreign key
param array $joins - Joins to update
return array - Updated Joins, array key is FK_RIGHT
throws Exception

JoinDao::updateRightJoin

predicates

public

inherited from

AbstractJoinDao::updateRightJoin

Update Joins with a common FK_RIGHT

This method deletes deleted Joins; updates existing Joins and inserts new Joins.

Side effect: the common param $fk_right will be set on all Joins.

public function updateRightJoin(
      Parameter #0 [ <required> int $fk_right ]
      Parameter #1 [ <required> array $joins ]
 ): array
param int $fk_right - common right hand foreign key
param array $joins - Joins to update
return array - Updated Joins, array key is FK_LEFT
throws Exception

JoinDao::dropTable

predicates

public

inherited from

AbstractDao::dropTable

Drop table if it exists

Tries to drop the table with the name returned by AbstractDao::getTableName().

public function dropTable(): bool
return bool - true on success, even if table does not exist, false on failure
throws Exception

JoinDao::createTable

predicates

public

inherited from

AbstractDao::createTable

Create a table in the database

The statement used is the one from AbstractDao::getCreateTableStatement().

public function createTable(
      Parameter #0 [ <optional> bool $drop = false ]
 ): int
param bool $drop - Drop (if exists) table with same name before create
return int - count of executed statements
throws Exception - code 200

JoinDao::getCreateTableStatement

predicates

public

inherited from

AbstractDao::getCreateTableStatement

Produces a minimal CreateTableStatement

CREATE TABLE IF NOT EXISTS `%table_name%`
(
     `ID`                INT NOT NULL AUTO_INCREMENT,
     `%int_prop%`        INT,
     `%string_prop%`     VARCHAR(255),
     `%bool_prop%`       BOOLEAN,
     `%float_prop%`      FLOAT,
     PRIMARY KEY (`ID`)
);

In the above %xyz% is placeholder for table name or property name. Notice that string type parameters have a limited length of 255 characters.

Subclasses may override. The table MUST have the same name as the one returned by the method AbstractDao::getTableName().

public function getCreateTableStatement(): string
return string - the CREATE TABLE sql

JoinDao::insert

predicates

public

inherited from

AbstractDao::insert

Insert the given Entity

With param $insertID set to false (this is the default), the ID of the Entity (if any) will be ignored. Returns an Entity equal to the given Entity with the new ID.

In order to be able to reconstruct a table, the ID of the Entity can be inserted as well. Set param $insertID to true to achieve this.

public function insert(
      Parameter #0 [ <required> bhenk\msdata\abc\Entity $entity ]
      Parameter #1 [ <optional> bool $insertID = false ]
 ): Entity
param Entity $entity - Entity to insert
param bool $insertID - should the primary key ID also be inserted
return Entity - new Entity, equal to given one, with new ID
throws Exception - code 201

JoinDao::insertBatch

predicates

public

inherited from

AbstractDao::insertBatch

Insert the Entities from the given array

The ID of the Entity (if any) will be ignored. Returns an array of Entities equal to the given Entities with new IDs and ID as array key. This default behaviour can be altered by providing a closure that receives each inserted entity and decides what key will be returned:

$func = function(Entity $entity): int {
    return  $entity->getID();
};

In order to be able to reconstruct a table, the ID of the Entities can be inserted as well. Set param $insertID to true to achieve this.

public function insertBatch(
      Parameter #0 [ <required> array $entity_array ]
      Parameter #1 [ <optional> ?Closure $func = NULL ]
      Parameter #2 [ <optional> bool $insertID = false ]
 ): array
param array $entity_array - array of Entities to insert
param ?Closure $func - function to assign key in the returned array
param bool $insertID - should the primary key ID also be inserted
return array - array of Entities with new IDs
throws Exception - code 201

JoinDao::update

predicates

public

inherited from

AbstractDao::update

Update the given Entity

public function update(
      Parameter #0 [ <required> bhenk\msdata\abc\Entity $entity ]
 ): int
param Entity $entity - persisted Entity to update
return int - rows affected: 1 for success, 0 for failure
throws Exception - code 202

JoinDao::updateBatch

predicates

public

inherited from

AbstractDao::updateBatch

Update the Entities in the given array

public function updateBatch(
      Parameter #0 [ <required> array $entity_array ]
 ): int
param array $entity_array - array of persisted Entities to update
return int - rows affected
throws Exception - code 202

JoinDao::delete

predicates

public

inherited from

AbstractDao::delete

Delete the row with the given ID

public function delete(
      Parameter #0 [ <required> int $ID ]
 ): int
param int $ID - the ID to delete
return int - rows affected: 1 for success, 0 if ID was not present
throws Exception - code 203

JoinDao::deleteBatch

predicates

public

inherited from

AbstractDao::deleteBatch

Delete rows with the given IDs

public function deleteBatch(
      Parameter #0 [ <required> array $ids ]
 ): int
param array $ids - array with IDs of persisted entities
return int - affected rows
throws Exception - code 203

JoinDao::select

predicates

public

inherited from

AbstractDao::select

Fetch the Entity with the given ID

public function select(
      Parameter #0 [ <required> int $ID ]
 ): ?Entity
param int $ID - the ID to fetch
return ?Entity - Entity with given ID or null if not present
throws Exception - code 204

JoinDao::selectBatch

predicates

public

inherited from

AbstractDao::selectBatch

Select Entities with the given IDs

The returned Entity[] array has Entity IDs as keys.

public function selectBatch(
      Parameter #0 [ <required> array $ids ]
 ): array
param array $ids - array of IDs of persisted Entities
return array - array of Entities or empty array if none found
throws Exception - code 204

JoinDao::deleteWhere

predicates

public

inherited from

AbstractDao::deleteWhere

Delete Entity rows with a where-clause

DELETE FROM %table_name% WHERE %expression%
public function deleteWhere(
      Parameter #0 [ <required> string $where_clause ]
 ): int
param string $where_clause - expression
return int - rows affected
throws Exception - code 203

JoinDao::selectWhere

predicates

public

inherited from

AbstractDao::selectWhere

Select Entities with a where-clause

SELECT FROM %table_name% WHERE %expression% LIMIT %offset%, %limit%;

The optional param $func receives selected Entities and can decide what key the Entity will have in the returned Entity[] array. Default: the returned Entity[] array has Entity IDs as keys.

$func = function(Entity $entity): int {
    return  $entity->getID();
};
public function selectWhere(
      Parameter #0 [ <required> string $where_clause ]
      Parameter #1 [ <optional> int $offset = 0 ]
      Parameter #2 [ <optional> int $limit = bhenk\msdata\abc\PHP_INT_MAX ]
      Parameter #3 [ <optional> ?Closure $func = NULL ]
 ): array
param string $where_clause - expression
param int $offset - offset of the first row to return
param int $limit - the maximum number of rows to return
param ?Closure $func - if given decides which keys the returned array will have
return array - array of Entities or empty array if none found
throws Exception - code 204

JoinDao::selectSql

predicates

public

inherited from

AbstractDao::selectSql

Select Entities with a sql statement

The optional param $func receives selected Entities and can decide what key the Entity will have in the returned Entity[] array. Default: the returned Entity[] array has Entity IDs as keys.

$func = function(Entity $entity): int {
    return  $entity->getID();
};

If the param $sql selects not all fields from the designated table or selects from tables other than the designated, the result is unpredictable.

public function selectSql(
      Parameter #0 [ <required> string $sql ]
      Parameter #1 [ <optional> ?Closure $func = NULL ]
 ): array
param string $sql - sql selecting all fields from designated table
param ?Closure $func - if given decides which keys the returned array will have
return array - array of Entities or empty array if none found
throws Exception

JoinDao::execute

predicates

public

inherited from

AbstractDao::execute

Execute the given query

public function execute(
      Parameter #0 [ <required> string $sql ]
 ): array|bool
param string $sql
return array | bool - result rows in array; bool if result is boolean
throws Exception

Sat, 01 Jul 2023 13:02:23 +0000


Sat, 01 Jul 2023 13:02:23 +0000


Sat, 01 Jul 2023 13:02:22 +0000