Reputation: 2871
Is there any good Objective-C or Cocoa Bridge/Connector for PHP? I'm interested in Mac development, but want to do it with PHP. It'd be also good if you could recommend me any PHP compiler for Mac.
Note: I already know Titanium-like apps, and that's not what I want. Thanks.
Upvotes: 1
Views: 1364
Reputation: 93
Unfortunately I wasn't able to get the wezfurlong-Bridge running under Mac OS X Lion. So I decided to use the flexibility of Objective-C to let PHP talk to my Cocoa application, even create objects and send messages with arguments to them. You can get the source including the (very basic) sample application on http://github.com/cundd/pop/
Upvotes: 2
Reputation: 16473
I "bridge" PHP like this… simplicity is golden.. If you wanna get fancy, JSON encode things back and forth, and send raw data as base64
encoded strings…
- (NSString *)getSomethingFromPHP {
NSString *scriptPath = [[[NSBundle mainBundle]resourcePath]
stringByAppendingPathComponent:@"myPHPscript.php"];
NSString *standardIn = [myApp someData]
NSTask *php = [NSTask new];
NSPipe *pipe = [NSPipe new];
[php setLaunchPath:@"/usr/bin/php"];
[php setArguments:[NSArray arrayWithObjects:
@"-f", scriptPath, standardIn, nil]];
[php setStandardOutput:pipe];
NSFileHandle *handle = [pipe fileHandleForReading];
[php launch];
NSString *string = [[NSString alloc] initWithData:
[handle readDataToEndOfFile] encoding:NSASCIIStringEncoding];
return string;
}
Upvotes: 0
Reputation: 52535
Looks like there's one here: http://www.slideshare.net/wezfurlong/hot-chocolate-you-got-cocoa-in-my-php
(download link is in the slides)
There's little in PHP that is going to do you any favors with Mac development, though. If you want to do Mac development with a language that has a more familiar syntax and you don't want to deal as much with memory issues and such, doing your coding with MacRuby or RubyCocoa shouldn't be too much of a jump from previous PHP experience.
Upvotes: 2