Components

Basics

A component in powerorm is any project that needs to extend the orm.

Basically its a class that implements Eddmash\PowerOrm\Components\ComponentInterface interface .

An example of a component class can be found at Faker , which is the component class for the faker library.

This library extends the orm to add the generatedata command which is used to generate dummy data.

namespace Eddmash\PowerOrmFaker;


use Eddmash\PowerOrm\BaseOrm;
use Eddmash\PowerOrm\Components\Component;
use Eddmash\PowerOrmFaker\Commands\Generatedata;

class Faker extends Component
{

    function ready(BaseOrm $baseOrm)
    {
    }

    /**
     * Command classes
     * @return array
     * @since 1.1.0
     *
     * @author Eddilbert Macharia (http://eddmash.com) <edd.cowan@gmail.com>
     */
    function getCommands()
    {
        return [
            Generatedata::class
        ];
    }
}

Project Application

An application in powerorm is a form of a component with the difference being an application provides more information that determines things like where

  • the orm should look for models,
  • where it should place the generated migrations

For a php project to use powerorm, an application class needs to be created for that project.

If you have a project with the namespace App. Create a class that extends the Eddmash\PowerOrm\Components\AppComponent. This class should be placed on the same level as your models, migration folders.

namespace App;


use Eddmash\PowerOrm\BaseOrm;
use Eddmash\PowerOrm\Components\AppComponent;

class App extends AppComponent
{

    public function ready(BaseOrm $baseOrm)
    {
    }

}

Technically this file can be placed anywhere on your project tree, To get this flexibility you need to override :

Class Reference

Component

\Eddmash\PowerOrm\Components\Component
ready()
This method is invoked after the orm registry is ready . This means the models can be accessed within this model without any issues.
isQueryable()

true if it this component is accessible as an attribute of the orm.

getInstance()

Instance to return if the component is queryable..

getCommands()

An array of Command classes that this component provides.

getName()

Name to use when querying this component, ensure its unique.

AppComponent

\Eddmash\PowerOrm\Components\AppComponent
ready()
This method is invoked after the orm registry is ready . This means the models can be accessed within this model without any issues.
getMigrationsPath()

This is location where the ORM will use to store migrations files.

getModelsPath()

This is location where the ORM will expect to find the model files.

getDbPrefix()

This is the prefix to use in all tables created by the ORM for this project.e.g. if

dbPrefix = 'testing'

all tables created for this project will prefixed with testing so instead of the table user it will becomes testing_user.