Download the PHP package harp-orm/harp without Composer

On this page you can find all versions of the php package harp-orm/harp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package harp

Harp ORM

Build Status Scrutinizer Quality Score Code Coverage Latest Stable Version

Harp ORM is a light DataMapper persistence layer for php objects.

Quick example

Why?

Why another ORM? At present there are no ORMs that use the latest PHP features. Recent advancements in the php language itself (e.g. traits), and external static analysis tools allow for writing applications that can be easily verified to be correct, however most available ORMs don't use them which makes static code analysis not very useful. And lastly, this package aims to be closer to the metal, smartly using existing PHP classes and extensions to make your models fast, without sacraficing features. Here's the elevator pitch:

Instalation

Harp uses composer so intalling it is as easy as:

It uses harp-orm/query for connecting to the database, so you'll also need to configure the connection:

Subsections

Defining Models

Here's an example model class.

All the public properties get persisted in the database, using the native types if available.

Tip Once related objects have been loaded, they will be cached and returned on further requests, however the data is not kept in the model itself, thus if you do a var_dump on an model it will return only data of the model itself and will keep your stack traces readable.

Detailed list of all the configuration methods:

Configuration Method Description
setTable($table) Set the name of the database table, defaults to the short class name of the model
setDb($dbName) Set alternative database connection, this will use alternative database configurations you've setup
setSoftDelete($isSoftDelete) Set to true if you want this model to be soft deleted. This is configured automatically by the SoftDeleteTrait. More on soft delete later
setInherited($isInherited) Set to true if this repo will be inherited by other repo using Single table inheritance. This is configured automatically by the InheritedTrait.
setPrimaryKey($primaryKey) Sets the property/column to be used for primary key, "id" by default
setNameKey($nameKey) Sets the property/column to be used for name key - will be used for findByName method on the repo. Defaults to "name"
addRel(AbstractRel $rel) Add a link to a related model. Read about Relations
addRels(array $rels) Add multiple rel objects.
addAssert(AbstractAssert $assert) Add an assertion for this model. Read about Assertions
addAsserts(array $asserts) Add multiple asserts
addSerializer(AbstractSerializer) Add a property serializer. Read about Serializers
addSerializers(array $serializers) Add multiple serializer objects
addEventBefore($event, $callback) Add event listener, to be triggered before a specific event
addEventAfter($event, $callback) Add event listener to be triggered after a specific event

For more about events, read Extending using events

Retrieving from the database

Retrieving models from the database (as well as saving but on that later) are handled with static methods on the model class. To find models by their primary key use the find method.

If the model has a "name" property (or a nameKey configured) you can use findByName method.

For more complex retrieving you can use the findAll method, which returns a 'Find' object. It has a rich interface of methods for constructing an sql query:

All the models retrieved from the database are stored in an "identity map". So that if at a later time, the same model is loaded again. It will return the same php object, associated with the db row.

Detailed docs for findAll

Persisting Models

When models have been created, modified or deleted they usually need to be persisted again. This is done with the "save" method on the model.

When you add / remove or otherwise modify related models they will be saved alongside your main model.

Preserving multiple models

You can presever multiple models of the same repo at once (with query grouping) using the saveArray method. Just pass an array of models.

Soft deletion

If you need to keep the models in the database even after they are deleted - e.g. logical deltion, you can use the SoftDeleteTrait

This adds a some of methods to your model. Read about soft deletion in detail here

Inherited

Sometimes you need several models to share the same database table - e.g. if there is just a slight variation of the same functionality. This is called Single Table Inheritance.

Harp ORM supports inheriting models out of the box. Read about inexperience in detail here

Model states

Throughout their lives Models have different states (Harp\Harp\Model\State). They can be:

State Description
State::PENDING Still not persisted in the database. This is the default state of models. Will be inserted in the database when persisted
State::DELETED Marked for deletion. When persisted will execute a DELETE query
State::SAVED Retrieved from the database. When is changed
State::VOID This represents a "non-existing" model, e.g. when you try to retrieve a model that does not exists

There are several methods for working with model states:

Method Description
setState($state) Set the state on the model
getState() Retrieve the current state
isSaved() Return true if state is State::SAVED
isPending() Return true if state is State::PENDING
isDeleted() Return true if state is State::DELETED
isVoid() Return true if state is State::VOID

Dirty Tracking

Models track all the changes to their public properties to minimise updates to the database. You can use that functionality yourself by calling these methods:

Method Description
getOriginals() Get an array with all the original values of the properties
getOriginal($name) Get a specific original value, returns null if value does not exist
getChange($name) Returns an array with [original, changed], or null if there is no change
getChanges() Return an array with [name => new value] for all the changes
hasChange($name) Return true if the property has been changed
isEmptyChanges() Return true if there are no changes
isChanged() Return true if there are any changes
resetOriginals() Set the current property values as the "original". This is called when a model has been saved
getProperties() Get an array with the current values of all the public properties
setProperties(array $properties) Set public properties with a [property name => value] array

Example:

Extending

When you want to write packages that extend functionality of Harp ORM, or simply share code between your models, you can use PHP's native Traits. They allow you to statically extends classes. All of the internals of Harp ORM are built around allowing you to accomplish this easily as this is the preferred way of writing "behaviours" or "templates".

Apart from that you will be able to add event listeners for various events in the life-cycle of models.

Read about extending in detail here

Direct database access.

There are times when you'll need to get to the bare metal and write custom sqls. To help you do that you can use the internal Query classes directly.

More details about custom queries you can read the Query section

License

Copyright (c) 2014, Clippings Ltd. Developed by Ivan Kerin as part of clippings.com

Under BSD-3-Clause license, read LICENSE file.

Icon made by Freepik from www.flaticon.com


All versions of harp with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
harp-orm/query Version ~0.2.0
harp-orm/serializer Version ~0.1.0
harp-orm/util Version ~0.2.2
harp-orm/validate Version ~0.4.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package harp-orm/harp contains the following files

Loading the files please wait ....