Search by

1:1 PHP bindings of AppKit and the CoreFoundation run loop it runs on, as classes named after their native counterparts

Package info

github.com/php-io-extensions/appkit

Language:C

Type:php-ext

Ext name:ext-appkit

pkg:composer/php-io-extensions/appkit

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.11.3 2026-11-28 19:12 UTC

This package is auto-updated.

Last update: 2026-12-02 16:54:15 UTC


README

ext-appkit

AppKit and the Core Foundation run loop bound 1:1 into PHP 8.4+

CI AppKit API Packagist PHP License Platform OKF PIE

A Mac app needs a menu bar, windows that resize, zoom, go full screen and carry sheets, controls that follow the system appearance and accent colour, keyboard focus, text input with dead keys and input methods, a Dock icon, and an event loop that sleeps until something happens. Drawing all of that yourself is a toolkit's worth of work before the first window feels at home on macOS.

AppKit is Apple's toolkit for it. NSApplication runs the event loop, NSWindow and NSView hold the interface, controls report through target/action and delegates, Auto Layout and stack and grid views place them, and the Core Foundation run loop sleeps between events. It is written in Objective-C, and Apple's documentation covers every class.

The only problem? PHP can't reach it. This extension binds AppKit, and the Foundation, Core Foundation, Core Graphics, QuartzCore, IOKit and GameController calls it runs on, one to one in Objective-C against the Zend API, linked against the system frameworks, so there is nothing to install but the Xcode Command Line Tools. Each PHP class is its native counterpart (NSApplication, NSEvent, CFRunLoop, …) and each method is one native call; delegates, targets, observers and notification blocks are PHP callables that run on the PHP thread, and an NSException AppKit raises arrives as AppKitException. No defaults, no composites, no opinions: what Apple documents is what you call.

Basic usage

Start AppKit, wait up to 16 ms for one event and dispatch it, then withdraw the app:

$app = NSApplication::sharedApplication();
$app->finishLaunching();
$app->setActivationPolicy(NSApplicationActivationPolicy::REGULAR); // Dock icon
$app->activate();

// Sleep up to 16 ms for the next event, dispatch it.
$event = $app->nextEventMatchingMaskUntilDateInModeDequeue(
    NSEventMask::ANY, NSDate::dateWithTimeIntervalSinceNow(0.016), NSDefaultRunLoopMode, true,
);
if ($event) {
    $app->sendEvent($event);
}

$app->setActivationPolicy(NSApplicationActivationPolicy::PROHIBITED); // icon gone

A window with a menu item whose action runs PHP:

$window = NSWindow::initWithContentRectStyleMaskBackingDefer(
    new NSRect(0, 0, 480, 320),
    NSWindowStyleMask::TITLED->value | NSWindowStyleMask::CLOSABLE->value,
    NSBackingStoreType::BUFFERED,
    false,
);
$window->setReleasedWhenClosed(false); // PHP holds the reference; AppKit must not release it on close

$delegate = new ObjCDelegate('NSWindowDelegate');
$delegate->on('windowWillClose:', fn (NSObject $notification) => print("closed\n"));
$window->setDelegate($delegate);       // AppKit holds delegates weakly: keep $delegate
$window->makeKeyAndOrderFront(null);

$target = new ObjCTarget(fn (?NSObject $sender) => print("refresh\n"));
$item = NSMenuItem::initWithTitleActionKeyEquivalent('Refresh', ObjCTarget::ACTION, 'r');
$item->setTarget($target);             // targets are weak too: keep $target

Requirements

  • macOS. composer.json lists only the darwin family.
  • PHP 8.4 or newer, NTS or ZTS, with phpize and php-config.
  • Xcode Command Line Tools: clang and the macOS SDK, whose frameworks the module links.
# Xcode Command Line Tools, and Homebrew's PHP ships phpize and php-config
xcode-select --install
brew install php@8.4

Installation

With PHP PIE (recommended)

pie install php-io-extensions/appkit

Manually (install script)

git clone https://github.com/php-io-extensions/appkit.git
cd appkit

./install-macos.sh                     # Homebrew php@8.4 and php@8.4-zts
./install-macos.sh /path/to/bin/php    # specific PHP binaries

Manually (phpize)

git clone https://github.com/php-io-extensions/appkit.git
cd appkit
phpize
./configure --enable-appkit
make -j"$(sysctl -n hw.ncpu)"
sudo make install

Then add extension=appkit.so to your php.ini, or to a file in the scan directory php --ini reports.

