mevdschee / php-crud-api

Single file PHP script that adds a REST API to a SQL database
MIT License
3.62k stars 1.01k forks source link

Use php-crud-api integrated in own project as database / rest api class? #638

Closed pwFoo closed 4 years ago

pwFoo commented 4 years ago

Hi,

is it possible to modify compiled api.php to use it as a class instance inside of my own project?

I looked into api.php and the source index.php file. Looks like that part need to be removed from api.php and moved to my own project to init php-crud-api?

<?php 
namespace Tqdev\PhpCrudApi;

$config = new Config([
    'username' => 'php-crud-api',
    'password' => 'php-crud-api',
    'database' => 'php-crud-api'
]);

And that part is need to routed by my custom project to php-crud-api?

$request = RequestFactory::fromGlobals();
$api = new Api($config);
$response = $api->handle($request);
ResponseUtils::output($response);

Would it possible that you add such a api.php version for that use case? Just to not need to change the file each time I update it? Could be named crudapi.php to be compatible to existing all in one api.php?

mevdschee commented 4 years ago

For this there is composer support. What you do is you make php-crud-api a dependency of your project using:

composer require mevdschee/php-crud-api:*

This way you will automatically receive updates when your run:

composer update

I hope this helps. See: https://getcomposer.org/doc/

mbnl commented 4 years ago

I'm looking for this too. How can we manage requests from inside, not outside? @mevdschee

mevdschee commented 4 years ago

How can we manage requests from inside, not outside?

Did you see the (composer based) integrations with various frameworks (Laravel, Symfony, SlimPHP)? Did you see and understand how that was done? Do you have questions about that approach?

mevdschee commented 4 years ago

@pwFoo & @mbnl Do you have any updates?

mevdschee commented 4 years ago

Closing due to inactivity.