|
|||||||
![]() |
|
|
Thread Tools |
|
#1
|
|||
|
|||
|
Updated 08/04/2009: Fixed len property issue and class level path's
Hi guys, I thought it would be nice to show another way of implementing Direct on a PHP server stack. It is using PHP comments and reflection to create the API for you automagically. I haven't documented it properly yet, and I dont have a client-side example to show it of, but I thought I would put it out here already anyway for you to try. I think the result is quite flexible and the router part should be easily extensible to use this with any server-side MVC framework out there . You can download the source code here. It consists of 3 classes called:
An example api.php that you would include in a <script> tag:
Here is a simple File class that shows of some of the other options like @formHandler (see how it handles file uploads nicely) and @remoteName (list is a reserved keyword in PHP so thats why we have to use the @remoteName option)
|
|
#2
|
||||
|
||||
|
Hi Tommy-
That is great. I wrote something similar for database field instantiantion / altering by parsing the files for doc comments in PHP4 - I didn't even realize the PHP5 reflection API lets you grab the doc comments. I plan on continuing development with my stuff and if I come up with any additional / generic parsing stuff, I'll post it back. Best Regards- Mark |
|
#3
|
|||
|
|||
|
Hi Fabrizim,
I had never looked at the Reflection capabilities in PHP5 before, but when I started doing this PHP router I thought it would be very useful. And it turned out it was. Im interested in what you come up with in regards to additional / generic parsing of the classes and looking forward to your post. |
|
#4
|
||||
|
||||
|
Ported your nice classes to a TYPO3 Extension will it release it soon
|
|
#5
|
||||
|
||||
|
yeah, this can be used in TYPO3 very well, great! (increase the TYPO3 lobby
)
__________________
vg Steffen |
|
#6
|
||||
|
||||
|
Hi!
There are some huge problems with the ExtJs's ExtDirectPack. The first enormous design error is, that we definitely don't want a third-party tool to know the way our classes should be constructed. First I tried the reverse-engineers way to implement the Sphicy style automatic dependency injections. But still, that's not what we want from a third-party. The other trouble was the untestability. Anyone interested in php unit-testing can find a great slide by Sebastian Bergman at this link. So I've started to solve these problems, and below is the first peak of it. The key concept is to add already constructed instances to the api instead of classnames. First of all, How a simple class looks like: TestClass.php <?php
class TestClass
{
/**
* @remotable
*/
public function shout($what)
{
return 'SHOUT: '.$what;
}
/**
* @remotable
*/
public function postHandler($name,$files=array()){
return array(
'gotName'=>$name,
'gotFiles'=>$files
);
}
}
?>
api.php <?php
require_once('TestClass.php');
require_once('ExtDirect/Api.php');
$api=new ExtDirect_Api();
$api->add(new TestClass());
//$api->setRouterUrl('router.php');
echo $api->output();
?>
router.php <?php
require_once('TestClass.php');
require_once('ExtDirect/Api.php');
require_once('ExtDirect/Router.php');
$api=new ExtDirect_Api();
$api->add(new TestClass());
//$api->setRouterUrl('router.php');
$router = new ExtDirect_Router($api);
echo $router->getResponse();
?>
Grab the source from here. The development is far from finished. Caching and the yet not refactored candy-s are soon to come. This release is just the absolute core ![]() Due to the refactoring, the code is all covered with tests which ensure the stability and functionality. A bit later the project will be public to see for anyone. |
|
#7
|
|||
|
|||
|
L]hi,
I'm having a little problem with the Ext.Direct PHP implementation. I have copied the entire example locally. I then created a basic html file, included the api.php as script source. added a button and then implemented a handler. The Handler below is called successfully, but the return value is undefined.
Using firebug I examined the router.php response as follows:
I have downloaded the latest version of Ext RC2 Any help or direction would be appreciated. Thanks, Mark |
|
#8
|
||||
|
||||
|
i think you have to handle the response like that,
|
|
#9
|
|||
|
|||
|
and you truly are, mr sunshine :-)
that works a treat. although, is there another implementation which doesn't require a function handler for the return value? the docs are a little thin on direct, although i'm piecing the bits together. |
|
#10
|
||||
|
||||
|
Keep in mind that Ext.Direct is asynchronous. So, that means that in order to act upon the value being returned by the server, you'll have to specify a callback in your method call to the server. Mr. Sunshine illustrates that, but didn't specifically indicate the issue was with not staying within the asynch paradigm.
__________________
Jeff Howden Ext JS - Support Team Volunteer jeff@extjs.com Any and all code samples that are authored by me and posted on the Ext forums or website are hereby released into the public domain and I release anyone or entity of liability by using said code samples unless explicitly stated otherwise. Opinions are mine and not necessarily endorsed by Ext, LLC. Please do not contact me directly for assistance unless requested by me. |
![]() |
| Thread Tools | |
|
|