php-objc /

Filename Size Date modified Message
libffi
samples
utils
47 B
713 B
918 B
2.3 KB
588 B
27.1 KB
1.3 KB
69.6 KB
2.7 KB
4.9 KB
This is an Objective-C bridge for PHP, allowing PHP to create and call into the
Objective-C runtime, and vice versa.

It plumbs the Objective-C auto-load mechanism into PHP, so that you may author
NIB files that reference classes implemented in PHP and have those instantiated
when parts of your user interface are loaded.

Objective-C supports what some people call "mutil-method dispatch" and others
call "method overloading", where two methods can have the same name but a
different set of parameters.  The way that this works is by encoding the
parameter names into the method names, so it's really just an illusion.

Here's a quick start guide to mapping Objective-C method names into PHP, using
the NSApplication class as an example.

+ (NSApplication *)sharedApplication

  this is a static method of the NSApplication class, the PHP way to call it is this:
  
  $App = NSApplication::sharedApplication();

- (void)setDelegate:(id)anObject

  this is a regular "instance" method of the NSApplication object, call it like this:
  
  $App->setDelegate_($anObject)
  
  note that the : is translated to an underscore.

- (id)targetForAction:(SEL)anAction to:(id)aTarget from:(id)sender

  $App->targetForAction_to_from_($anAction, $aTarget, $sender);
  
  note that the names before the colons are encoded into the method name


Method signature hackery

The bridge isn't quite smart enough to automatically figure out type mapping
for everything, particularly if you are declaring a delegate object that will
act as a sink for events, so you will need to provide hints in some cases.

You can provide the hints using doc-comments like this:

class MyDelegate extends NSObject {
	/** @objc:signature c@: */
	function run_() {
		echo "*** run!\n";
	}
}

the "c@:" part defines the return type and parameters for the run_ method; it
is a standard objective-C stype signature.

A TODO item is to also examine @param and @return doc comments, but this is
hard because there isn't always a good way to map them.


Some resources:

http://developer.apple.com/reference/Cocoa/idxObjectiveCLanguage-title.html#doclist

http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ObjC_classic/index.html

http://developer.apple.com/documentation/Cocoa/Reference/ObjCRuntimeRef/index.html#//apple_ref/doc/uid/TP40001418

http://trac.macosforge.org/projects/BridgeSupport

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.