Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an Authentication Class from Custom Folder #21

Closed
KitCarrau opened this issue Dec 15, 2011 · 4 comments
Closed

Add an Authentication Class from Custom Folder #21

KitCarrau opened this issue Dec 15, 2011 · 4 comments

Comments

@KitCarrau
Copy link

How do you add an authentication class that is not in the root directory for your app using addAuthenticationClass?

addAuthenticationClass only works when my auth class is in the root directory.

I have tried adding the optional parameter of $base_path but it has not worked.

@ghost ghost assigned Luracast Dec 15, 2011
@Luracast
Copy link
Collaborator

Loading php class files from Custom Folders

Solution for this problem is quite simple and nothing specific to Restler framework! Let me explain

addAuthenticationClass($class_name);

As you can see above it only takes the name of the class and it does not care where the php file is located. You can do one the following to make sure your class files are found

  • Use the old style include, include_once or require, require_once to include the php file that contains the class
  • Place the class file in one of the include paths, they need not be in the web root. You may use set_include_path to add your custom folder to include path.
  • You can write and use a custom autoloader function. Take a look at restler.php around line 1210 for an example

Hope this helps, and have fun with Restler :) Also tell us what you want to see in Rester 3.0!

@KitCarrau
Copy link
Author

Hi,

Thank you. I can use one of the work arounds to solve the auth class problem.

For version 3.0, would it possible to have the following:

  • Versioning - To have an inbuilt Restler way to manage your API versions
  • Auth Class Path - Option to add a path to the addAuthenticationClass?

What are your thoughts on these two? Thanks,

Kit

@electrical
Copy link

Hi Kit,

I already started a new 'issue' for new version discussion to avoid having everything scattered.
I've taken the liberty to copy your message into that.

#22

Cheers.

@Luracast
Copy link
Collaborator

Hi @KitCarrau,

It is not a work around, that is how we should load classes in PHP ;)

Design goal for restler is to keep it simple so that any one who knows PHP and OOP should be able to use Restler by thinking how they would do something in plain PHP.

Ideally I should come up with an example index.php (gateway) that shows how we can create a custom folder structure for keeping auth classes, and api classes using spl_autoload.

Will that help?

Versioning Yes, we are already woking on it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants