Download the PHP package brandonlamb/spot without Composer
On this page you can find all versions of the php package brandonlamb/spot. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download brandonlamb/spot
More information about brandonlamb/spot
Files in brandonlamb/spot
Package spot
Short Description DataMapper ORM for PHP 5.5+
License BSD
Homepage https://github.com/brandonlamb/Spot
Informations about the package spot
Spot PHP ORM+ODM
For Relational Databases and MongoDB
Connecting to a Database
The Spot\Config object stores and references database connections by name.
Create a new instance of Spot\Config and add database connections created outside
of Spot. This was a change to allow your app to create the raw PDO connection and
just reuse this. A big complaint I have always had is pretty much every ORM/Model
class always wants to create this for you instead of being passed this connection.
Accessing the Mapper
Since Spot follows the DataMapper design pattern, you will need a mapper instance for working with object Entities and database tables.
Since you have to have access to your mapper anywhere you use the database, most people create a helper method to create a mapper instance once and then return the same instance when required again. Such a helper method might look something like this:
Or if you have a Registry class in your framework:
Or using a Dependency Injection Container
Creating Entities
Entity classes can be named and namespaced however you want to set them
up within your project structure. For the following examples, the
Entities will just be prefixed with an Entity namespace for easy psr-0
compliant autoloading.
Another entity example of a model class inside an application's Model namespace. This is the simplest definition, only defining the model's fields.
Built-in Field Types
All the basic field types are built-in with all the default functionality provided for you:
stringintfloat/double/decimalbooleantextdatedatetimetimestampyearmonthday
Registering Custom Field Types
If you want to register your own custom field type with custom
functionality on get/set, have a look at the clases in the Spot\Type
namespace, make your own, and register it in Spot\Config:
Relation Types
Entity relation types are:
HasOneHasManyHasManyThrough
Finders (Mapper)
The main finders used most are all to return a collection of entities,
and first or get to return a single entity matching the conditions.
all(entityName, [conditions])
Find all entityName that matches the given conditions and return a
Spot\Entity\Collection of loaded Spot\Entity objects.
Since a Spot\Query object is returned, conditions and other statements
can be chained in any way or order you want. The query will be
lazy-executed on interation or count, or manually by ending the chain with a
call to execute().
first(entityName, [conditions])
Find and return a single Spot\Entity object that matches the criteria.
