PHP code example of fyre / orm
1. Go to this page and download the library: Download fyre/orm library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
fyre / orm example snippets
use Fyre\ORM\ModelRegistry;
ModelRegistry::addNamespace($namespace);
ModelRegistry::clear();
$model = ModelRegistry::createDefaultModel();
$defaultModelClass = ModelRegistry::getDefaultModelClass();
$namespaces = ModelRegistry::getNamespaces();
$hasNamespace = ModelRegistry::hasNamespace($namespace);
$isLoaded = ModelRegistry::isLoaded($alias);
$model = ModelRegistry::load($alias);
$removed = ModelRegistry::removeNamespace($namespace);
ModelRegistry::setDefaultModelClass($defaultModelClass);
$unloaded = ModelRegistry::unload($alias);
$model = ModelRegistry::use($alias);
$query = $model->deleteQuery($options);
$connection = $model->getConnection($type);
protected array $connectionKeys = [
self::WRITE => 'default',
self::READ => 'read_replica'
];
$query = $model->insertQuery();
$query = $model->replaceQuery();
$query = $model->selectQuery($options);
$model->setConnection($connection, $type);
$query = $model->subquery($options);
$query = $model->updateQuery($options);
$query = $model->updateBatchQuery($options);
$aliasField = $model->aliasField($field, $alias);
$alias = $model->getAlias();
$autoIncrementKey = $model->getAutoIncrementKey();
$displayName = $model->getDisplayName();
protected string $displayName = 'display_name';
$primaryKeys = $model->getPrimaryKey();
$tableSchema = $model->getSchema();
$table = $model->getTable();
protected string $table = 'my_table';
$model->setAlias($alias);
$model->setDisplayName($displayName);
$model->setTable($table);
$entityClass = $model->getEntityClass();
protected string $entityClass = MyEntity::class;
$model->loadInto($entity, $contain);
$entity = $model->newEmptyEntity();
$entity = $model->newEntity($data, $options);
$entities = $model->newEntities($data, $options);
$model->patchEntity($entity, $data, $options);
$model->patchEntities($entities, $data, $options);
$result = $model->delete($entity, $options);
$affectedRows = $model->deleteAll($conditions);
$result = $model->deleteMany($entities, $options);
$exists = $model->exists($conditions);
$query = $model->find($data);
$entity = $model->get($primaryValues, $data);
$result = $model->save($entity, $options);
$result = $model->saveMany($entities, $options);
$affectedRows = $model->updateAll($data, $conditions);
$model->addRelationship($relationship);
$relationship = $model->getRelationship($name);
$relationships = $model->getRelationships();
$hasRelationship = $model->hasRelationship($name);
$model->removeRelationship($name);
$model->addBehavior($name, $options);
$behavior = $model->getBehavior($name);
$hasBehavior = $model->hasBehavior($name);
$model->removeBehavior($name);
$rules = $model->getRules();
$validator = $model->getValidator();
$model->setRules($rules);
$model->setValidator($validator);
use Fyre\Entity\Entity;
public function afterDelete(Entity $entity) {}
use Fyre\Entity\Entity;
public function afterDeleteCommit(Entity $entity) {}
use Fyre\ORM\Result;
public function afterFind(Result $result): Result {}
use Fyre\Entity\Entity;
public function afterRules(Entity $entity) {}
use Fyre\Entity\Entity;
public function afterParse(Entity $entity) {}
use Fyre\Entity\Entity;
public function afterSave(Entity $entity) {}
use Fyre\Entity\Entity;
public function afterSaveCommit(Entity $entity) {}
use Fyre\Entity\Entity;
public function beforeDelete(Entity $entity) {}
use Fyre\ORM\Query;
public function beforeFind(Query $query): Query {}
use ArrayObject;
public function beforeParse(ArrayObject $data) {}
use Fyre\Entity\Entity;
public function beforeRules(Entity $entity) {}
use Fyre\Entity\Entity;
public function beforeSave(Entity $entity) {}
use Fyre\ORM\RuleSet;
public function buildRules(RuleSet $rules): RuleSet
{
return $rules;
}
use Fyre\Validation\Validator;
public function buildValidation(Validator $validator): Validator
{
return $validator;
}
$model = $query->getModel();
$model->deleteQuery()
->where($conditions)
->execute();
$model->insertQuery()
->values($values)
->execute();
$model->replaceQuery()
->values($values)
->execute();
$model->selectQuery()
->select($fields)
->where($conditions)
->execute();
$results = $query->all();
$query->clearResult();
$query->contain($contain, $overwrite);
$count = $query->count();
$query->disableAutoFields();
$query->disableBuffering();
$query->enableAutoFields();
$query->enableBuffering();
$entity = $query->first();
$alias = $query->getAlias();
$connectionType = $query->getConnectionType();
$contain = $query->getContain();
$matching = $query->getMatching();
$result = $query->getResult();
$query->innerJoinWith($contain, $conditions);
$query->leftJoinWith($contain, $conditions);
php
$query->matching($contain, $conditions);
php
$query->notMatching($contain, $conditions);
php
$array = $query->toArray();
php
$model->updateQuery()
->set($values)
->where($conditions)
->execute();
php
$alias = $query->getAlias();
php
$model->updateBatchQuery()
->set($values, $keys)
->execute();
php
$alias = $query->getAlias();
php
$model->belongsTo($name, $data);
php
$model->hasMany($name, $data);
php
$model->hasOne($name, $data);
php
$model->manyToMany($name, $data);
php
BehaviorRegistry::addNamespace($namespace);
php
BehaviorRegistry::clear();
php
$className = BehaviorRegistry::find($name);
php
$namespaces = BehaviorRegistry::getNamespaces();
php
$hasNamespace = BehaviorRegistry::hasNamespace($namespace);
php
$behavior = BehaviorRegistry::load($name, $model, $options);
php
$removed = BehaviorRegistry::removeNamespace($namespace);
php
$this->addBehavior('MyBehavior');
$behavior = $this->MyBehavior;
php
$config = $behavior->getConfig();
php
$model = $behavior->getModel();
php
$model->addBehavior('Timestamp', $options);
php
$rules->add($rule);
php
$rules->existsIn($fields, $name, $options);
php
$rules->isClean($fields, $options);
php
$rules->isUnique($fields, $options);
php
$rules->validate($entity);