Skip to content

Commit 5a447da

Browse files
authored
Merge branch 'mevdschee:main' into main
2 parents d5c63a6 + 5284548 commit 5a447da

34 files changed

+830
-570
lines changed

.gitattributes

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/docker/ export-ignore
2+
/examples/ export-ignore
3+
/extras/ export-ignore
4+
/src/index.php export-ignore
5+
/tests/ export-ignore
6+
/.gitattributes export-ignore
7+
/.gitignore export-ignore
8+
/.htaccess export-ignore
9+
/*.php export-ignore
10+
/*.sh export-ignore
11+
/docker-compose.yml export-ignore
12+
/Dockerfile export-ignore

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 Maurits van der Schee
3+
Copyright (c) 2022 Maurits van der Schee
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ NB: This is the [TreeQL](https://treeql.org) reference implementation in PHP.
1616

1717
## Installation
1818

19+
Download the "`api.php`" file from the latest release:
20+
21+
https://github.com/mevdschee/php-crud-api/releases/latest or direct from:
22+
https://raw.githubusercontent.com/mevdschee/php-crud-api/main/api.php
23+
1924
This is a single file application! Upload "`api.php`" somewhere and enjoy!
2025

2126
For local development you may run PHP's built-in web server:
@@ -134,8 +139,9 @@ Related projects:
134139
- [PHP-CRUD-UI](https://github.com/mevdschee/php-crud-ui): Single file PHP script that adds a UI to a PHP-CRUD-API project.
135140
- [PHP-CRUD-ADMIN](https://github.com/mevdschee/php-crud-admin): Single file PHP script that adds a database admin interface to a PHP-CRUD-API project.
136141
- [PHP-SP-API](https://github.com/mevdschee/php-sp-api): Single file PHP script that adds a REST API to a SQL database.
137-
- [VUE-CRUD-UI](https://github.com/nlware/vue-crud-ui): Single file Vue.js script that adds a UI to a PHP-CRUD-API project.
138142
- [ra-data-treeql](https://github.com/nkappler/ra-data-treeql): NPM package that provides a [Data Provider](https://marmelab.com/react-admin/DataProviderIntroduction.html) for [React Admin](https://marmelab.com/react-admin/).
143+
- [scriptPilot/vueuse](https://github.com/scriptPilot/vueuse/): Vue [Composables](https://vuejs.org/guide/reusability/composables.html) in addition to [VueUse.org](https://vueuse.org/) (that support PHP-CRUD-API).
144+
- [VUE-CRUD-UI](https://github.com/nlware/vue-crud-ui): Single file Vue.js script that adds a UI to a PHP-CRUD-API project.
139145

140146
There are also ports of this script in:
141147

@@ -285,7 +291,7 @@ On list operations you may apply filters and joins.
285291
### Filters
286292

287293
Filters provide search functionality, on list calls, using the "filter" parameter. You need to specify the column
288-
name, a comma, the match type, another commma and the value you want to filter on. These are supported match types:
294+
name, a comma, the match type, another comma and the value you want to filter on. These are supported match types:
289295

290296
- "cs": contain string (string contains value)
291297
- "sw": start with (string starts with value)
@@ -572,7 +578,7 @@ This adjusts the titles of the posts. And the return values are the number of ro
572578
[1,1]
573579

574580
Which means that there were two update operations and each of them had set one row. Batch operations use database
575-
transactions, so they either all succeed or all fail (successful ones get roled back). If they fail the body will
581+
transactions, so they either all succeed or all fail (successful ones get rolled back). If they fail the body will
576582
contain the list of error documents. In the following response the first operation succeeded and the second operation
577583
of the batch failed due to an integrity violation:
578584

@@ -667,7 +673,7 @@ You can enable the following middleware using the "middlewares" config parameter
667673
- "multiTenancy": Restricts tenants access in a multi-tenant scenario
668674
- "pageLimits": Restricts list operations to prevent database scraping
669675
- "joinLimits": Restricts join parameters to prevent database scraping
670-
- "textSearch": Search in all text fields with a simple paramater
676+
- "textSearch": Search in all text fields with a simple parameter
671677
- "customization": Provides handlers for request and response customization
672678
- "json": Support read/write of JSON strings as JSON objects/arrays
673679
- "xml": Translates all input and output from JSON to XML
@@ -709,6 +715,7 @@ You can tune the middleware behavior using middleware specific configuration par
709715
- "dbAuth.passwordFormField": The name of the form field that holds the password ("password")
710716
- "dbAuth.newPasswordFormField": The name of the form field that holds the new password ("newPassword")
711717
- "dbAuth.registerUser": JSON user data (or "1") in case you want the /register endpoint enabled ("")
718+
- "dbAuth.loginAfterRegistration": 1 or zero if registered users should be logged in after registration ("")
712719
- "dbAuth.passwordLength": Minimum length that the password must have ("12")
713720
- "dbAuth.sessionName": The name of the PHP session that is started ("")
714721
- "jwtAuth.mode": Set to "optional" if you want to allow anonymous access ("required")
@@ -765,7 +772,7 @@ In the sections below you find more information on the built-in middleware.
765772
### Authentication
766773

767774
Currently there are five types of authentication supported. They all store the authenticated user in the `$_SESSION` super global.
768-
This variable can be used in the authorization handlers to decide wether or not sombeody should have read or write access to certain tables, columns or records.
775+
This variable can be used in the authorization handlers to decide wether or not somebody should have read or write access to certain tables, columns or records.
769776
The following overview shows the kinds of authentication middleware that you can enable.
770777

771778
| Name | Middleware | Authenticated via | Users are stored in | Session variable |
@@ -782,7 +789,7 @@ Below you find more information on each of the authentication types.
782789

783790
API key authentication works by sending an API key in a request header.
784791
The header name defaults to "X-API-Key" and can be configured using the 'apiKeyAuth.header' configuration parameter.
785-
Valid API keys must be configured using the 'apiKeyAuth.keys' configuration parameter (comma seperated list).
792+
Valid API keys must be configured using the 'apiKeyAuth.keys' configuration parameter (comma separated list).
786793

787794
X-API-Key: 02c042aa-c3c2-4d11-9dae-1a6e230ea95e
788795

@@ -832,7 +839,7 @@ Note that this middleware uses session cookies and stores the logged in state on
832839

833840
**Login using views with joined table**
834841

835-
For login operations, it is possible to use a view as the usersTable. Such view can return a filtered result from the users table, e.g., *where active = true* or it may also return a result multiple tables thru a table join. At a minimum, the view should include the ***username*** and ***password***.
842+
For login operations, it is possible to use a view as the usersTable. Such view can return a filtered result from the users table, e.g., *where active = true* or it may also return a result multiple tables thru a table join. At a minimum, the view should include the ***username*** and ***password*** and a field named ***id***.
836843

837844
However, views with joined tables are not insertable ([see issue 907](https://github.com/mevdschee/php-crud-api/issues/907) ). As a workaround, use the property ***loginTable*** to set a different reference table for login. The **usersTable** will still be set to the normal, insertable users table.
838845

@@ -1394,6 +1401,9 @@ The following errors may be reported:
13941401
| 1017 | 403 Forbidden | Bad or missing XSRF token
13951402
| 1018 | 403 Forbidden | Only AJAX requests allowed
13961403
| 1019 | 403 Forbidden | Pagination Forbidden
1404+
| 1020 | 409 Conflict | User already exists
1405+
| 1021 | 422 Unprocessable entity | Password too short
1406+
| 1022 | 422 Unprocessable entity | Username is empty
13971407
| 9999 | 500 Internal server error | Unknown error
13981408

13991409
The following JSON structure is used:

0 commit comments

Comments
 (0)