TheSHEEEP
TheSHEEEP

Reputation: 3132

How to break up the "main class" structure for PHP export?

This is my current project.hxml:

-cp Source
-main Login
-php Export/Server
-v

What this does is take one of the classes (Login.hx) and use it as the main class for the whole PHP server.
This isn't very useful for PHP, though, as PHP does not really support the notion of a "main" class, instead you'd need a .php script for each function you want to call on the server from the web, working mostly independently from each other.

The biggest problem here is obviously the "main" class as haxe outputs everything into the specified folder, but renames the Login.hx to index.php.
However, I don't want it to become index.php.
What I want is a login.php, logout.php, morestuff.php, basically all of my haxe classes to become callable php scripts, to be able to call them like this:

/appname/login  
/appname/logout
/appname/morestuff  
etc.

The only ways to achieve this I could think of right now are not-so-nice workarounds.

  1. Create a much bigger project.hxml file, outputting each class into its own folder (so Export/Server/Login, Export/Server/Logout, etc.) using --next. That would work, but would also blow up the size as all the .php files haxe outputs (Std, etc.) would be duplicate within these folders.
  2. Have an actual Main class that uses parameters to "forward" the different calls to the actual classes. So basically the calls would become /appname/Main?function=login, /appname/Main?function=logout, etc.
    This would be more acceptable, but still feels kinda cumbersome.
  3. I'm not a PHP expert, but there is probably a way to do this doing some configurations in PHP internals. I'd rather not.

Surely, there must be a better way?

Upvotes: 1

Views: 158

Answers (1)

Confidant
Confidant

Reputation: 386

I wrestled with this same issue you are having and this was the best I could do. You can change the filename of the php entry script in the hxml file or command-line option using:

--php-front newfilename.php     

You might also find it useful to change where the lib directory is located:

--php-lib ../lib

So the full settings in the hxml file (to generate multiple php entry points) might look like so:

-cp src
-main Main
--php-front joomlahaxe.php
-php bin/com_joomlahaxe/site
-debug

--next
-cp src
-main JoomlahaxeViewJoomlahaxe
--php-front view.html.php   
--php-lib ../../lib
-php bin/com_joomlahaxe/site/views/joomlahaxe

Upvotes: 2

Related Questions