[BeanCan Resty] Correct way to extend rest methods

53 views
Skip to first unread message

Dario Marotta

unread,
Apr 24, 2022, 10:12:05 AM4/24/22
to redbeanphp
As in subject, i'd like to add some rest apis to beanCan, for example make it call a CSVimport extension
(something like R::CSVimport($data))

Which should be the correct way to add my custom calls?
Should i extend \RedBeanPHP\SimpleModel ?

In some case, the subject af the call would not be a bean (see CSVimport example)

The rest url could be something like this:

POST => {site_id}/{table_name}/csv_import (acccepts an array containing csv data)

Dario Marotta

unread,
May 16, 2022, 6:14:59 AM5/16/22
to redbeanphp
UP for this subject! 

gabor

unread,
May 21, 2022, 4:57:16 AM5/21/22
to redbeanphp
You can extend the BeanCan with standard OOP techniques. However some of the methods are private, which is a mistake. You need to turn those methods to protected to be able to override them.
Another option would be to wrap the BeanCan object in your own class.

cheers
Gabor

Dario Marotta

unread,
May 21, 2022, 6:47:13 AM5/21/22
to redbeanphp
Could you show me a short example of OOP  extension please? 

gabor

unread,
May 22, 2022, 5:55:26 AM5/22/22
to redbeanphp
I fixed the methods for you: https://github.com/gabordemooij/RB4Plugins/commit/49462041041dce4a16e0886048fe55d3e2fc1299


OOP extension is just extending the class:

class MyBeanCanResty extends BeanCanResty {
}...

now you can override any method you like.

cheers
Gabor
Reply all
Reply to author
Forward
0 new messages