Verify

$ php --ri appkit

appkit

appkit support => enabled
Version => 0.11.3
macOS => Version 15.4.1 (Build 24E263)

API

The calls that start AppKit, present the app to the OS and withdraw it, pump events, sleep with a budget, wake a sleep from a file descriptor, open and close windows, build the menu bar, lay out and populate views, observe changes, and play video:

Class Native
NSObject, NSResponder className, isKindOfClass:, respondsToSelector:, isEqual:, hash, description; pointer() (the address, for another extension), fromPointer() (the object at an address, checked against the called class); NSResponder: nextResponder, setNextResponder:, acceptsFirstResponder; NSString (every string object AppKit hands back): stringWithString:, UTF8String
CALayer layer, contentsScale/setContentsScale:, sublayers, addSublayer:, backgroundColor/setBackgroundColor:, contents/setContents:, contentsGravity/setContentsGravity:, masksToBounds/setMasksToBounds:
NSApplication sharedApplication, finishLaunching, run, stop:, activationPolicy, setActivationPolicy:, activate, activateIgnoringOtherApps:, deactivate, isActive, isRunning, nextEventMatchingMask:untilDate:inMode:dequeue:, discardEventsMatchingMask:beforeEvent:, sendEvent:, postEvent:atStart:, currentEvent, updateWindows, delegate, setDelegate:, mainMenu, setMainMenu:, keyWindow, mainWindow, windows, orderFrontStandardAboutPanel:, orderFrontStandardAboutPanelWithOptions:; applicationIconImage, setApplicationIconImage: (null restores the bundle icon), requestUserAttention: (NSRequestUserAttentionType), cancelUserAttentionRequest:
NSWindow initWithContentRect:styleMask:backing:defer: (allocates the called class), title, setTitle:, makeKeyAndOrderFront:, orderOut:, close, performClose:, beginSheet:completionHandler:, endSheet:, endSheet:returnCode:, sheets, attachedSheet, sheetParent, miniaturize:, isVisible, isKeyWindow, isMainWindow, canBecomeKeyWindow, canBecomeMainWindow, makeKeyWindow, delegate, setDelegate:, isReleasedWhenClosed, setReleasedWhenClosed:, center, contentView/setContentView:, windowNumber, frame, setContentSize:, styleMask, backingScaleFactor; window modes: setStyleMask:, contentMin/MaxSize (+set), contentAspectRatio (+set), setFrameOrigin:, setFrame:display:, contentRectForFrameRect:, frameRectForContentRect:, convertRectToBacking:, orderFront:, zoom:, isZoomed, deminiaturize:, isMiniaturized, toggleFullScreen:, collectionBehavior (+set, NSWindowCollectionBehavior), level (+set, NS*WindowLevel or CGDisplay::shieldingWindowLevel()), screen, isOpaque/setOpaque:, backgroundColor (+set, null = default), hasShadow (+set), titlebarAppearsTransparent (+set), titleVisibility (+set), ignoresMouseEvents (+set), isMovableByWindowBackground (+set), occlusionState (NSWindowOcclusionState bits), alphaValue (+set), acceptsMouseMovedEvents (+set), static windowNumberAtPoint:belowWindowWithWindowNumber:, makeFirstResponder:, firstResponder, initialFirstResponder/setInitialFirstResponder:, selectNextKeyView:, selectPreviousKeyView:, setAutorecalculatesKeyViewLoop:
NSView initWithFrame: (allocates the class it is called on), frame/setFrame:, window, menu, superview, subviews, addSubview:, removeFromSuperview, isHidden/setHidden:, isHiddenOrHasHiddenAncestor, contentHuggingPriorityForOrientation:/setContentHuggingPriority:forOrientation:, contentCompressionResistancePriorityForOrientation:/setContentCompressionResistancePriority:forOrientation:, fittingSize, intrinsicContentSize, layoutSubtreeIfNeeded, visibleRect, scrollPoint:, translatesAutoresizingMaskIntoConstraints/set…:, wantsLayer/setWantsLayer:, layer/setLayer:, postsFrameChangedNotifications/set…:, postsBoundsChangedNotifications/set…:, widthAnchor … centerYAnchor; bounds, convertRectToBacking:, convertSizeToBacking:, setNeedsDisplayInRect: (partial redraw), displayIfNeeded, layerContentsRedrawPolicy (+set), displayLinkWithTarget:selector: (macOS 14+, a CADisplayLink not yet on a run loop), safeAreaRect (macOS 11), hitTest:, convertPoint:fromView:, isFlipped, nextKeyView (+set)
NSLayoutAnchor, NSLayoutDimension, NSLayoutXAxisAnchor, NSLayoutYAxisAnchor, NSLayoutConstraint constraintEqualToAnchor:, constraintEqualToAnchor:constant:, constraintGreaterThanOrEqualToAnchor: / constraintLessThanOrEqualToAnchor: (± constant:); on NSLayoutDimension: constraintEqualToConstant:, constraintGreaterThanOrEqualToConstant:, constraintLessThanOrEqualToConstant:; activateConstraints:, deactivateConstraints:, isActive/setActive:, constant/setConstant:, priority/setPriority:
NSStackView stackViewWithViews:, orientation, spacing, edgeInsets, alignment, distribution (+ setters), addArrangedSubview:, insertArrangedSubview:atIndex:, removeArrangedSubview:, arrangedSubviews, customSpacingAfterView:/setCustomSpacing:afterView:, visibilityPriorityForView:/setVisibilityPriority:forView:, huggingPriorityForOrientation:/setHuggingPriority:forOrientation:
NSGridView, NSGridCell, NSGridRow, NSGridColumn gridViewWithNumberOfColumns:rows:, numberOfRows/numberOfColumns, addRowWithViews:, insertRowAtIndex:withViews:, removeRowAtIndex:, addColumnWithViews:, rowSpacing/columnSpacing (+ setters), cellAtColumnIndex:rowIndex:, mergeCellsInHorizontalRange:verticalRange:, rowAtIndex:, columnAtIndex:; cell emptyContentView, contentView/setContentView:, xPlacement/yPlacement (+ setters); row height, topPadding, bottomPadding, yPlacement (+ setters); column width, leadingPadding, trailingPadding, xPlacement (+ setters)
NSColor, NSFont, NSFontManager colorWithRed:green:blue:alpha:, redComponent … alphaComponent (of the colour as it is), CGColor, colorWithCGColor:, colorUsingColorSpace:, controlAccentColor (a catalog colour: convert before reading components), NSColorSpace; systemFontOfSize:weight:, monospacedSystemFontOfSize:weight:, fontWithName:size:, systemFontSize, pointSize, familyName (nullable); sharedFontManager, fontWithFamily:traits:weight:size:, weightOfFont:; NSFont::WEIGHT_* = NSFontWeight*
NSControl sendAction:to:, isEnabled/setEnabled:, target/setTarget:, action/setAction:, stringValue, doubleValue, integerValue (+ setters), font/setFont:, alignment/setAlignment:, sizeToFit, performClick:, cell
NSTextField, NSSecureTextField labelWithString:, labelWithAttributedString:, attributedStringValue, allowsEditingTextAttributes, isSelectable, textFieldWithString:, placeholderString, isEditable, isBezeled, drawsBackground, textColor, backgroundColor, lineBreakMode, maximumNumberOfLines, preferredMaxLayoutWidth, delegate (+ setters); secure field initWithFrame:
NSAttributedString, NSMutableAttributedString, NSTextStorage, NSWorkspace initWithString:attributes:, string, length, attribute:atIndex:effectiveRange: (value and run), NSLinkAttributeName, NSFontAttributeName, NSParagraphStyleAttributeName, NSForegroundColorAttributeName, NSBackgroundColorAttributeName; addAttribute:value:range:, removeAttribute:range: (a range past the string raises AppKitException NSRangeException; a foreground or background colour that is no NSColor is a TypeError), setAttributedString:, beginEditing, endEditing; sharedWorkspace, openURL:
NSParagraphStyle, NSMutableParagraphStyle, NSTextBlock alignment, textBlocks; init, setAlignment:, setTextBlocks:; NSTextBlock: init, backgroundColor/setBackgroundColor:, setValue:type:forDimension:, valueForDimension:, valueTypeForDimension:
NSButton, NSSwitch buttonWithTitle:target:action:, checkboxWithTitle:target:action:, setButtonType:, title/setTitle:, state/setState:, contentTintColor/setContentTintColor:, keyEquivalent/setKeyEquivalent:; switch initWithFrame:, state/setState:
NSSlider, NSPopUpButton sliderWithValue:minValue:maxValue:target:action:, minValue/maxValue (+ setters), isContinuous/setContinuous:; initWithFrame:pullsDown:, addItemWithTitle:, addItemsWithTitles:, removeAllItems, numberOfItems, indexOfSelectedItem, selectItemAtIndex:, titleOfSelectedItem, itemTitles; an NSPopUpButton is an NSButton (setBordered: draws a flat pull-down)
NSComboBox, NSScroller addItemWithObjectValue: (a string), removeAllItems, numberOfItems, indexOfSelectedItem, selectItemAtIndex:, deselectItemAtIndex:, setNumberOfVisibleItems:; +scrollerWidthForControlSize:scrollerStyle:, +preferredScrollerStyle, scrollerStyle (+ set), knobProportion (+ set), hitPart, NSPreferredScrollerStyleDidChangeNotification
NSButton images, NSTrackingArea image/setImage:, imagePosition/setImagePosition: (NSCellImagePosition), isBordered/setBordered:; NSMenuItem image/setImage:; NSControl refusesFirstResponder (+ set); initWithRect:options:owner:userInfo:, rect, options, owner; NSView addTrackingArea:, removeTrackingArea:, convertRect:toView:; NSEvent phase, momentumPhase, trackingArea; NSWindow addChildWindow:ordered:, removeChildWindow:, convertRectToScreen:; NSTabView insertTabViewItem:atIndex:
NSDatePicker, NSTimeZone, NSProgressIndicator initWithFrame:, dateValue/setDateValue:, timeZone/setTimeZone: (NSTimeZone timeZoneWithName:, name), setDatePickerStyle:, setDatePickerElements: (ELEMENT_*), setDatePickerMode:; setStyle:, minValue/maxValue/doubleValue (+ setters), isIndeterminate/setIndeterminate:, startAnimation:/stopAnimation:, setDisplayedWhenStopped:
NSAlert, NSPanel, NSSavePanel, NSOpenPanel init (allocates the called class), messageText/setMessageText:, informativeText/setInformativeText:, addButtonWithTitle:, buttons, beginSheetModalForWindow:completionHandler: (a ^(NSModalResponse) block to the closure; the button at index i returns NSAlertFirstButtonReturn + i), window; savePanel, URL, directoryURL/setDirectoryURL:, nameFieldStringValue/setNameFieldStringValue:, message/setMessage:, beginSheetModalForWindow:completionHandler:; openPanel, URLs, canChooseFiles, canChooseDirectories, allowsMultipleSelection (each + set)
NSPasteboard generalPasteboard, clearContents (the new change count), setString:forType:, stringForType:; any thread
NSAppearance appearanceNamed:, name; constants NSAppearanceNameAqua, NSAppearanceNameDarkAqua; NSApplication appearance / setAppearance:
NSSplitView, NSTabView, NSTabViewItem isVertical/setVertical:, dividerStyle/setDividerStyle:, dividerThickness, arrangesAllSubviews (+ set), addArrangedSubview:, insertArrangedSubview:atIndex:, removeArrangedSubview:, arrangedSubviews, setPosition:ofDividerAtIndex:, adjustSubviews, isSubviewCollapsed:, holdingPriorityForSubviewAtIndex: (+ set); addTabViewItem:, removeTabViewItem:, tabViewItems, numberOfTabViewItems, indexOfTabViewItemWithIdentifier: (-1 when none), selectTabViewItemWithIdentifier:, selectedTabViewItem, delegate (+ set); initWithIdentifier: (an NSString), identifier, label/setLabel:, view/setView:, tabView. AppKit's own behaviour throughout: an insert past the end and an unknown identifier raise (AppKitException), a divider index out of range and a foreign item do nothing
NSImage, NSImageView, NSBox, NSScrollView, NSClipView, NSTextView initWithContentsOfFile: (null when unreadable), initWithCGImage:size:, size/setSize:; imageViewWithImage:, image/setImage:, imageScaling/setImageScaling:; boxType/setBoxType:; contentView (the clip view), documentView/setDocumentView:, hasVerticalScroller/hasHorizontalScroller/drawsBackground (+ setters), contentSize, reflectScrolledClipView:, documentVisibleRect; NSClipView scrollToPoint:; scrollableTextView, string/setString:, backgroundColor/drawsBackground (+ setters), layoutManager, textContainer, textContainerInset, textStorage, selectedRange/setSelectedRange:, scrollRangeToVisible:, isHorizontallyResizable/setHorizontallyResizable:, maxSize/setMaxSize:; NSTextContainer widthTracksTextView, size (+ setters); NSLayoutManager ensureLayoutForTextContainer:, usedRectForTextContainer:, glyphRangeForCharacterRange:actualCharacterRange: (both ranges), boundingRectForGlyphRange:inTextContainer:, allowsNonContiguousLayout (+ set); isEditable/setEditable:, font, textColor, delegate (+ setters)
NSTableView, NSTableColumn, NSTableHeaderView, NSCell, NSIndexSet addTableColumn:/removeTableColumn:, tableColumns, dataSource/delegate (+ setters), reloadData, numberOfRows, selectedRow, selectRowIndexes:byExtendingSelection:, deselectAll:, setAllowsEmptySelection:, setUsesAlternatingRowBackgroundColors:, backgroundColor/setBackgroundColor:, headerView/setHeaderView:, preparedCellAtColumn:row:, viewAtColumn:row:makeIfNecessary:, doubleAction/setDoubleAction:, clickedRow, scrollRowToVisible:; NSOutlineView outlineTableColumn (+ setter), expandItem:, collapseItem:, isItemExpanded:, itemAtRow:, rowForItem:, reloadItem:reloadChildren:, indentationPerLevel (+ setter); NSCell objectValue, startTrackingAt:inView:, continueTracking:at:inView:, stopTracking:at:inView:mouseIsUp:; column initWithIdentifier:, identifier, title, width, setResizingMask: (RESIZING_MASK_*); indexSetWithIndex:, firstIndex, count
NSNotificationCenter, NSNotification, NSOperationQueue defaultCenter, addObserverForName:object:queue:usingBlock: (PHP callable), removeObserver:, postNotificationName:object:; name, object, userInfo; mainQueue, init, waitUntilAllOperationsAreFinished. Constants NSViewFrameDidChangeNotification, NSViewBoundsDidChangeNotification, NSWindowDidResizeNotification, NSApplicationDidResignActiveNotification
NSURL fileURLWithPath:, URLWithString:, path, absoluteString
NSMenu initWithTitle:, title, setTitle:, addItem:, insertItem:atIndex:, removeItem:, removeAllItems, numberOfItems, itemAtIndex:, indexOfItem:, autoenablesItems, setAutoenablesItems:, update, performActionForItemAtIndex:, performKeyEquivalent:, popUpMenuPositioningItem:atLocation:inView:, cancelTracking
NSMenuItem initWithTitle:action:keyEquivalent:, separatorItem, title/setTitle:, isSeparatorItem, hasSubmenu, submenu/setSubmenu:, menu, target/setTarget:, action/setAction:, state/setState:, isEnabled/setEnabled:, keyEquivalent/setKeyEquivalent:, keyEquivalentModifierMask/setKeyEquivalentModifierMask:, tag/setTag:
NSRect, NSSize, NSPoint, NSEdgeInsets, NSRange, CFRange value classes; every field is a required constructor argument
NSColorSpace, NSWindow colour space initWithCGColorSpace:, sRGBColorSpace, displayP3ColorSpace, localizedName; NSWindow::colorSpace / setColorSpace: (null = the screen's)
NSOpenGLPixelFormat, NSOpenGLContext, NSOpenGLView, ObjCOpenGLView initWithAttributes: (a list ending on an attribute that takes a value, with none after it, is a ValueError: AppKit would read past it); initWithFormat:shareContext:, makeCurrentContext, clearCurrentContext, currentContext, CGLContextObj, flushBuffer, update, view/setView:; initWithFrame:pixelFormat:, openGLContext/setOpenGLContext:, pixelFormat, wantsBestResolutionOpenGLSurface (+set); NSOpenGLPFAColorFloat; on any NSView: wantsBestResolutionOpenGLSurface, wantsExtendedDynamicRangeOpenGLSurface (+set); trampoline: an NSOpenGLView whose drawRect: calls PHP with the view and the dirty rect (the handler makes the context current and flushes); context setValues:forParameter: / getValues:forParameter: (NSOpenGLContextParameter, ≤ 4 ints; SWAP_INTERVAL 0/1 = vsync off/on)
ObjCStageWindow NSWindow subclass: on('canBecomeKeyWindow' | 'canBecomeMainWindow', callable) / off() set the PHP handler each override asks; without one it answers NSWindow's own (NO for a borderless window); made with the inherited initWithContentRectStyleMaskBackingDefer()
ObjCFocusView NSView subclass conforming to NSTextInputClient: on(selector, callable) / off() set the PHP handler an override asks: acceptsFirstResponder (no handler = NSView's own, NO); keyDown:, keyUp:, flagsChanged: with the NSEvent; insertText:replacementRange: with the text; doCommandBySelector: with the selector's name; for those five, false or no handler = NSView's own; cut:, copy:, paste:, selectAll:, undo:, redo: with the sender, false or no handler = the next responder, and respondsToSelector: answers each only while its handler is set. The marked text of a dead key stays in the glue; PHP sees only what interpretKeyEvents() commits. Made with the inherited initWithFrame()
ObjCKeyWindow NSWindow subclass: on('keyDown:', callable) / off(); keyDown: hands PHP the NSEvent, and passes it on to NSWindow's own keyDown: (Tab walks the key-view loop) when no handler ran or it returned false; made with the inherited initWithContentRectStyleMaskBackingDefer()
ObjCDrawView trampoline: static initWithFrameDraw(NSRect, callable); drawRect: calls PHP with (view, NSRect dirty) inside the view's graphics context: mark rects with setNeedsDisplayInRect: and AppKit asks for only those (partial redraw)
NSGraphicsContext, CGContext currentContext, CGContext; CGContextSaveGState / RestoreGState / ClipToRect / TranslateCTM / ScaleCTM / SetInterpolationQuality / GetInterpolationQuality (CGInterpolationQuality, NONE = nearest) / DrawImage
NSScreen mainScreen, screens (menu-bar screen first), frame, visibleFrame, backingScaleFactor, maximumFramesPerSecond, localizedName, deviceDescription (array: NSScreenNumber = CGDirectDisplayID, NSDeviceSize/NSDeviceResolution as NSSize), maximumExtendedDynamicRangeColorComponentValue, maximumPotentialExtendedDynamicRangeColorComponentValue
CGDisplay, CGDisplayMode static CGMainDisplayID, CGGetActiveDisplayList ($activeDisplays and $displayCount by reference), CGDisplayBounds, CGDisplayCopyDisplayMode, CGDisplayCopyAllDisplayModes (options array, kCGDisplayShowDuplicateLowResolutionModes lists the HiDPI modes), CGDisplaySetDisplayMode (mode and options nullable), CGDisplayCapture, CGDisplayRelease, CGShieldingWindowLevel (a display named by its int id; the CGError functions return the CGError, compared with kCGError*); mode GetWidth/GetHeight/GetPixelWidth/GetPixelHeight/GetRefreshRate/IsUsableForDesktopGUI
CADisplayLink, CAFrameRateRange, NSRunLoop link timestamp, targetTimestamp, duration, preferredFrameRateRange (+set), addToRunLoop:forMode:, removeFromRunLoop:forMode:, isPaused/setPaused:, invalidate (macOS 14+); range value class (minimum, maximum, preferred); mainRunLoop, currentRunLoop, getCFRunLoop
NSProcessInfo, IOPMAssertion processInfo, beginActivityWithOptions:reason: (NSActivityOptions, returns the token), endActivity:; static IOPMAssertionCreateWithName (returns the IOReturn, the IOPMAssertionID by reference), IOPMAssertionRelease (returns the IOReturn); compare with kIOReturnSuccess
CFData, CGDataProvider, CGColorSpace, CGColor, CGImage CFDataCreate (allocator or null, a string or an address, the byte count; copies; a count past the string or a null address with a count above 0 is a ValueError: Core Foundation would read past it), CFDataCreateMutable (allocator or null, a capacity; 0 lets it grow), CFDataSetLength (new bytes are zero), CFDataGetMutableBytePtr (the address of the bytes, as an int), CFDataGetBytes (a CFRange, and a by-reference string the range is copied into; the range must lie within the length: Core Foundation aborts on one past it), GetLength, CGDataProviderCreateWithCFData, CGColorSpaceCreateWithName, CGColor (a CGColorRef, from NSColor::CGColor() and CALayer::backgroundColor()); CGImageCreate (nullable space and provider, an optional decode list of two floats per colour component, fewer is a ValueError), GetWidth, GetHeight; CGDataProviderCreateDirect (createDirect(address, size): reads the memory in place, no copy, caller keeps it alive; null for a size below 1); CGImage::create answers null for any description Core Graphics refuses, a provider shorter than it included (the last row needs only its pixels); CGImageCreateWithImageInRect (null when they do not meet)
ObjCDelegate, ObjCTarget, ObjCObserver trampolines: an object answering a protocol's selectors by calling PHP (struct arguments as their value classes, a char as int; returns written back by the selector's type: objects, numbers, NSRect/NSSize/NSPoint/NSRange/NSEdgeInsets, a selector or class name, an address), a target whose action: calls PHP, and a KVO observer (observe/stop with options, OPTION_*, and context) handing (keyPath, object, change, context) to PHP with KVO's whole change dictionary
NSEvent otherEventWithType:…data2:, mouseEventWithType:…pressure:, type, buttonNumber, subtype, modifierFlags, timestamp, windowNumber, locationInWindow, data1, data2, keyEventWithType:…keyCode:, eventWithCGEvent:, static mouseLocation, static pressedMouseButtons, static addLocalMonitorForEventsMatchingMask:handler: (AppKit gets the NSEvent the handler returns, nil for null; any other return hands AppKit its own event) / removeMonitor: (a second removal of one monitor, which crashes AppKit, is a ValueError), keyCode, characters/charactersIgnoringModifiers (key events only), isARepeat, clickCount, deltaX/deltaY, scrollingDeltaX/scrollingDeltaY, hasPreciseScrollingDeltas, isDirectionInvertedFromDevice, window
CGEvent, CGEventSource CGEventCreateMouseEvent, CGEventCreateScrollWheelEvent2, CGEventCreateKeyboardEvent (each takes a ?CGEventSource first), Get/SetFlags, Get/SetIntegerValueField, Get/SetLocation; enums CGEventType, CGMouseButton, CGScrollEventUnit, constants kCGMouseEvent*. The NSEvents AppKit cannot construct (scroll, other buttons), via NSEvent::eventWithCGEvent(). CGEventSource::create (CGEventSourceCreate), CGEventSource::keyState (CGEventSourceKeyState, enum CGEventSourceStateID)
GCController and its profiles and elements (GameController.framework) controllers, startWirelessControllerDiscoveryWithCompletionHandler:, stopWirelessControllerDiscovery, shouldMonitorBackgroundEvents (+set), vendorName, extendedGamepad, microGamepad, playerIndex (+set, GCControllerPlayerIndex); extended and micro gamepads, buttons, axes, direction pads; GCControllerDidConnectNotification, GCControllerDidDisconnectNotification
NSDate date, dateWithTimeIntervalSinceNow:, dateWithTimeIntervalSince1970:, distantPast, distantFuture, timeIntervalSinceNow, timeIntervalSince1970
CFRunLoop, CFRunLoopSource CFRunLoopGetMain/GetCurrent/Run/RunInMode/Stop/WakeUp/IsWaiting/CopyCurrentMode/AddSource/RemoveSource/ContainsSource, CFRunLoopSourceGetOrder/Invalidate/IsValid/Signal
CFFileDescriptor Create (allocator or null, fd as int, PHP callable callout), GetNativeDescriptor, EnableCallBacks, DisableCallBacks, Invalidate, IsValid, CreateRunLoopSource (allocator or null, order)
CFType, CFAllocator CFGetTypeID, CFHash, CFCopyDescription (copyDescription()), pointer(); CFAllocatorGetDefault (every allocator parameter takes it or null)
NSError domain, code, localizedDescription, userInfo
AppKitException extends RuntimeException: an NSException AppKit raised during the call, as "<name>: <reason>", and the main-thread refusal

A CAMetalLayer made by ext-metal is set as a view's layer through CALayer::fromPointer($layer->pointer()), and comes back from layer() as a CALayer.

Enums: NSApplicationActivationPolicy, NSEventType, NSEventMask, NSEventModifierFlags, CFRunLoopRunResult, NSWindowStyleMask, NSBackingStoreType, NSWindowCollectionBehavior, NSWindowTitleVisibility, NSWindowOcclusionState, NSViewLayerContentsRedrawPolicy, NSOpenGLContextParameter, CGInterpolationQuality, NSActivityOptions, NSControlStateValue, NSUserInterfaceLayoutOrientation, NSLayoutConstraintOrientation, NSStackViewGravity, NSLayoutAttribute, NSStackViewDistribution, NSGridCellPlacement, NSTextAlignment (values from the SDK: arm64 and x86_64 differ), NSLineBreakMode, NSButtonType, NSDatePickerStyle, NSDatePickerMode, NSProgressIndicatorStyle, NSImageScaling, NSBoxType, NSTextBlockValueType, NSTextBlockDimension, NSSplitViewDividerStyle. Constants: run-loop modes, kCFFileDescriptor*CallBack, NSTextAlignment*, NSCarriageReturnCharacter, NSEnterCharacter, NSBackspaceCharacter, NSTabCharacter, NS{Up,Down,Left,Right}ArrowFunctionKey, NSF1FunctionKey … NSF12FunctionKey, NS{Delete,Home,End,PageUp,PageDown}FunctionKey, NSForegroundColorAttributeName, NSBackgroundColorAttributeName, NSViewBoundsDidChangeNotification, NSSplitViewDidResizeSubviewsNotification, kCAGravity*, kCGImageAlpha*, kCGBitmapByteOrder*, kCGRenderingIntentDefault, kCGColorSpaceSRGB, kCGError*, kIOReturnSuccess, NS{Normal,Floating,Submenu,TornOffMenu,MainMenu,Status,ModalPanel,PopUpMenu,ScreenSaver}WindowLevel, kCGDisplayShowDuplicateLowResolutionModes, kIOPMAssertionType{PreventUserIdleSystemSleep,PreventUserIdleDisplaySleep,PreventSystemSleep}, kIOPMAssertionLevel{Off,On}, NSControlTextDidChangeNotification, NSTextDidChangeNotification, NSAlertFirstButtonReturn, NSModalResponseOK, NSModalResponseCancel, NSPasteboardTypeString, the notification names above. The stubs in stubs/ are the full declaration; every enum's values are _Static_assert-checked against the SDK.

Names

Selectors become methods by joining their parts: nextEventMatchingMask:untilDate:inMode:dequeue: is nextEventMatchingMaskUntilDateInModeDequeue().

Static constructors and instancetype factories build the class they are called on: NSTextField::initWithFrame() is [[NSTextField alloc] initWithFrame:].

Callbacks and threads

A PHP callable handed to native code (delegate, target, observer, notification block, file-descriptor callout) only ever runs on the PHP thread that handed it over; a native call on any other thread does not enter PHP. Route notifications that may be posted elsewhere (AVFoundation's) through NSOperationQueue::mainQueue().

The AppKit UI classes (NSApplication, NSWindow, NSView and its subclasses, NSMenu, NSMenuItem, NSScreen, the NSEvent monitors, the layout anchors, CADisplayLink) throw AppKitException when called off the main thread: AppKit traps the process there. Every other class runs on whichever thread calls it.

Errors

Results are AppKit's own: nil is null, CGError and IOReturn codes are returned as int (compare with kCGErrorSuccess / kIOReturnSuccess), C out-parameters are by-reference arguments, and an NSException AppKit raises arrives as AppKitException. The extension declines a call only where a probe shows the call would crash the process or use memory it does not own: the main-thread gate above, the CFData byte-count and null-address checks, a CGImage decode list too short for its colour space, a pixel-format attribute missing its value, a colour attribute that is no NSColor, a second glue constructor call, and a second removeMonitor:.

Coverage

SUPPORT.md lists every method and property accessor that the SDK's AppKit headers declare and do not mark deprecated or unavailable on macOS, each marked bound or not; the API badge is computed from it. Regenerate both after a binding change, and check them:

php84 scripts/support.php           # writes SUPPORT.md and the badge
php84 scripts/support.php --check   # exits 1 when either is stale

Running the test suite

composer install
XDEBUG_MODE=off php -d memory_limit=128M vendor/bin/pest   # tests/Probes skip: they need a build configured with --enable-appkit-probes
php examples/smoke.php                                     # bridge: Dock icon, pump, sleep, wake; prints SMOKE_OK
php examples/window-smoke.php                              # window, menu bar, target/action, delegate close; prints SMOKE_OK

Tests open windows: run them in a logged-in GUI session.

Each kept refusal has a probe in tests/Probes that shows the crash it prevents. They run against a probe build, configured with --enable-appkit-probes in a scratch copy and never installed; in that build APPKIT_PROBE_OFF=<site id> turns one site's check off:

P=$(mktemp -d)/appkit && rsync -a --exclude vendor --exclude .git ./ "$P"/
(cd "$P" && phpize && ./configure --enable-appkit --enable-appkit-probes && make)
APPKIT_PROBE_EXT="$P/modules/appkit.so" php -n -d memory_limit=128M \
    -d extension="$P/modules/appkit.so" vendor/bin/pest tests/Probes

The main-thread probe needs a ZTS PHP with ext-parallel.

Design notes live in the OKF bundle under .okf/.

License

MIT. See LICENSE. AppKit and the other frameworks are part of macOS; they are linked, not shipped.