Download the PHP package bit-mx/data-entities without Composer

On this page you can find all versions of the php package bit-mx/data-entities. 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 data-entities

Data Entities

Execute stored procedures in Laravel from Sqlserver without all the boilerplate code.

Table of Contents

Introduction

Data Entities is a library that allows you to execute stored procedures in Sqlserver easily. It is a wrapper around the Laravel's DB Facade.

Installation

You can install the package via composer:

Setup

You need to publish the configuration file to set the connection name.

This command will create a new configuration file in the config directory.

Compatibility

This package is compatible with Laravel 10.x and above.

Due laravel 11 requires php 8.2, this package is compatible with php 8.2 and above.

Getting Started

Create a Data Entity

To create a Data Entity, you need to extend the DataEntity class and implement the resolveStoreProcedure method with the name of the stored procedure you want to execute.

You can also override the defaultParameters method to set the default parameters for the stored procedure.

You can also use the parameters method to set the parameters for the stored procedure.

The ResponseType enum has two options: SINGLE and COLLECTION.

SINGLE is used when the stored procedure returns a single row, and COLLECTION is used when the stored procedure returns multiple rows.

You can use the artisan command to create a new Data Entity:

This command will create a new Data Entity in the app/DataEntities directory.

Connection

You can set the connection name overriding the resolveDatabaseConnection method.

Execute the Data Entity

To execute the Data Entity, you need to call the execute method on the Data Entity instance.

The execute method returns a Response object that contains the data returned by the stored procedure.

Mutators

You can use the mutators method to transform the parameters before sending them to the Store Procedure.

This will transform the date parameter to a formatted date string before sending it to the stored procedure.

Available mutators

Custom mutators

You can create custom mutators by implementing the Mutable interface.

You can create a new cast using the artisan command.

Accessors

You can use the accessors method to transform the data returned by the stored procedure.

This will transform the contact_id key to an integer before returning the data.

Available accessors

Custom accessor

You can create custom accessors by implementing the Accessable interface.

You can create a new accessor using the artisan command.

Response useful methods

The Response object has some useful methods to work with the data returned by the stored procedure.

data

The data method returns the data returned by the stored procedure as an array.

Data with a key

You can get the data with a key

Data with a key and a default value

You can get the data with a key and a default value

Add data value

You can add a value to the data array

You can add as an array to the data array

Merge data

You can merge an array with the data array

As object

You can get the data as an object

As collection

You can get the data as a collection

success

The success method returns true if the stored procedure was executed successfully, and false otherwise.

failed

The fail method returns true if the stored procedure failed, and false otherwise.

throw

By default, the Response object won't throw an exception if the stored procedure fails. You can throw an exception manually using the throw method.

Boot

You can use the boot method to execute code before and after the stored procedure is executed.

Traits

You can use traits to add functionality to your Data Entities. Add the method bootTrait to the Data Entity to use the trait.

The bootTaggable method will be called before the stored procedure is executed.

Middlewares

You can use middlewares to execute code before and after the stored procedure is executed.

You can alse use a invokable class as a middleware. This class should implement the QueryMiddleware or ResponseMiddleware interface.

Plugins

You can use plugins to add functionality to your Data Entities.

AlwaysThrowOnError

The AlwaysThrowOnError plugin will throw an exception if the stored procedure fails.

HasCache

The HasCache plugin will cache the data returned by the stored procedure.

Data Entity shloud implement the Cacheable interface.

You can invalidate the cache using the invalidateCache method.

Or you can disable temporarily the cache using the disableCaching method.

Response object will have a isCached method to check if the data was cached.

Data Transfer objects

You can use Data Transfer objects to map the data returned by the stored procedure to a PHP object.

You can get the dto from the response using the dto method.

Debugging

You cal call dd and ddRaw methods to debug the query sent to the database.

Testing

You can create integration tests for your Data Entities easily.

Mocking the Data Entity

You can mock the Data Entity using the DataEntity::fake method.

When using the fake method, the execute method will return the data specified in the MockResponse::make method and won't execute the stored procedure.

Assertions

You can use the assert method to assert that the Data Entity was executed.

Assertions

You can use the following assertions:

Using factories

You can use factories to create fake data for your Data Entities.

To create a factory you should extend the DataEntityFactory class and implement the definition method.

You can use the faker property to generate fake data.

You can pass directly the factory to the MockResponse::make method. or you can create an array with the create method.

You can also use the count method to create an array of fake data.

You can use the state method to change the default values of the factory.

Or create a new method in the factory to change the default values.

You can create a fake with an exception

Response type

You can set the response type using the responseType method.

You can change the response type on MockResponse

You can create a new factory using the artisan command.

This command will create a new factory in the tests/DataEntityFactories directory.


All versions of data-entities with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/support Version ^10.0 || ^11.0
illuminate/database Version ^10.0 || ^11.0
fakerphp/faker Version ^1.23
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 bit-mx/data-entities contains the following files

Loading the files please wait ....