Download the PHP package davewid/cactus without Composer
On this page you can find all versions of the php package davewid/cactus. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download davewid/cactus
More information about davewid/cactus
Files in davewid/cactus
Package cactus
Short Description A lightweight ORM using the DataMapper pattern, PHP 5.3+
License MIT
Homepage https://github.com/daveWid/cactus
Informations about the package cactus
Cactus
Cactus is a ORM using the DataMapper pattern for PHP 5.3+
Example
We will walk through a quick example on how to use Cactus. First we will start
with a table called user
that we will build our example around.
Working with this structure we can now dive into the model and entity classes.
Mapper
The mapper classes hold all of the information about the database table it is mapping, including the table name and primary key.
Here is the model class for our user
table.
The mapper class has no knowledge of how to connect to your data source so you will have to specify that yourself.
As you can see the adapter needs to be injected into the class, so it is probably wise to use a dependency injection container to accomplish this.
See the PDO docs for more information on creating a PDO connection.
Using a framework or don't have PDO available? You are in luck because you can
easily create adapters to suit your needs. All you need to do is implement the
\Cactus\Adapter
interface and inject that adapter into Cactus.
Entity
An entity is a representation of each data row as an object. All validation and data normalization should be contained within the entity.
Below is a sample entity class for our user.
Pretty simple huh?
Querying
There are 3 types of queries built in; finding, saving and deleting.
Find
Save
Delete
Defining Columns
The goal of defining the columns is not to be able to generate the sql to create your tables, but to convert the string values from the database over to native php types.
Lets take a look at the example from UserMapper
above
As you can see the columns array is setup in a $name => $type setup. For a full
list of field types you can choose from check the documentation for
\Cactus\Converter
. Setting a field to false
keeps it as a string as well.
Building Queries
You can build queries for custom methods in your model anyway you want. Cactus comes bundled with Peyote if you would like to build your queries in an object oriented way.
Supported Adapters
Below is a list of currently supported adapters. If you don't see your framework in the list, hack the code and send a pull request.
- PDO
Hacking
Cactus is in heavy development and all contributions are welcome and encouraged.
Before you start hacking away, make sure you switch over to the develop
branch.
Running Tests
Before you send a pull request on any changes, make sure that the phpunit tests pass, adding tests where necessary.
Since this is an ORM, you will need to test a database. To connect to the database
you will need to to modify the php
section of the phpunit.xml file with your settings.
Before you commit changes make sure you run...
git update-index --assume-unchanged phpunit.xml
This way your username/passwords don't get pushed into the repo.
Developed by Dave Widmer