Download the PHP package weiwenhao/tree-ql without Composer

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

English | 简体中文

What is tree-ql?

tree-ql is a laravel extension that builds a highly descriptive, readable, high-performance API with no redundancy through a simple configuration.

Basic description

Quick description

Complex description

Installation

Make sure your laravel version is above 5.5 and execute in the project root directory

The current version number < 1.0.0, which belongs to the alpha version.

Document

include

You can see that the core of tree-ql is include, so what is the grammar rule of include?

You can see that the include syntax is simpler, add two points.

Simple configuration

I have been introducing the function and external performance of tree-ql. Now let me introduce the internal configuration of tree-ql. First, let's look at the configuration entry file.

From the perspective of the front-end, the description describes the fields that are indistinguishable, such as user, content, liked, etc., but from the perspective of the backend, we will divide the include fields into four types. That is, the above code segment The four attributes column/relations/custom/meta, which cover all the fields involved in our daily api writing process.

columns

It is the column in the database.

When do you need to include the column?

From the perspective of SQL statements, select * is a very uncommitted way to write, it has uncontrollable performance problems and field redundancy problems. The most common example is the content of our post. Usually get the SQL list of the post list In the middle, we will not take out the content. The content will be retrieved only when the post details are displayed.

In this case, there is a practice in the past is test.com/api/posts/{post}?fields=id,title,content. But in tree-ql column can be controlled by include, avoiding the problem of select * At the same time, it is more consistent.

relations

Relations are Relationships in laravel, which correspond to association methods in Model.

When do you need to include the relation?

In the scene of the post list. On the pc side, due to the sufficient placement, the author information is usually displayed. However, the display position in android/ios is small, and the author information is usually not displayed. The author here belongs to the post, ie belogs to user Relationship relationship.

In the past, you can write a generic api (always carry author information) to adapt to both ends, or write two apis to adapt pc and android/ios. Now we have a better way to let the client decide according to the actual situation. Do you need to carry author information?

which is pc: test.com/api/posts?include=user, android/ios: test.com/api/posts

Note that since user belongs to relation, you need to define the related Resource for user. By default, PostsResource will associate app/Resources/UserResource. Of course you can specify user corresponding resource.

UserResource definition

And the corresponding relationship

With the definition of the online, we can have a happy include=user

When the field defined in relation consists of multiple words $relations = ['custom_relation'] defines the underlined word segmentation. The association method uses the small hump both customRelation()

In summary, as long as the field defined in the relation, you need the corresponding Resource and Model relationship support.

custom

It is not stored in the database, and the column is calculated by some rules.

When do you need to include custom?

In some scenarios of a list of posts, it is shown whether the current user has thumb up over the post, which is a performance-intensive calculation.

The client likes this easy-to-bind data structure, but there is no liked field in the post table to record whether you liked the post.

At this point custom has come in handy, as defined in $custom above. But what's worse?

Yes, we still have a callback to determine whether the current login user liked the post. But php does not support the above. So in tree-ql we need to pull the callback out.

This is the use of custom, and the use of callbacks, the client only needs to pass test.com/api/posts?include=liked will trigger the callback, and return the corresponding results.

When the field defined in custom consists of multiple words $custom = ['custom_test'] defines the underlined word segmentation. The callback method uses the small hump both customTest($item, ​$params)

meta

One point that must be explained is that tree-ql wraps data and meta for the outermost layer of data. I think this is necessary, for example, in a scene with paging, we can put the paging information in meta.

Similarly, we can define some additional information in the meta according to business needs, and set the callback (consistent with the custom callback operation, but the callback parameter is only params), let the client to include.

The pagination here does not require active include, tree-ql will maintain this data for you.

When the field defined in meta is composed of multiple words, $meta = ['custom_meta'] defines the underlined word segmentation. The callback method uses the small hump both customMeta($params)

default

The definition in default is obtained from columns/relations/custom/meta, and the definition in default is included by default, without the need to explicitly include it in the url.

Resource nesting

Although there are 4 types of configurations in our Resource, only the fields of the relation type allow resource nesting using the . and {} syntax.

test.com/api/posts?include=comments{user}

params

This is the syntax of params. As mentioned above, custom and meta have corresponding callback functions, so params are also passed to the callback function.

There is also a type of situation where relational params. relation load is responsible for tree-ql, and there is no custom callback function. But in load, the corresponding callback is reserved.

For example, test.com/api/posts/{post}?include=comments(sort_by:floor) then the corresponding callback is

The grammar rules of include and all the configuration rules of tree-ql have been introduced. Although it takes a long time to introduce, most of the space is used to introduce the use of the scene, the actual configuration is very simple.

Use

Take a look at PostController, the use of tree-ql is clear at a glance.

The only thing to explain here is the column() query constructor, which is provided by tree-ql. It will add the appropriate select() to the Builder according to the column and default defined in PostResource, combined with the actual include, instead of select *

License

This project is licensed under the MIT License


All versions of tree-ql with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1.0
illuminate/support Version 5.5.*|5.6.*|5.7.*|5.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 weiwenhao/tree-ql contains the following files

Loading the files please wait ...