Objectiphy
  • Introduction
  • Quick Start
  • Basic Fetching
  • Basic Saving
  • Deleting
  • Mapping Providers
    • Attributes
    • Objectiphy Mapping
    • Doctrine Mapping
  • Defining Relationships
    • One to one
    • One to Many
    • Many to one
    • Many to Many
    • Scalar Joins
  • Query Builder
    • Running a Query
    • Select Queries
    • Update Queries
    • Insert Queries
    • Delete Queries
    • Criteria
      • Operators
      • Filtering by Child Objects
      • Filtering by Aggregates
    • Joins
  • Pagination and Sorting
  • Embedded Value Objects
  • Serialization Groups
  • Late Binding and Lazy Loading
  • Streaming Results
  • Custom Repositories
  • Optimisation
  • Configuration Options
  • Mapping Overrides
  • Caching
  • Comparison with Doctrine
  • Code Generation etc.
  • Troubleshooting
  • Licence, Copyright, Credits
Powered by GitBook
On this page

Was this helpful?

Introduction

Objectiphy is a simple data mapper ORM - inspired by (and somewhat compatible with) the Doctrine project, with the aim of being easy to learn, intuitive, and flexible.

Create repositories using the repository factory:

use Objectiphy\Objectiphy\Factory\RepositoryFactory;
use MyProject\Contact;

$pdo = new \PDO(
    'mysql:host=localhost;dbname=test', 
    getenv('DB_USER'), 
    getenv('DB_PASS')
);

$factory = new RepositoryFactory($pdo);
$repository = $factory->createRepository(Contact::class);

You can use simple criteria in an array to load entities:

// Load all staff in Sales department:
$criteria = ['department.name' => 'Sales'];
$contacts = $repository->findBy($criteria);

Or use more complex criteria to limit which properties of which records are returned using the object-oriented query builder, which closely resembles standard SQL syntax (but using classes and properties instead of tables and columns):

// Get just the name for permanent staff in Sales and 
// Finance who have a car (even if the Contact entity 
// does not have a vehicle property)
$criteria = ['departments' => ['Sales', 'Finance']];
$query = QB::create()
         ->select('firstName', 'lastName')
         ->from(Contact::class)
         ->innerJoin(Vehicle::class, 'v')
             ->on('id', '=', 'v.ownerContactId')
             ->and('v.type', '=', 'car')
         ->where('department.name', 'IN', ':departments')
         ->and('isPermanent', '=', true)
         ->buildSelectQuery($criteria);
 $contacts = $repository->findBy($query);

Inserting or updating entities is also very easy (Objectiphy keeps track of changes to entities that it loaded, so will only save the things that have changed):

$repository->saveEntity($contact);

Features

  • option of fetching unbound (scalar) results

  • use any MySQL function you like in custom queries

  • mark properties as read only

  • custom collection classes (for collections of child objects)

  • handles recursive object relationships

This library has the ability to insert, update, and delete records in your database. Use with care!

NextQuick Start

Last updated 2 years ago

Was this helpful?

Mapping information is typically specified using . You can use entities with or attributes or annotations (some features of Objectiphy that are not present in Doctrine require Objectiphy attributes, but you can mix both types).

, , , and relationships

loading

of both parent and child objects (even one-to-many)

filter using

easily write

for streaming

limit hydration using

automatic or manual control of

, , , and records

and

value objects

perform (retrieve a single value from a joined table without needing a new entity or custom query)

use aggregate functions to populate or as

mapping definitions (useful for unit testing)

mapping definitions
Objectiphy
Doctrine
one-to-one
many-to-one
one-to-many
many-to-many
filter based on properties
complex criteria
custom queries
iterable results
custom repositories
serialization groups
select
insert
update
delete
embedded
scalar joins
manually override
filter criteria
cascade deletes
orphan removal
pagination
transactions
lazy or eager
properties