Download the PHP package bardoqi/sight without Composer

On this page you can find all versions of the php package bardoqi/sight. 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 sight

Sight

Your Missing Presenter for Laravel

Build Status StyleCI Codecov branch

About Sight

中文(Chinese)

There is no MVP (Model View Presenter) pattern in Laravel framework before.

Maybe you know that there is no presenter layer in server side. But I should tell you, the Sight just is one.

Sight not only for changing the MVC web application to MVP, but also Is a good library for changing the API application.

Now you could use Sight, which is in an elegant architecture and give you elegant MVP pattern.

The difference between MVC and MVP is that, a view is totally passive and unaware of the model layer. While in MVC it isn't passive and aware of the Model Layer. In proper MVP, View class (if it is) also SHOULD NOT implement a constructor.

A typical example of MVP will consist of these parts:

And Sight is using to bridge both Business Logic Layer and View or Controller (for API application) layer.

And Sight is a mapping class to help you transform the original data from database query to the former that the view or client could use.

So Sight is a presenter layer for Laravel framework.

We believe that you will be more happier during your coding with Sight.

With Sight you need not coding repeat unhappy any more.

With Sight you need not coding to search array any more, because we transform the join array with mapping.

With Sight you need not join many tables for on field.

With sight you could stop mew programmer to query table in code segment "for" or "foreach".

With Sight Many unnecessary join query will be avoided.

Enjoy Sight now, please!

What do Sight do?

From data layer to view or API layer you need to write many foreach code for the data transform.

Now you need not write foreach code any more. Just use "ToArray()"!

Maybe the troubleshooting is that you will unable to using "foreach" in future! :)

Why Sight?

Maybe your team member often using database query in the "foreach" block. When you start using Sight, the bad code will be disappeared.

We should better avoid too many join queries. If the join only for one field, we should better to do that with many time queries. But then we must do coding more! Now it is simple.

Maybe you often using database view to query for trans form many id fields to name. That is just a bad query for database performance and the legibility of the code. With Sight you can prohibit them from using these queries.

With database you could doing hasOne and hasMany join query. But you could not get one record with hasMany join query. You should merge the record manually with coding with query many times. With Sight it will be simple!

Maybe you had used the library like League\Fractal, we recommend you have a try with Sight!

Maybe you use the mutators. But you had need to transform the field after some doing. With Sight you could doing it just before return to controller.

Features

Getting Start

Install

Code Sample

It is very simple! You just using it like using Model.

The function chain is just like:

Just like in Model Or SQL:

Of course, it is not same as Model at all.

At first you should create a presenter class to extents the Presenter. For Instanace;

Then you could add a function to get the data.

Then you can call from controller:

And you also could define the mapping in the property:

Then the created_by will return the user_name field from the array Users.

Maybe you found that is very simple.

Just all!

Document

Class Presenter

Presenter::selectFields($field_lists)

The $field_lists could be array or comma seperated string.

With the function you could decide that which fields will be show.

And you could change the key name with the field mapping.

Presenter::fromLocal($data_list,$alias,$path)

The $data_list could be array, also could be Collection object of Laravel.

Optional paramater. The $alias is a name for we access it after.

Optional paramater. When the data is from elasticsearch, we should point that which node is fact data we need.

$path is a dot seperated string.

Presenter::fromLocalItem($data_item,$alias,$data_path)

The function is same as the fucntion fromLocal. But it only for single item. So the first argument is $data_item and not $data_list.

Presenter::pluck(...$fields)

Get the foreign keys as array. After you could query the join array with the foreign keys.

After you got the foreign data, you could using "innerJoinForeign" and "outerJoinForeign" to make the join with foreign array.

If foreign keys are join same foreign array, you could pass the all local keys and pluck once. For instance:

Both the fields created_by and updated_by are in the table User. So you could:

Presenter::innerJoinForeign($data_list,$alias,$keyed_by)

For the params of $data_list and $alias, see: fromLocal()

The $keyed_by is the field name of foreign key in join array.

We sort the array using the $keyed_by for reducing the performance.

The function with join type "inner", that like database, if foreign array not exists, we will remove the record.

Presenter::outerJoinForeign($data_list,$alias,$keyed_by)

The Outer join is mean that when the foreign record not exists, we will keep the record in the output table.

About paramerters, see innerJoinForeign

Presenter::onRelation($local_field, $foreign_alias, $foreign_field, $relation_type)

The function is like the on phrase "on" in the SQL.

All of the properties are: $local_alias, $local_field, $foreign_alias, $foreign_field, $relation_type $foreign_fieds You need not pass $local_alias, because the program could get the $local_alias from other function.

In SQL clause: on local_table.field_local_name = foreign_table.field_foreign_name. And the $local_field just is 'field_local_name'.

In SQL clause: on local_table.field_local_name = foreign_table.field_foreign_name. And the $foreign_alias is the 'foreign_table'.

In SQL clause: on local_table.field_local_name = foreign_table.field_foreign_name. And the $foreign_field is the 'field_foreign_name'.

