1. Go to this page and download the library: Download php-io-extensions/appkit library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
php-io-extensions / appkit example snippets
$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
$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
bash
bash install-macos.sh # Homebrew [email protected] and [email protected]
bash install-macos.sh /path/to/php ... # specific PHP binaries
bash
composer install
php 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
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.