The $relation_type is number of RelationEnum which contains values:

-- HAS_ONE:   There is 1 item in join array.
-- HAS_MANY:   There are many items in join array.
-- HAS_MANY_MERGE: There are many items in join array and must to merge to a field.
-- HAS_MANY_SPLIT: There are many items in join array and must to merge to a field.

For HAS_MANY_MERGE AND HAS_MANY_SPLIT you should give a function to merge the records.

Presenter::onRelationbyObject(Relation $relation)

The function is same as onRelation. But you should pass an object of Relation.

see Class Relation.

Presenter::addFieldMapping($key,$src,$type,$alias)

What is mapping? The mapping is used for the field transform.

The unique name for the mapping. And it also is the output fieldname.

The $src is given the location where we could get the value. Maybe it is a name of a field or of a function, or of a formatter's name.

The $type is given that how we could get the value. It is a number of MappingTypeEnum which contains values:

-- FIELD_NAME : Access the value via field name
-- DATA_FORMATER:Transform the value via method of class DataFormatter.
-- METHOD_NAME: Access the value via method name. You should add member method to the class. The difference of the DataFormatter, DataFormatter could using for many fields. The mapping key of the DataFormatter is both source fieldname and output field name, and the member method is only for one field, and  the key of member method is only output field name.   
-- ARRAY_PATH: Access the value via path of array. for instance: "a.b.c". If the data is from ElasticSearch, Or the data contains the Json fields. And you need to flatten it. You could use ARRAY_PATH.
-- JOIN_FIELD: Access the value from the join array

The rules of mapping are:

Presenter::addFieldMappingByObject(FieldMapping $mapping)

The function is same as addFieldMapping. But you should pass an object of FieldMapping.

see Class FieldMapping.

Presenter::addFieldMappingList($mapping_list)

The function is same as addFieldMapping. But addFieldMapping only support to add 1 mapping. addFieldMappingList support to add an array of mappings.

The array formatter is:

Presenter::addFormatter($name,$callback)

Add a function to the DataFormatter.

Please see the source of \Bardoqi\Sight\Formatters\DataFormatter. There are some functions for converting in the class.

And if you want to add new function, you could use addFormatter;

The name of the Formatter.

The function of Converting.

Presenter::toArray()

Return the record list array.

Presenter::toItemArray()

Return on record. It is using with SelectLocalItem.

Presenter::toPaginateArray()

Return the record list array.

Presenter::toTreeArray($parent_id_key)

$return the list with tree structure.

Give the field name of the parent_id. The default value is 'parent_d'.

Presenter::getValue($field_name)

Get the value of the current item via name of field ($field_name) through the mapping.

Functions for API Response

There are the functions for the API response:

setError(), getError(), setMessage(), getMessage(), setStatusCode(), getStatusCode()

Class FieldMapping

FieldMapping::of()

It is a short-name function for create a FieldMapping instance.

And other functions is for the peroperty's value.

You could use the operator chain for the instance initial.

For instance:

Class Relation

Relation::of()

It is a short-name function for create a Relation instance.

And other functions are for the property's value.

You could use the operator chain for the instance initial.

For instance:

Class CombineItem

if you using the function $this->getCurrentItem(), it will be return a instance of CombineItem;

CombineItem::getItemValue($field_name,$offset = 0, $alias = null)

Get the value of an item.

The name of the field you want to read

If the relation type is HAS_MANY, HAS_MANY_MERGE and HAS_MANY_SPLIT, you should pass the $offset.

If the field you want to read is in join array, you should pass the $alias.

CombineItem::getData($alias)

Get the join data with an alias of join array. It will return an instance of IMapItem.

Interface IMapItem

There are 2 class implements the interface IMapItem: MultiMapItem, SingleMapitem.

IMapItem::findByPath($path,$offset = null)

Find the value form the json field.

If the class is MultiMapItem, you should pass $offset.

IMapItem::hasColunm($name)

Check if the field name $name exists.

IMapItem::getItemValue($key,$offset = null);

Get the value form the field.

If the class is MultiMapItem, you should pass $offset.

Exceptions

There are many exceptions for helping your coding and to flatten your developing.

We are enjoying to tell you the detail about:

FAQ

Q; Could you tell me the difference about league/fractal And Sight?

A: The league/fractal is a best library for transforming the data. And with Sight you could using array join,

Q: Why we need define the mapping? Why not using data structure like league/fractal?

A: With mapping we could to get manyfold using of functions and formatters for transform.

Troubleshootings

Road Mapping

In the plan:

Has released:

Contribution

  1. Fork the repository
  2. Create Feat_xxx branch
  3. Commit your code
  4. Create Pull Request

Donation

If you find this project useful, you can buy author a glass of juice 🍹

donate

License

MIT

Copyright [2020] Bardo Qi [email protected]


All versions of sight with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
laravel/framework Version ^5.8|^6|^7|^8
illuminate/support Version ^5.8|^6|^7|^8
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 bardoqi/sight contains the following files

Loading the files please wait ....