repo
stringlengths
7
63
file_url
stringlengths
81
284
file_path
stringlengths
5
200
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:02:33
2026-01-05 05:24:06
truncated
bool
2 classes
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version08/TestCase/WithBeforeClassAnnotation/SleeperTest.php
test/EndToEnd/Version08/TestCase/WithBeforeClassAnnotation/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version08\TestCase\WithBeforeClassAnnotation; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; /** * @covers \Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\Sleeper */ final class SleeperTest extends Framework\TestCase { /** * @beforeClass */ public static function sleepWithBeforeClassAnnotation(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @dataProvider provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration */ public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void { $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @return \Generator<int, array{0: int}> */ public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable { $values = \range( 200, 300, 100 ); foreach ($values as $value) { yield $value => [ $value, ]; } } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version08/TestCase/WithBeforeAnnotation/SleeperTest.php
test/EndToEnd/Version08/TestCase/WithBeforeAnnotation/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version08\TestCase\WithBeforeAnnotation; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; /** * @covers \Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\Sleeper */ final class SleeperTest extends Framework\TestCase { /** * @before */ public function sleepWithBeforeAnnotation(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @dataProvider provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration */ public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void { $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @return \Generator<int, array{0: int}> */ public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable { $values = \range( 200, 300, 100 ); foreach ($values as $value) { yield $value => [ $value, ]; } } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version08/TestCase/WithSetUpBeforeClass/SleeperTest.php
test/EndToEnd/Version08/TestCase/WithSetUpBeforeClass/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version08\TestCase\WithSetUpBeforeClass; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; /** * @covers \Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\Sleeper */ final class SleeperTest extends Framework\TestCase { public static function setUpBeforeClass(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @dataProvider provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration */ public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void { $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @return \Generator<int, array{0: int}> */ public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable { $values = \range( 200, 300, 100 ); foreach ($values as $value) { yield $value => [ $value, ]; } } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version08/TestCase/WithAssertPostConditions/SleeperTest.php
test/EndToEnd/Version08/TestCase/WithAssertPostConditions/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version08\TestCase\WithAssertPostConditions; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; /** * @covers \Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\Sleeper */ final class SleeperTest extends Framework\TestCase { protected function assertPostConditions(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @dataProvider provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration */ public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void { $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @return \Generator<int, array{0: int}> */ public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable { $values = \range( 200, 300, 100 ); foreach ($values as $value) { yield $value => [ $value, ]; } } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version08/TestCase/WithAssertPreConditions/SleeperTest.php
test/EndToEnd/Version08/TestCase/WithAssertPreConditions/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version08\TestCase\WithAssertPreConditions; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; /** * @covers \Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\Sleeper */ final class SleeperTest extends Framework\TestCase { protected function assertPreConditions(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @dataProvider provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration */ public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void { $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @return \Generator<int, array{0: int}> */ public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable { $values = \range( 200, 300, 100 ); foreach ($values as $value) { yield $value => [ $value, ]; } } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version08/TestCase/Bare/SleeperTest.php
test/EndToEnd/Version08/TestCase/Bare/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version08\TestCase\Bare; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; /** * @covers \Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\Sleeper */ final class SleeperTest extends Framework\TestCase { public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @dataProvider provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration */ public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void { $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @return \Generator<int, array{0: int}> */ public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable { $values = \range( 200, 300, 100 ); foreach ($values as $value) { yield $value => [ $value, ]; } } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version08/TestCase/WithTearDown/SleeperTest.php
test/EndToEnd/Version08/TestCase/WithTearDown/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version08\TestCase\WithTearDown; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; /** * @covers \Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\Sleeper */ final class SleeperTest extends Framework\TestCase { protected function tearDown(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @dataProvider provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration */ public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void { $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @return \Generator<int, array{0: int}> */ public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable { $values = \range( 200, 300, 100 ); foreach ($values as $value) { yield $value => [ $value, ]; } } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version08/TestCase/WithAfterClassAnnotation/SleeperTest.php
test/EndToEnd/Version08/TestCase/WithAfterClassAnnotation/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version08\TestCase\WithAfterClassAnnotation; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; /** * @covers \Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\Sleeper */ final class SleeperTest extends Framework\TestCase { /** * @afterClass */ public static function sleepWithAfterClassAnnotation(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @dataProvider provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration */ public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void { $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @return \Generator<int, array{0: int}> */ public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable { $values = \range( 200, 300, 100 ); foreach ($values as $value) { yield $value => [ $value, ]; } } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version08/TestMethod/WithMaximumDurationAnnotation/SleeperTest.php
test/EndToEnd/Version08/TestMethod/WithMaximumDurationAnnotation/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version08\TestMethod\WithMaximumDurationAnnotation; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; /** * @covers \Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\Sleeper */ final class SleeperTest extends Framework\TestCase { /** * @maximumDuration 3.14 */ public function testSleeperSleepsShorterThanMaximumDurationFromXmlConfigurationWhenTestMethodHasInvalidMaximumDurationAnnotation(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @maximumDuration 3.14 */ public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWhenTestMethodHasInvalidMaximumDurationAnnotation(): void { $milliseconds = 200; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @maximumDuration 200 */ public function testSleeperSleepsShorterThanMaximumDurationFromAnnotationWhenTestMethodHasValidMaximumDurationAnnotation(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @dataProvider provideDataWhereDataNameIsInteger * * @maximumDuration 200 */ public function testSleeperSleepsShorterThanMaximumDurationFromAnnotationWithNumericDataProvider(): void { $milliseconds = 150; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @return list<array{0: string}> */ public static function provideDataWhereDataNameIsInteger(): array { return [ [ 'bar', ], ]; } /** * @dataProvider provideDataWhereDataNameIsString * * @maximumDuration 200 */ public function testSleeperSleepsShorterThanMaximumDurationFromAnnotationWithNamedDataProvider(): void { $milliseconds = 150; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @return array<string, array{0: string}> */ public static function provideDataWhereDataNameIsString(): array { return [ 'foo' => [ 'bar', ], ]; } /** * @maximumDuration 200 */ public function testSleeperSleepsLongerThanMaximumDurationFromAnnotationWhenTestMethodHasValidMaximumDurationAnnotation(): void { $milliseconds = 300; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version08/TestMethod/WithSlowThresholdAndMaximumDurationAnnotations/SleeperTest.php
test/EndToEnd/Version08/TestMethod/WithSlowThresholdAndMaximumDurationAnnotations/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version08\TestMethod\WithSlowThresholdAndMaximumDurationAnnotations; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; /** * @covers \Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\Sleeper */ final class SleeperTest extends Framework\TestCase { /** * @slowThreshold 400 * * @maximumDuration 200 */ public function testSleeperSleepsShorterThanMaximumDurationFromAnnotationWhenTestMethodHasMaximumDurationAndSlowThresholdAnnotations(): void { $milliseconds = 50; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @slowThreshold 400 * * @maximumDuration 200 */ public function testSleeperSleepsLongerThanMaximumDurationFromAnnotationWhenTestMethodHasMaximumDurationAndSlowThresholdAnnotations(): void { $milliseconds = 300; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version08/TestMethod/WithSlowThresholdAnnotation/SleeperTest.php
test/EndToEnd/Version08/TestMethod/WithSlowThresholdAnnotation/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version08\TestMethod\WithSlowThresholdAnnotation; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; /** * @covers \Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\Sleeper */ final class SleeperTest extends Framework\TestCase { /** * @slowThreshold 3.14 * * @see https://github.com/johnkary/phpunit-speedtrap/blob/1.0/src/JohnKary/PHPUnit/Listener/SpeedTrapListener.php#L309-L331 */ public function testSleeperSleepsShorterThanMaximumDurationFromXmlConfigurationWhenTestMethodHasInvalidSlowThresholdAnnotation(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @slowThreshold 3.14 * * @see https://github.com/johnkary/phpunit-speedtrap/blob/1.0/src/JohnKary/PHPUnit/Listener/SpeedTrapListener.php#L309-L331 */ public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWhenTestMethodHasInvalidSlowThresholdAnnotation(): void { $milliseconds = 200; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @slowThreshold 200 * * @see https://github.com/johnkary/phpunit-speedtrap/blob/1.0/src/JohnKary/PHPUnit/Listener/SpeedTrapListener.php#L309-L331 */ public function testSleeperSleepsShorterThanSlowThresholdFromAnnotationWhenTestMethodHasValidSlowThresholdAnnotation(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @slowThreshold 200 * * @see https://github.com/johnkary/phpunit-speedtrap/blob/1.0/src/JohnKary/PHPUnit/Listener/SpeedTrapListener.php#L309-L331 */ public function testSleeperSleepsLongerThanSlowThresholdFromAnnotationWhenTestMethodHasValidSlowThresholdAnnotation(): void { $milliseconds = 300; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version08/TestMethod/WithMaximumDurationAndSlowThresholdAnnotations/SleeperTest.php
test/EndToEnd/Version08/TestMethod/WithMaximumDurationAndSlowThresholdAnnotations/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version08\TestMethod\WithMaximumDurationAndSlowThresholdAnnotations; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; /** * @covers \Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\Sleeper */ final class SleeperTest extends Framework\TestCase { /** * @maximumDuration 200 * * @slowThreshold 400 */ public function testSleeperSleepsShorterThanMaximumDurationFromAnnotationWhenTestMethodHasMaximumDurationAndSlowThresholdAnnotations(): void { $milliseconds = 50; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @maximumDuration 200 * * @slowThreshold 400 */ public function testSleeperSleepsLongerThanMaximumDurationFromAnnotationWhenTestMethodHasMaximumDurationAndSlowThresholdAnnotations(): void { $milliseconds = 300; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version08/TestMethod/WithRunInSeparateProcessAnnotation/SleeperTest.php
test/EndToEnd/Version08/TestMethod/WithRunInSeparateProcessAnnotation/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version08\TestMethod\WithRunInSeparateProcessAnnotation; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; /** * @covers \Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\Sleeper */ final class SleeperTest extends Framework\TestCase { public static function setUpBeforeClass(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } public static function tearDownAfterClass(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } protected function setUp(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } protected function assertPreConditions(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } protected function assertPostConditions(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } protected function tearDown(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } /** * @before */ public function sleepWithBeforeAnnotation(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } /** * @beforeClass */ public static function sleepWithBeforeClassAnnotation(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } /** * @after */ public function sleepWithAfterAnnotation(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } /** * @afterClass */ public static function sleepWithAfterClassAnnotation(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } public function testSleeperSleepsShorterThanMaximumDurationFromXmlConfiguration(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @runInSeparateProcess */ public function testSleeperSleepsShorterThanMaximumDurationFromXmlConfigurationWhenMethodHasRunInSeparateProcessAnnotation(): void { $milliseconds = 50; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfiguration(): void { $milliseconds = 200; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @runInSeparateProcess */ public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWhenMethodHasRunInSeparateProcessAnnotation(): void { $milliseconds = 300; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version12/Configuration/Defaults/SleeperTest.php
test/EndToEnd/Version12/Configuration/Defaults/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\Configuration\Defaults; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Test\Fixture\Sleeper::class)] final class SleeperTest extends Framework\TestCase { public function testSleeperSleepsLessThanDefaultMaximumDuration(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } #[Framework\Attributes\DataProvider('provideMillisecondsGreaterThanDefaultMaximumDuration')] public function testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider(int $milliseconds): void { $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @return \Generator<int, array{0: int}> */ public static function provideMillisecondsGreaterThanDefaultMaximumDuration(): iterable { $values = \range( 600, 1600, 100 ); foreach ($values as $value) { yield $value => [ $value, ]; } } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version12/Configuration/MaximumDuration/SleeperTest.php
test/EndToEnd/Version12/Configuration/MaximumDuration/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\Configuration\MaximumDuration; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Test\Fixture\Sleeper::class)] final class SleeperTest extends Framework\TestCase { public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } #[Framework\Attributes\DataProvider('provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration')] public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void { $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @return \Generator<int, array{0: int}> */ public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable { $values = \range( 200, 1200, 100 ); foreach ($values as $value) { yield $value => [ $value, ]; } } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version12/Configuration/MaximumCount/SleeperTest.php
test/EndToEnd/Version12/Configuration/MaximumCount/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\Configuration\MaximumCount; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Test\Fixture\Sleeper::class)] final class SleeperTest extends Framework\TestCase { public function testSleeperSleepsLessThanDefaultMaximumDuration(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } #[Framework\Attributes\DataProvider('provideMillisecondsGreaterThanDefaultMaximumDuration')] public function testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider(int $milliseconds): void { $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @return \Generator<int, array{0: int}> */ public static function provideMillisecondsGreaterThanDefaultMaximumDuration(): iterable { $values = \range( 600, 1000, 100 ); foreach ($values as $value) { yield $value => [ $value, ]; } } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version12/Option/NoOutput/SleeperTest.php
test/EndToEnd/Version12/Option/NoOutput/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\Option\NoOutput; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Test\Fixture\Sleeper::class)] final class SleeperTest extends Framework\TestCase { public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfiguration(): void { $milliseconds = 200; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version12/TestCase/WithSetUp/SleeperTest.php
test/EndToEnd/Version12/TestCase/WithSetUp/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\TestCase\WithSetUp; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Test\Fixture\Sleeper::class)] final class SleeperTest extends Framework\TestCase { protected function setUp(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } #[Framework\Attributes\DataProvider('provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration')] public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void { $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @return \Generator<int, array{0: int}> */ public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable { $values = \range( 200, 300, 100 ); foreach ($values as $value) { yield $value => [ $value, ]; } } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version12/TestCase/WithTearDownAfterClass/SleeperTest.php
test/EndToEnd/Version12/TestCase/WithTearDownAfterClass/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\TestCase\WithTearDownAfterClass; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Test\Fixture\Sleeper::class)] final class SleeperTest extends Framework\TestCase { public static function tearDownAfterClass(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } #[Framework\Attributes\DataProvider('provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration')] public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void { $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @return \Generator<int, array{0: int}> */ public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable { $values = \range( 200, 300, 100 ); foreach ($values as $value) { yield $value => [ $value, ]; } } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version12/TestCase/Combination/SleeperTest.php
test/EndToEnd/Version12/TestCase/Combination/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\TestCase\Combination; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Test\Fixture\Sleeper::class)] final class SleeperTest extends Framework\TestCase { public static function setUpBeforeClass(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } public static function tearDownAfterClass(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } protected function setUp(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } protected function assertPreConditions(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } protected function assertPostConditions(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } protected function tearDown(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } #[Framework\Attributes\Before] public function sleepWithBeforeAttribute(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } #[Framework\Attributes\BeforeClass] public static function sleepWithBeforeClassAttribute(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } #[Framework\Attributes\After] public function sleepWithAfterAttribute(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } #[Framework\Attributes\AfterClass] public static function sleepWithAfterClassAttribute(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } #[Framework\Attributes\DataProvider('provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration')] public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void { $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @return \Generator<int, array{0: int}> */ public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable { $values = \range( 200, 300, 100 ); foreach ($values as $value) { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); yield $value => [ $value, ]; } } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version12/TestCase/WithBeforeAttribute/SleeperTest.php
test/EndToEnd/Version12/TestCase/WithBeforeAttribute/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\TestCase\WithBeforeAttribute; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Test\Fixture\Sleeper::class)] final class SleeperTest extends Framework\TestCase { #[Framework\Attributes\Before] public function sleepWithBeforeAttribute(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } #[Framework\Attributes\DataProvider('provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration')] public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void { $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @return \Generator<int, array{0: int}> */ public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable { $values = \range( 200, 300, 100 ); foreach ($values as $value) { yield $value => [ $value, ]; } } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version12/TestCase/WithDataProvider/SleeperTest.php
test/EndToEnd/Version12/TestCase/WithDataProvider/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\TestCase\WithDataProvider; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Test\Fixture\Sleeper::class)] final class SleeperTest extends Framework\TestCase { public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } #[Framework\Attributes\DataProvider('provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration')] public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void { $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @return \Generator<int, array{0: int}> */ public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable { $values = \range( 200, 300, 100 ); foreach ($values as $value) { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); yield $value => [ $value, ]; } } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version12/TestCase/WithAfterAttribute/SleeperTest.php
test/EndToEnd/Version12/TestCase/WithAfterAttribute/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\TestCase\WithAfterAttribute; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Test\Fixture\Sleeper::class)] final class SleeperTest extends Framework\TestCase { #[Framework\Attributes\After] public function sleepWithAfterAttribute(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } #[Framework\Attributes\DataProvider('provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration')] public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void { $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @return \Generator<int, array{0: int}> */ public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable { $values = \range( 200, 300, 100 ); foreach ($values as $value) { yield $value => [ $value, ]; } } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version12/TestCase/WithSetUpBeforeClass/SleeperTest.php
test/EndToEnd/Version12/TestCase/WithSetUpBeforeClass/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\TestCase\WithSetUpBeforeClass; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Test\Fixture\Sleeper::class)] final class SleeperTest extends Framework\TestCase { public static function setUpBeforeClass(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } #[Framework\Attributes\DataProvider('provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration')] public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void { $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @return \Generator<int, array{0: int}> */ public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable { $values = \range( 200, 300, 100 ); foreach ($values as $value) { yield $value => [ $value, ]; } } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version12/TestCase/WithAssertPostConditions/SleeperTest.php
test/EndToEnd/Version12/TestCase/WithAssertPostConditions/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\TestCase\WithAssertPostConditions; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Test\Fixture\Sleeper::class)] final class SleeperTest extends Framework\TestCase { protected function assertPostConditions(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } #[Framework\Attributes\DataProvider('provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration')] public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void { $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @return \Generator<int, array{0: int}> */ public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable { $values = \range( 200, 300, 100 ); foreach ($values as $value) { yield $value => [ $value, ]; } } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version12/TestCase/WithBeforeClassAttribute/SleeperTest.php
test/EndToEnd/Version12/TestCase/WithBeforeClassAttribute/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\TestCase\WithBeforeClassAttribute; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Test\Fixture\Sleeper::class)] final class SleeperTest extends Framework\TestCase { #[Framework\Attributes\BeforeClass] public static function sleepWithBeforeClassAttribute(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } #[Framework\Attributes\DataProvider('provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration')] public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void { $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @return \Generator<int, array{0: int}> */ public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable { $values = \range( 200, 300, 100 ); foreach ($values as $value) { yield $value => [ $value, ]; } } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version12/TestCase/WithAssertPreConditions/SleeperTest.php
test/EndToEnd/Version12/TestCase/WithAssertPreConditions/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\TestCase\WithAssertPreConditions; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Test\Fixture\Sleeper::class)] final class SleeperTest extends Framework\TestCase { protected function assertPreConditions(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } #[Framework\Attributes\DataProvider('provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration')] public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void { $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @return \Generator<int, array{0: int}> */ public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable { $values = \range( 200, 300, 100 ); foreach ($values as $value) { yield $value => [ $value, ]; } } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version12/TestCase/Bare/SleeperTest.php
test/EndToEnd/Version12/TestCase/Bare/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\TestCase\Bare; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Test\Fixture\Sleeper::class)] final class SleeperTest extends Framework\TestCase { public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } #[Framework\Attributes\DataProvider('provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration')] public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void { $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @return \Generator<int, array{0: int}> */ public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable { $values = \range( 200, 300, 100 ); foreach ($values as $value) { yield $value => [ $value, ]; } } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version12/TestCase/WithAfterClassAttribute/SleeperTest.php
test/EndToEnd/Version12/TestCase/WithAfterClassAttribute/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\TestCase\WithAfterClassAttribute; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Test\Fixture\Sleeper::class)] final class SleeperTest extends Framework\TestCase { #[Framework\Attributes\AfterClass] public static function sleepWithAfterClassAttribute(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } #[Framework\Attributes\DataProvider('provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration')] public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void { $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @return \Generator<int, array{0: int}> */ public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable { $values = \range( 200, 300, 100 ); foreach ($values as $value) { yield $value => [ $value, ]; } } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version12/TestCase/WithTearDown/SleeperTest.php
test/EndToEnd/Version12/TestCase/WithTearDown/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\TestCase\WithTearDown; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Test\Fixture\Sleeper::class)] final class SleeperTest extends Framework\TestCase { protected function tearDown(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } public function testSleeperSleepsLessThanMaximumDurationFromXmlConfiguration(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } #[Framework\Attributes\DataProvider('provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration')] public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWithDataProvider(int $milliseconds): void { $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } /** * @return \Generator<int, array{0: int}> */ public static function provideMillisecondsGreaterThanMaximumDurationFromXmlConfiguration(): iterable { $values = \range( 200, 300, 100 ); foreach ($values as $value) { yield $value => [ $value, ]; } } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version12/TestMethod/WithMaximumDurationAttribute/SleeperTest.php
test/EndToEnd/Version12/TestMethod/WithMaximumDurationAttribute/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\TestMethod\WithMaximumDurationAttribute; use Ergebnis\PHPUnit\SlowTestDetector\Attribute; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Test\Fixture\Sleeper::class)] final class SleeperTest extends Framework\TestCase { #[Attribute\MaximumDuration(200)] public function testSleeperSleepsShorterThanMaximumDurationFromAttributeWhenTestMethodHasValidMaximumDurationAttribute(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } #[Attribute\MaximumDuration(200)] public function testSleeperSleepsLongerThanMaximumDurationFromAttributeWhenTestMethodHasValidMaximumDurationAttribute(): void { $milliseconds = 300; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/EndToEnd/Version12/TestMethod/WithRunInSeparateProcessAttribute/SleeperTest.php
test/EndToEnd/Version12/TestMethod/WithRunInSeparateProcessAttribute/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version12\TestMethod\WithRunInSeparateProcessAttribute; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Test\Fixture\Sleeper::class)] final class SleeperTest extends Framework\TestCase { public static function setUpBeforeClass(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } public static function tearDownAfterClass(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } protected function setUp(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } protected function assertPreConditions(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } protected function assertPostConditions(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } protected function tearDown(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } #[Framework\Attributes\Before] public function sleepWithBeforeAttribute(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } #[Framework\Attributes\BeforeClass] public static function sleepWithBeforeClassAttribute(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } #[Framework\Attributes\After] public function sleepWithAfterAttribute(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } #[Framework\Attributes\AfterClass] public static function sleepWithAfterClassAttribute(): void { Test\Fixture\Sleeper::fromMilliseconds(100)->sleep(); } public function testSleeperSleepsShorterThanMaximumDurationFromXmlConfiguration(): void { $milliseconds = 50; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } #[Framework\Attributes\RunInSeparateProcess] public function testSleeperSleepsShorterThanMaximumDurationFromXmlConfigurationWhenMethodHasRunInSeparateProcessAttribute(): void { $milliseconds = 10; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfiguration(): void { $milliseconds = 200; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } #[Framework\Attributes\RunInSeparateProcess] public function testSleeperSleepsLongerThanMaximumDurationFromXmlConfigurationWhenMethodHasRunInSeparateProcessAttribute(): void { $milliseconds = 300; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/Phar/Version09/SleeperTest.php
test/Phar/Version09/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\Phar\Version09; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; /** * @covers \Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\Sleeper */ final class SleeperTest extends Framework\TestCase { public function testSleeperDoesNotSleepAtAll(): void { $milliseconds = 0; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } public function testSleeperSleepsJustAboveDefaultMaximumDuration(): void { $milliseconds = 600; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/Phar/Version09/bootstrap.php
test/Phar/Version09/bootstrap.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ require_once __DIR__ . '/../../Fixture/Sleeper.php';
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/Phar/Version10/SleeperTest.php
test/Phar/Version10/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\Phar\Version10; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Test\Fixture\Sleeper::class)] final class SleeperTest extends Framework\TestCase { public function testSleeperDoesNotSleepAtAll(): void { $milliseconds = 0; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } public function testSleeperSleepsJustAboveDefaultMaximumDuration(): void { $milliseconds = 600; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/Phar/Version10/bootstrap.php
test/Phar/Version10/bootstrap.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ require_once __DIR__ . '/../../Fixture/Sleeper.php';
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/Phar/Version07/SleeperTest.php
test/Phar/Version07/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\Phar\Version07; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; /** * @covers \Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\Sleeper */ final class SleeperTest extends Framework\TestCase { public function testSleeperDoesNotSleepAtAll(): void { $milliseconds = 0; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } public function testSleeperSleepsJustAboveDefaultMaximumDuration(): void { $milliseconds = 600; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/Phar/Version07/bootstrap.php
test/Phar/Version07/bootstrap.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ require_once __DIR__ . '/../../Fixture/Sleeper.php';
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/Phar/Version11/SleeperTest.php
test/Phar/Version11/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\Phar\Version11; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Test\Fixture\Sleeper::class)] final class SleeperTest extends Framework\TestCase { public function testSleeperDoesNotSleepAtAll(): void { $milliseconds = 0; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } public function testSleeperSleepsJustAboveDefaultMaximumDuration(): void { $milliseconds = 600; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/Phar/Version11/bootstrap.php
test/Phar/Version11/bootstrap.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ require_once __DIR__ . '/../../Fixture/Sleeper.php';
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/Phar/Version08/SleeperTest.php
test/Phar/Version08/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\Phar\Version08; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; /** * @covers \Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\Sleeper */ final class SleeperTest extends Framework\TestCase { public function testSleeperDoesNotSleepAtAll(): void { $milliseconds = 0; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } public function testSleeperSleepsJustAboveDefaultMaximumDuration(): void { $milliseconds = 600; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/Phar/Version08/bootstrap.php
test/Phar/Version08/bootstrap.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ require_once __DIR__ . '/../../Fixture/Sleeper.php';
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/Phar/Version12/SleeperTest.php
test/Phar/Version12/SleeperTest.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\Phar\Version12; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Test\Fixture\Sleeper::class)] final class SleeperTest extends Framework\TestCase { public function testSleeperDoesNotSleepAtAll(): void { $milliseconds = 0; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } public function testSleeperSleepsJustAboveDefaultMaximumDuration(): void { $milliseconds = 600; $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); $sleeper->sleep(); self::assertSame($milliseconds, $sleeper->milliseconds()); } }
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/test/Phar/Version12/bootstrap.php
test/Phar/Version12/bootstrap.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ require_once __DIR__ . '/../../Fixture/Sleeper.php';
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/bin/remove-autoload-configuration.php
bin/remove-autoload-configuration.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ $composerJsonFile = __DIR__ . '/../composer.json'; $composerJson = \json_decode( \file_get_contents($composerJsonFile), false ); $composerJson->autoload = new stdClass(); \file_put_contents($composerJsonFile, \json_encode( $composerJson, \JSON_PRETTY_PRINT | \JSON_PRESERVE_ZERO_FRACTION | \JSON_UNESCAPED_SLASHES ));
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
ergebnis/phpunit-slow-test-detector
https://github.com/ergebnis/phpunit-slow-test-detector/blob/d06e5c5f486a899390ad0f0a85ee2104a5ed5326/phar/phpunit-slow-test-detector.php
phar/phpunit-slow-test-detector.php
<?php declare(strict_types=1); /** * Copyright (c) 2021-2026 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. * * @see https://github.com/ergebnis/phpunit-slow-test-detector */ require_once __DIR__ . '/../vendor/autoload.php';
php
MIT
d06e5c5f486a899390ad0f0a85ee2104a5ed5326
2026-01-05T04:38:52.648196Z
false
laravel-notification-channels/facebook-poster
https://github.com/laravel-notification-channels/facebook-poster/blob/c92180c0e8694b5ae8ee4c27e0bc731b48b02ed9/src/FacebookPosterPost.php
src/FacebookPosterPost.php
<?php namespace NotificationChannels\FacebookPoster; class FacebookPosterPost { /** * Create a new post instance. */ public function __construct( public ?string $message = null, public ?string $link = null, public array $params = [] ) { // } /** * Set the post message. */ public function withMessage(?string $message) { $this->message = $message; return $this; } /** * Set ths post link. */ public function withLink(?string $link) { $this->link = $link; return $this; } /** * Set the post params. */ public function withParams(array $params) { $this->params = $params; return $this; } /** * Get the filtered body. */ public function getBody(): array { $body = array_merge([ 'message' => $this->message, 'link' => $this->link, ], $this->params); return array_filter($body); } }
php
MIT
c92180c0e8694b5ae8ee4c27e0bc731b48b02ed9
2026-01-05T04:39:01.841453Z
false
laravel-notification-channels/facebook-poster
https://github.com/laravel-notification-channels/facebook-poster/blob/c92180c0e8694b5ae8ee4c27e0bc731b48b02ed9/src/FacebookPosterChannel.php
src/FacebookPosterChannel.php
<?php namespace NotificationChannels\FacebookPoster; use GuzzleHttp\Client; use Illuminate\Contracts\Config\Repository; use Illuminate\Notifications\Notification; use Illuminate\Support\Arr; class FacebookPosterChannel { /** * Create a new channel instance. */ public function __construct(protected Client $guzzle, protected Repository $config) { // } /** * Send the given notification. */ public function send(mixed $notifiable, Notification $notification): void { $post = $notification->toFacebookPoster($notifiable); $routing = $notifiable->routeNotificationFor('facebookPoster'); $pageId = Arr::get($routing, 'page_id', function () { return $this->config->get('services.facebook_poster.page_id'); }); $accessToken = Arr::get($routing, 'access_token', function () { return $this->config->get('services.facebook_poster.access_token'); }); $this->guzzle->post("https://graph.facebook.com/v18.0/{$pageId}/feed?access_token={$accessToken}", [ 'form_params' => $post->getBody(), ]); } }
php
MIT
c92180c0e8694b5ae8ee4c27e0bc731b48b02ed9
2026-01-05T04:39:01.841453Z
false
laravel-notification-channels/facebook-poster
https://github.com/laravel-notification-channels/facebook-poster/blob/c92180c0e8694b5ae8ee4c27e0bc731b48b02ed9/tests/TestNotifiable.php
tests/TestNotifiable.php
<?php namespace NotificationChannels\FacebookPoster\Tests; use Illuminate\Notifications\Notifiable; class TestNotifiable { use Notifiable; public function routeNotificationForFacebookPoster() { // } }
php
MIT
c92180c0e8694b5ae8ee4c27e0bc731b48b02ed9
2026-01-05T04:39:01.841453Z
false
laravel-notification-channels/facebook-poster
https://github.com/laravel-notification-channels/facebook-poster/blob/c92180c0e8694b5ae8ee4c27e0bc731b48b02ed9/tests/TestCase.php
tests/TestCase.php
<?php namespace NotificationChannels\FacebookPoster\Tests; use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; use PHPUnit\Framework\TestCase as BaseTestCase; class TestCase extends BaseTestCase { use MockeryPHPUnitIntegration; }
php
MIT
c92180c0e8694b5ae8ee4c27e0bc731b48b02ed9
2026-01-05T04:39:01.841453Z
false
laravel-notification-channels/facebook-poster
https://github.com/laravel-notification-channels/facebook-poster/blob/c92180c0e8694b5ae8ee4c27e0bc731b48b02ed9/tests/TestNotifiableWithCustomRouting.php
tests/TestNotifiableWithCustomRouting.php
<?php namespace NotificationChannels\FacebookPoster\Tests; use Illuminate\Notifications\Notifiable; class TestNotifiableWithCustomRouting { use Notifiable; public function routeNotificationForFacebookPoster(): array { return [ 'page_id' => 'customPageId', 'access_token' => 'customAccessToken', ]; } }
php
MIT
c92180c0e8694b5ae8ee4c27e0bc731b48b02ed9
2026-01-05T04:39:01.841453Z
false
laravel-notification-channels/facebook-poster
https://github.com/laravel-notification-channels/facebook-poster/blob/c92180c0e8694b5ae8ee4c27e0bc731b48b02ed9/tests/FacebookPosterPostTest.php
tests/FacebookPosterPostTest.php
<?php namespace NotificationChannels\FacebookPoster\Tests; use NotificationChannels\FacebookPoster\FacebookPosterPost; class FacebookPosterPostTest extends TestCase { public function test_it_can_be_instantiated() { $post = new FacebookPosterPost('message'); $this->assertInstanceOf(FacebookPosterPost::class, $post); $result = $post->getBody(); $this->assertEquals([ 'message' => 'message', ], $result); } public function test_it_can_be_instantiated_with_arguments() { $post = new FacebookPosterPost( message: 'message', link: 'https://laravel.com', params: ['foo' => 'bar'], ); $result = $post->getBody(); $this->assertEquals([ 'message' => 'message', 'link' => 'https://laravel.com', 'foo' => 'bar', ], $result); } /** @test */ public function test_it_can_be_instantiated_with_setters() { $post = (new FacebookPosterPost) ->withMessage('message') ->withLink('https://laravel.com') ->withParams([ 'foo' => 'bar', ]); $result = $post->getBody(); $this->assertEquals([ 'message' => 'message', 'link' => 'https://laravel.com', 'foo' => 'bar', ], $result); } /** @test */ public function it_returns_filtered_body() { $post = new FacebookPosterPost('message'); $result = $post->getBody(); $this->assertEquals([ 'message' => 'message', ], $result); } }
php
MIT
c92180c0e8694b5ae8ee4c27e0bc731b48b02ed9
2026-01-05T04:39:01.841453Z
false
laravel-notification-channels/facebook-poster
https://github.com/laravel-notification-channels/facebook-poster/blob/c92180c0e8694b5ae8ee4c27e0bc731b48b02ed9/tests/TestNotification.php
tests/TestNotification.php
<?php namespace NotificationChannels\FacebookPoster\Tests; use Illuminate\Notifications\Notification; use NotificationChannels\FacebookPoster\FacebookPosterPost; class TestNotification extends Notification { public function toFacebookPoster($notifiable) { return new FacebookPosterPost('message'); } }
php
MIT
c92180c0e8694b5ae8ee4c27e0bc731b48b02ed9
2026-01-05T04:39:01.841453Z
false
laravel-notification-channels/facebook-poster
https://github.com/laravel-notification-channels/facebook-poster/blob/c92180c0e8694b5ae8ee4c27e0bc731b48b02ed9/tests/TestNotificationWithLink.php
tests/TestNotificationWithLink.php
<?php namespace NotificationChannels\FacebookPoster\Tests; use Illuminate\Notifications\Notification; use NotificationChannels\FacebookPoster\FacebookPosterPost; class TestNotificationWithLink extends Notification { public function toFacebookPoster($notifiable) { return (new FacebookPosterPost('message')) ->withLink('https://laravel.com'); } }
php
MIT
c92180c0e8694b5ae8ee4c27e0bc731b48b02ed9
2026-01-05T04:39:01.841453Z
false
laravel-notification-channels/facebook-poster
https://github.com/laravel-notification-channels/facebook-poster/blob/c92180c0e8694b5ae8ee4c27e0bc731b48b02ed9/tests/FacebookPosterChannelTest.php
tests/FacebookPosterChannelTest.php
<?php namespace NotificationChannels\FacebookPoster\Tests; use GuzzleHttp\Client; use Illuminate\Contracts\Config\Repository; use Mockery; use Mockery\MockInterface; use NotificationChannels\FacebookPoster\FacebookPosterChannel; class FacebookPosterChannelTest extends TestCase { protected MockInterface $guzzle; protected MockInterface $config; protected FacebookPosterChannel $channel; public function setUp(): void { parent::setUp(); $this->guzzle = Mockery::mock(Client::class); $this->config = Mockery::mock(Repository::class); $this->channel = new FacebookPosterChannel($this->guzzle, $this->config); } /** @test */ public function it_can_send_a_post() { $this->config->shouldReceive('get')->with('services.facebook_poster.page_id')->andReturn('pageId'); $this->config->shouldReceive('get')->with('services.facebook_poster.access_token')->andReturn('accessToken'); $this->guzzle->shouldReceive('post')->once()->with( 'https://graph.facebook.com/v18.0/pageId/feed?access_token=accessToken', ['form_params' => ['message' => 'message']], ); $this->channel->send(new TestNotifiable, new TestNotification); } /** @test */ public function it_can_send_a_post_with_link() { $this->config->shouldReceive('get')->with('services.facebook_poster.page_id')->andReturn('pageId'); $this->config->shouldReceive('get')->with('services.facebook_poster.access_token')->andReturn('accessToken'); $this->guzzle->shouldReceive('post')->once()->with( 'https://graph.facebook.com/v18.0/pageId/feed?access_token=accessToken', ['form_params' => ['message' => 'message', 'link' => 'https://laravel.com']], ); $this->channel->send(new TestNotifiable, new TestNotificationWithLink); } /** @test */ public function it_can_send_post_with_custom_routing() { $this->config->shouldNotReceive('get'); $this->guzzle->shouldReceive('post')->once()->with( 'https://graph.facebook.com/v18.0/customPageId/feed?access_token=customAccessToken', ['form_params' => ['message' => 'message']], ); $this->channel->send(new TestNotifiableWithCustomRouting, new TestNotification); } }
php
MIT
c92180c0e8694b5ae8ee4c27e0bc731b48b02ed9
2026-01-05T04:39:01.841453Z
false
ircmaxell/FFIMe
https://github.com/ircmaxell/FFIMe/blob/0b7fb71209b192e55a61ec2fb33a932a561dd82a/test/rebuild.php
test/rebuild.php
<?php use FFIMe\FFIMe; require __DIR__ . '/../vendor/autoload.php'; const EXPECTATIONS = [ 'EXPECT', 'EXPECTF', 'EXPECTREGEX', ]; const EXTERNAL_SECTIONS = [ 'FILE', 'EXPECT', 'EXPECTF', 'EXPECTREGEX', ]; const REQUIRED_SECTIONS = [ 'FILE', EXPECTATIONS, ]; const UNSUPPORTED_SECTIONS = [ 'REDIRECTTEST', 'REQUEST', 'POST', 'PUT', 'POST_RAW', 'GZIP_POST', 'DEFLATE_POST', 'GET', 'COOKIE', 'HEADERS', 'CGI', 'EXPECTHEADERS', 'EXTENSIONS', 'PHPDBG', ]; $regen = ($argv[1] ?? "") === "--regen"; foreach (provideTestsFromDir(__DIR__ . '/cases/') as $test) { $path = str_replace(__DIR__ . '/cases/', '', $test[0]); $targetName = 'FFIMe\\Test\\' . str_replace(['/', '.phpt'], ['\\', ''], $path) . 'Test'; $targetFile = __DIR__ . '/generated/' . str_replace('.phpt', 'Test', $path); $targetDir = dirname($targetFile); @mkdir($targetDir, 0777, true); $namespace = explode('\\', $targetName); $class = array_pop($namespace); compileTest($targetFile, implode('\\', $namespace), $class, $test, true, $regen); } function compileTest(string $targetFile, string $namespace, string $class, array $test, bool $isDump, bool $regenerate): void { file_put_contents($targetFile . '.h', $test[2]); $parts = explode('/', $targetFile); $relativeTarget = array_pop($parts); $targetParts = ltrim(str_replace(__DIR__ . '/', '', $targetFile), '/'); $searchParts = explode('/', $targetParts); array_pop($searchParts); $searchPath = '/'; foreach ($searchParts as $relative) { $searchPath .= '../'; } $searchPath .= 'include'; $expected = ''; $assert = ''; $resultFile = var_export('/' . $relativeTarget . '.result.php', true); if (isset($test[3]['EXPECT'])) { $expected = trim($test[3]['EXPECT']); $assert = '$this->assertStringContainsString(self::EXPECTED, trim(file_get_contents(__DIR__ . ' . $resultFile . ')));'; } elseif (isset($test[3]['EXPECTF'])) { $expected = trim($test[3]['EXPECTF']); $assert = '$this->assertStringMatchesFormat(self::EXPECTED, trim(file_get_contents(__DIR__ . ' . $resultFile . ')));'; } else { throw new \LogicException("Unknown test expectation type"); } if ($regenerate) { $ffime = new class(PHP_OS_FAMILY === "Darwin" ? "/usr/lib/libSystem.B.dylib" : "/lib/x86_64-linux-gnu/libc.so.6") extends FFIMe { // Bypass filtering for tests protected function filterSymbolDeclarations(): void {} }; $ffime->include($targetFile . '.h'); $tmp = tempnam(sys_get_temp_dir(), "ffi-rebuild-"); $ffime->codeGen('test\test', $tmp); $out = preg_replace(['(namespace \Ktest(?=;)|const __\K(x86_64|aarch64)(?=__)|const SOFILE = \'\K.+(?=\';))', '(class .*_ptr_ptr.*\{\K(.*+|\r?\n\s*+)+?(?=^}))m'], ["%s", "%a"], file_get_contents($tmp)); file_put_contents($test[0], preg_split("(--EXPECTF--\s+\K)", file_get_contents($test[0]))[0] . $out); unlink($tmp); $expected = trim($out); } $return = '<?php declare(strict_types=1); namespace ' . $namespace . '; use FFIMe\FFIMe; use PHPUnit\Framework\TestCase; /** * Note: this is a generated file, do not edit this!!! */ class ' . $class . ' extends TestCase { const EXPECTED = ' . var_export($expected, true) . '; protected FFIMe $lib; protected Printer $printer; public function setUp(): void { $this->lib = new class( PHP_OS_FAMILY === "Darwin" ? "/usr/lib/libSystem.B.dylib" : "/lib/x86_64-linux-gnu/libc.so.6", [ __DIR__, __DIR__ . ' . var_export($searchPath, true) . ' ] ) extends FFIMe { // Bypass filtering for tests protected function filterSymbolDeclarations(): void {} }; } public function tearDown(): void { @unlink(__DIR__ . ' . $resultFile . '); } /** * @textdox ' . $test[1] . ' */ public function testCodeGen() { $this->lib->include(__DIR__ . ' . var_export('/' . $relativeTarget . '.h', true) . '); $this->lib->codeGen("test\\\\test", __DIR__ . ' . $resultFile . '); $this->assertFileExists(__DIR__ . ' . $resultFile . '); ' . $assert . ' } }'; file_put_contents($targetFile . '.php', $return); } function provideTestsFromDir(string $dir): \Generator { foreach (new \DirectoryIterator($dir) as $path) { if (!$path->isDir() || $path->isDot()) { continue; } yield from provideTestsFromDir($path->getPathname()); } foreach (new \GlobIterator($dir . '/*.phpt') as $test) { yield parseTest(realpath($test->getPathname())); } } function parseTest(string $filename): array { $sections = []; $section = ''; foreach (file($filename) as $line) { if (preg_match('(^--([_A-Z]+)--)', $line, $result)) { $section = $result[1]; $sections[$section] = ''; continue; } if (empty($section)) { throw new \LogicException("Invalid PHPT file: empty section header"); } $sections[$section] .= $line; } if (!isset($sections['TEST'])) { throw new \LogicException("Every test must have a name"); } if (isset($sections['FILEEOF'])) { $sections['FILE'] = rtrim($sections['FILEEOF'], "\r\n"); unset($sections['FILEEOF']); } parseExternal($sections, dirname($filename)); if (!validate($sections)) { throw new \LogicException("Invalid PHPT File"); } foreach (UNSUPPORTED_SECTIONS as $section) { if (isset($sections[$section])) { throw new \LogicException("PHPT $section sections are not supported"); } } return [ $filename, trim($sections["TEST"]), $sections['FILE'], $sections, ]; } function parseExternal(array &$sections, string $testdir): void { foreach (EXTERNAL_SECTIONS as $section) { if (isset($sections[$section . '_EXTERNAL'])) { $filename = trim($sections[$section . '_EXTERNAL']); if (!is_file($testdir . '/' . $filename)) { throw new \RuntimeException("Could not load external file $filename"); } $sections[$section] = file_get_contents($testdir . '/' . $filename); } } } function validate(array &$sections): bool { foreach (REQUIRED_SECTIONS as $section) { if (is_array($section)) { foreach ($section as $any) { if (isset($sections[$any])) { continue 2; } } return false; } elseif (!isset($sections[$section])) { return false; } } return true; }
php
MIT
0b7fb71209b192e55a61ec2fb33a932a561dd82a
2026-01-05T04:39:07.148223Z
false
ircmaxell/FFIMe
https://github.com/ircmaxell/FFIMe/blob/0b7fb71209b192e55a61ec2fb33a932a561dd82a/test/InlineFunctions/basic_structs.php
test/InlineFunctions/basic_structs.php
<?php namespace FFIMe\Test\InlineFunctions; use FFIMe\Test\InlineFunctions\generated\BasicStructs\string_; class BasicStructs extends InlineTestcase { public function testBasicStructManipulation() { $this->compile(<<<HEADER struct bar { int val; }; struct foo { int value[2]; struct { int second_value; } u; struct { const char *str; struct bar bar; }; }; typedef struct bar bar_t; bar_t global_bar; static inline bar_t init_bar(int val) { return global_bar = (struct bar){ val }; } static inline struct foo init_foo(const char *str) { struct foo foo = { 0, 1, 2, .str = str }; foo.bar = init_bar(3); return foo; } static inline void update_foo_bar(struct foo *foo) { foo->bar = (bar_t){ .val = foo->value[1] }; } HEADER); $testCase = generated\BasicStructs\Defs::ffi(); $str = string_::persistentZero("some str"); $foo = $testCase->init_foo($str); $this->assertSame(0, $foo->value[0]); $this->assertSame(1, $foo->value[1]); $this->assertSame(2, $foo->u->second_value); $this->assertSame("some str", $foo->str->toString()); $this->assertSame(3, $foo->bar->val); $this->assertSame(3, $testCase->global_bar->val); $testCase->update_foo_bar($foo->addr()); $this->assertSame(1, $foo->bar->val); \FFI::free($str->getData()); } }
php
MIT
0b7fb71209b192e55a61ec2fb33a932a561dd82a
2026-01-05T04:39:07.148223Z
false
ircmaxell/FFIMe
https://github.com/ircmaxell/FFIMe/blob/0b7fb71209b192e55a61ec2fb33a932a561dd82a/test/InlineFunctions/passing_string_array.php
test/InlineFunctions/passing_string_array.php
<?php namespace FFIMe\Test\InlineFunctions; class PassingStringArray extends InlineTestcase { public function testBasicStructManipulation() { $this->compile(<<<HEADER struct foo { char str1[4]; char str2[4]; unsigned char isNull; }; static inline void copystr(char *from, char *to) { do { *(to++) = *from; } while (*(from++)); } static inline struct foo collect_strs(const char **str) { struct foo foo; copystr(*(str++), foo.str1); copystr(*(str++), foo.str2); foo.isNull = *str == (void*)0; return foo; } HEADER); $testCase = generated\PassingStringArray\Defs::ffi(); $foo = $testCase->collect_strs(["foo", "bar", null]); $this->assertSame("foo", $foo->str1->toString()); $this->assertSame("bar", $foo->str2->toString()); $this->assertSame(1, $foo->isNull); } }
php
MIT
0b7fb71209b192e55a61ec2fb33a932a561dd82a
2026-01-05T04:39:07.148223Z
false
ircmaxell/FFIMe
https://github.com/ircmaxell/FFIMe/blob/0b7fb71209b192e55a61ec2fb33a932a561dd82a/test/InlineFunctions/function_pointers.php
test/InlineFunctions/function_pointers.php
<?php namespace FFIMe\Test\InlineFunctions; class FunctionPointers extends InlineTestcase { public function testFunctionPointerUsage() { $this->compile(<<<HEADER typedef struct { int integer; char *str; } bar; bar (*global_bar)(int integer, char *str); static inline bar init_bar(int val, char *str) { return (bar){ val, str }; } static inline bar init_other_bar(int val, char *str) { return (bar){ val, str + val }; } static inline void set_bar_ptr() { global_bar = &init_bar; } static inline const char *call_bar(int integer) { return global_bar(integer, "foo").str; } HEADER); $testCase = generated\FunctionPointers\Defs::ffi(); $testCase->global_bar = \Closure::fromCallable([$testCase, 'init_other_bar']); self::assertSame("oo", $testCase->call_bar(1)->toString()); $testCase->set_bar_ptr(); self::assertSame("foo", $testCase->call_bar(1)->toString()); } }
php
MIT
0b7fb71209b192e55a61ec2fb33a932a561dd82a
2026-01-05T04:39:07.148223Z
false
ircmaxell/FFIMe
https://github.com/ircmaxell/FFIMe/blob/0b7fb71209b192e55a61ec2fb33a932a561dd82a/test/InlineFunctions/InlineTestcase.php
test/InlineFunctions/InlineTestcase.php
<?php namespace FFIMe\Test\InlineFunctions; use FFIMe\FFIMe; abstract class InlineTestcase extends \PHPUnit\Framework\TestCase { public function compile($header): void { $classname = substr(strrchr(get_class($this), '\\'), 1); @mkdir(__DIR__ . '/generated/' . $classname); $headerfile = __DIR__ . '/generated/' . $classname . '/defs.h'; file_put_contents($headerfile, $header); $ffi = new FFIMe( PHP_OS_FAMILY === "Darwin" ? "/usr/lib/libSystem.B.dylib" : "/lib/x86_64-linux-gnu/libc.so.6", [ __DIR__, ] ); $ffi->include($headerfile); $phpfile = __DIR__ . '/generated/' . $classname . '/defs.php'; $ffi->codeGen(__NAMESPACE__ . '\\generated\\'. $classname . '\\Defs', $phpfile); } }
php
MIT
0b7fb71209b192e55a61ec2fb33a932a561dd82a
2026-01-05T04:39:07.148223Z
false
ircmaxell/FFIMe
https://github.com/ircmaxell/FFIMe/blob/0b7fb71209b192e55a61ec2fb33a932a561dd82a/test/InlineFunctions/duffs_device.php
test/InlineFunctions/duffs_device.php
<?php namespace FFIMe\Test\InlineFunctions; class DuffsDevice extends InlineTestcase { public function testSimpleDuffsDevice() { $this->compile(<<<HEADER static inline int calcHash(int len, const char *str) { int result = 0; int mul = 1; const char *end = str + len; str -= (4 - len) & 0x3; switch (len & 0x3) { case 0: ; while (str < end) { result ^= str[0] * mul; case 3: result ^= str[1] * mul * 9; case 2: result ^= str[2] * mul * 9 * 9; case 1: result ^= str[3] * mul * 9 * 9 * 9; mul *= 9 * 9 * 9 * 9; str += 4; } } return result; } HEADER); $testCase = generated\DuffsDevice\Defs::ffi(); $this->assertSame(32 * (9 ** 3), $testCase->calcHash(1, \chr(32))); $this->assertSame((32 * (9 ** 3)) ^ ((9 ** 4) * 64) ^ ((9 ** 5) * 16) ^ ((9 ** 6) * 48) ^ ((9 ** 7) * 80), $testCase->calcHash(5, \chr(32) . \chr(64) . \chr(16) . \chr(48) . \chr(80))); } }
php
MIT
0b7fb71209b192e55a61ec2fb33a932a561dd82a
2026-01-05T04:39:07.148223Z
false
ircmaxell/FFIMe
https://github.com/ircmaxell/FFIMe/blob/0b7fb71209b192e55a61ec2fb33a932a561dd82a/test/InlineFunctions/basic_strings.php
test/InlineFunctions/basic_strings.php
<?php namespace FFIMe\Test\InlineFunctions; class BasicStrings extends InlineTestcase { public function testBasicStringManipulation() { $this->compile(<<<HEADER #include <stdio.h> #include <ctype.h> #include <stdlib.h> #include <string.h> static inline char *getUppercaseString(char *str) { int len = strlen(str); char *upper = malloc(len + 1), *ret; for (int i = 0; i < len; ++i) { upper[i] = toupper(*(str++)); } upper[len] = 0; ret = malloc(50); sprintf(ret, "len: %d str: %s", strlen(upper), upper); free(upper); return ret; } HEADER); $testCase = generated\BasicStrings\Defs::ffi(); $str = $testCase->getUppercaseString("lower case string"); $this->assertSame('len: 17 str: LOWER CASE STRING', $str->toString()); $testCase->free($str); } }
php
MIT
0b7fb71209b192e55a61ec2fb33a932a561dd82a
2026-01-05T04:39:07.148223Z
false
ircmaxell/FFIMe
https://github.com/ircmaxell/FFIMe/blob/0b7fb71209b192e55a61ec2fb33a932a561dd82a/test/generated/basic_stringsTest.php
test/generated/basic_stringsTest.php
<?php declare(strict_types=1); namespace FFIMe\Test; use FFIMe\FFIMe; use PHPUnit\Framework\TestCase; /** * Note: this is a generated file, do not edit this!!! */ class basic_stringsTest extends TestCase { const EXPECTED = '<?php namespace %s; use FFI; use test\\double; interface itest {} interface itest_ptr {} class test { const __%s__ = 1; const __LP64__ = 1; const __GNUC_VA_LIST = 1; const __GNUC__ = 4; const __GNUC_MINOR__ = 2; const __STDC__ = 1; public static function ffi(?string $pathToSoFile = testFFI::SOFILE): testFFI { return new testFFI($pathToSoFile); } public static function sizeof($classOrObject): int { return testFFI::sizeof($classOrObject); } } class testFFI { const SOFILE = \'%s\'; const TYPES_DEF = \'\'; const HEADER_DEF = self::TYPES_DEF . \'void setFoo(char *value); char *getFoo(); \'; private FFI $ffi; private static FFI $staticFFI; private static \\WeakMap $__arrayWeakMap; private array $__literalStrings = []; public function __construct(?string $pathToSoFile = self::SOFILE) { $this->ffi = FFI::cdef(self::HEADER_DEF, $pathToSoFile); } public static function cast(itest $from, string $to): itest { if (!is_a($to, itest::class, true)) { throw new \\LogicException("Cannot cast to a non-wrapper type"); } return new $to(self::$staticFFI->cast($to::getType(), $from->getData())); } public static function makeArray(string $class, int|array $elements): itest { $type = $class::getType(); if (substr($type, -1) !== "*") { throw new \\LogicException("Attempting to make a non-pointer element into an array"); } if (is_int($elements)) { $cdata = self::$staticFFI->new(substr($type, 0, -1) . "[$elements]"); } else { $cdata = self::$staticFFI->new(substr($type, 0, -1) . "[" . count($elements) . "]"); foreach ($elements as $key => $raw) { $cdata[$key] = \\is_scalar($raw) ? \\is_int($raw) && $type === "char*" ? \\chr($raw) : $raw : $raw->getData(); } } $object = new $class(self::$staticFFI->cast($type, \\FFI::addr($cdata))); self::$__arrayWeakMap[$object] = $cdata; return $object; } public static function sizeof($classOrObject): int { if (is_object($classOrObject) && $classOrObject instanceof itest) { return FFI::sizeof($classOrObject->getData()); } elseif (is_a($classOrObject, itest::class, true)) { return FFI::sizeof(self::$staticFFI->type($classOrObject::getType())); } else { throw new \\LogicException("Unknown class/object passed to sizeof()"); } } public function getFFI(): FFI { return $this->ffi; } public function __get(string $name) { switch($name) { default: return $this->ffi->$name; } } public function __set(string $name, $value) { switch($name) { default: return $this->ffi->$name; } } public function __allocCachedString(string $str): FFI\\CData { return $this->__literalStrings[$str] ??= string_::ownedZero($str)->getData(); } public function setFoo(void_ptr | string_ | null | string | array $value): void { $__ffi_internal_refsvalue = []; if (\\is_string($value)) { $value = string_::ownedZero($value)->getData(); } elseif (\\is_array($value)) { $_ = $this->ffi->new("char[" . \\count($value) . "]"); $_i = 0; if ($value) { if ($_ref = \\ReflectionReference::fromArrayElement($value, \\key($value))) { foreach ($value as $_k => $_v) { $__ffi_internal_refsvalue[$_i] = &$value[$_k]; $_[$_i++] = $_v ?? 0; } $__ffi_internal_originalvalue = $value = $_; } else { foreach ($value as $_v) { $_[$_i++] = $_v ?? 0; } $value = $_; } } } else { $value = $value?->getData(); if ($value !== null) { $value = $this->ffi->cast("char*", $value); } } $this->ffi->setFoo($value); foreach ($__ffi_internal_refsvalue as $_k => &$__ffi_internal_ref_v) { $__ffi_internal_ref_v = $__ffi_internal_originalvalue[$_k]; $__ffi_internal_ref_v = \\ord($__ffi_internal_ref_v); } } public function getFoo(): ?string_ { $result = $this->ffi->getFoo(); return $result === null ? null : new string_($result); } } class string_ implements itest, itest_ptr, \\ArrayAccess { private FFI\\CData $data; public function __construct(FFI\\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\\CData { return $this->data; } public function equals(string_ $other): bool { return $this->data == $other->data; } public function addr(): string_ptr { return new string_ptr(FFI::addr($this->data)); } public function deref(int $n = 0): int { return \\ord($this->data[$n]); } #[\\ReturnTypeWillChange] public function offsetGet($offset): int { return $this->deref($offset); } #[\\ReturnTypeWillChange] public function offsetExists($offset): bool { return !FFI::isNull($this->data); } #[\\ReturnTypeWillChange] public function offsetUnset($offset): void { throw new \\Error("Cannot unset C structures"); } #[\\ReturnTypeWillChange] public function offsetSet($offset, $value): void { $this->data[$offset] = \\chr($value); } public static function array(int $size = 1): self { return testFFI::makeArray(self::class, $size); } /** @return int[] */ public function toArray(?int $length = null): array { $ret = []; if ($length === null) { $i = 0; while ("\\0" !== $cur = $this->data[$i++]) { $ret[] = \\ord($cur); } } else { for ($i = 0; $i < $length; ++$i) { $ret[] = \\ord($this->data[$i]); } } return $ret; } public function toString(?int $length = null): string { return $length === null ? FFI::string($this->data) : FFI::string($this->data, $length); } public static function persistent(string $string): self { $str = new self(FFI::cdef()->new("char[" . \\strlen($string) . "]", false)); FFI::memcpy($str->data, $string, \\strlen($string)); return $str; } public static function owned(string $string): self { $str = new self(FFI::cdef()->new("char[" . \\strlen($string) . "]", true)); FFI::memcpy($str->data, $string, \\strlen($string)); return $str; } public static function persistentZero(string $string): self { return self::persistent("$string\\0"); } public static function ownedZero(string $string): self { return self::owned("$string\\0"); } public function set(int | void_ptr | string_ $value): void { if (\\is_scalar($value)) { $this->data[0] = \\chr($value); } else { FFI::addr($this->data)[0] = $value->getData(); } } public static function getType(): string { return \'char*\'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class string_ptr implements itest, itest_ptr, \\ArrayAccess { private FFI\\CData $data; public function __construct(FFI\\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\\CData { return $this->data; } public function equals(string_ptr $other): bool { return $this->data == $other->data; } public function addr(): string_ptr_ptr { return new string_ptr_ptr(FFI::addr($this->data)); } public function deref(int $n = 0): string_ { return new string_($this->data[$n]); } #[\\ReturnTypeWillChange] public function offsetGet($offset): string_ { return $this->deref($offset); } #[\\ReturnTypeWillChange] public function offsetExists($offset): bool { return !FFI::isNull($this->data); } #[\\ReturnTypeWillChange] public function offsetUnset($offset): void { throw new \\Error("Cannot unset C structures"); } #[\\ReturnTypeWillChange] public function offsetSet($offset, $value): void { $this->data[$offset] = $value->getData(); } public static function array(int $size = 1): self { return testFFI::makeArray(self::class, $size); } /** @return string_[] */ public function toArray(?int $length = null): array { $ret = []; if ($length === null) { $i = 0; while (null !== $cur = $this->data[$i++]) { $ret[] = new string_($cur); } } else { for ($i = 0; $i < $length; ++$i) { $ret[] = new string_($this->data[$i]); } } return $ret; } public function set(void_ptr | string_ptr $value): void { FFI::addr($this->data)[0] = $value->getData(); } public static function getType(): string { return \'char**\'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class string_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class string_ptr_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class void_ptr implements itest, itest_ptr { private FFI\\CData $data; public function __construct(FFI\\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\\CData { return $this->data; } public function equals(void_ptr $other): bool { return $this->data == $other->data; } public function addr(): void_ptr_ptr { return new void_ptr_ptr(FFI::addr($this->data)); } public function set(itest_ptr $value): void { FFI::addr($this->data)[0] = $value->getData(); } public static function getType(): string { return \'void*\'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class void_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class void_ptr_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class void_ptr_ptr_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} (function() { self::$staticFFI = \\FFI::cdef(testFFI::TYPES_DEF); self::$__arrayWeakMap = new \\WeakMap; })->bindTo(null, testFFI::class)();'; protected FFIMe $lib; protected Printer $printer; public function setUp(): void { $this->lib = new class( PHP_OS_FAMILY === "Darwin" ? "/usr/lib/libSystem.B.dylib" : "/lib/x86_64-linux-gnu/libc.so.6", [ __DIR__, __DIR__ . '/../include' ] ) extends FFIMe { // Bypass filtering for tests protected function filterSymbolDeclarations(): void {} }; } public function tearDown(): void { @unlink(__DIR__ . '/basic_stringsTest.result.php'); } /** * @textdox Test basic parsing of strings */ public function testCodeGen() { $this->lib->include(__DIR__ . '/basic_stringsTest.h'); $this->lib->codeGen("test\\test", __DIR__ . '/basic_stringsTest.result.php'); $this->assertFileExists(__DIR__ . '/basic_stringsTest.result.php'); $this->assertStringMatchesFormat(self::EXPECTED, trim(file_get_contents(__DIR__ . '/basic_stringsTest.result.php'))); } }
php
MIT
0b7fb71209b192e55a61ec2fb33a932a561dd82a
2026-01-05T04:39:07.148223Z
false
ircmaxell/FFIMe
https://github.com/ircmaxell/FFIMe/blob/0b7fb71209b192e55a61ec2fb33a932a561dd82a/test/generated/char_returnsTest.php
test/generated/char_returnsTest.php
<?php declare(strict_types=1); namespace FFIMe\Test; use FFIMe\FFIMe; use PHPUnit\Framework\TestCase; /** * Note: this is a generated file, do not edit this!!! */ class char_returnsTest extends TestCase { const EXPECTED = '<?php namespace %s; use FFI; use test\\double; interface itest {} interface itest_ptr {} class test { const __%s__ = 1; const __LP64__ = 1; const __GNUC_VA_LIST = 1; const __GNUC__ = 4; const __GNUC_MINOR__ = 2; const __STDC__ = 1; public static function ffi(?string $pathToSoFile = testFFI::SOFILE): testFFI { return new testFFI($pathToSoFile); } public static function sizeof($classOrObject): int { return testFFI::sizeof($classOrObject); } } class testFFI { const SOFILE = \'%s\'; const TYPES_DEF = \'typedef struct LLVMOpaqueModule *LLVMModuleRef; \'; const HEADER_DEF = self::TYPES_DEF . \'char *LLVMGetModuleIdentifier(LLVMModuleRef M, size_t *Len); \'; private FFI $ffi; private static FFI $staticFFI; private static \\WeakMap $__arrayWeakMap; private array $__literalStrings = []; public function __construct(?string $pathToSoFile = self::SOFILE) { $this->ffi = FFI::cdef(self::HEADER_DEF, $pathToSoFile); } public static function cast(itest $from, string $to): itest { if (!is_a($to, itest::class, true)) { throw new \\LogicException("Cannot cast to a non-wrapper type"); } return new $to(self::$staticFFI->cast($to::getType(), $from->getData())); } public static function makeArray(string $class, int|array $elements): itest { $type = $class::getType(); if (substr($type, -1) !== "*") { throw new \\LogicException("Attempting to make a non-pointer element into an array"); } if (is_int($elements)) { $cdata = self::$staticFFI->new(substr($type, 0, -1) . "[$elements]"); } else { $cdata = self::$staticFFI->new(substr($type, 0, -1) . "[" . count($elements) . "]"); foreach ($elements as $key => $raw) { $cdata[$key] = \\is_scalar($raw) ? \\is_int($raw) && $type === "char*" ? \\chr($raw) : $raw : $raw->getData(); } } $object = new $class(self::$staticFFI->cast($type, \\FFI::addr($cdata))); self::$__arrayWeakMap[$object] = $cdata; return $object; } public static function sizeof($classOrObject): int { if (is_object($classOrObject) && $classOrObject instanceof itest) { return FFI::sizeof($classOrObject->getData()); } elseif (is_a($classOrObject, itest::class, true)) { return FFI::sizeof(self::$staticFFI->type($classOrObject::getType())); } else { throw new \\LogicException("Unknown class/object passed to sizeof()"); } } public function getFFI(): FFI { return $this->ffi; } public function __get(string $name) { switch($name) { default: return $this->ffi->$name; } } public function __set(string $name, $value) { switch($name) { default: return $this->ffi->$name; } } public function __allocCachedString(string $str): FFI\\CData { return $this->__literalStrings[$str] ??= string_::ownedZero($str)->getData(); } public function LLVMGetModuleIdentifier(void_ptr | struct_LLVMOpaqueModule_ptr | null | array $M, void_ptr | size_t_ptr | null | array $Len): ?string_ { $__ffi_internal_refsM = []; if (\\is_array($M)) { $_ = $this->ffi->new("struct LLVMOpaqueModule[" . \\count($M) . "]"); $_i = 0; if ($M) { if ($_ref = \\ReflectionReference::fromArrayElement($M, \\key($M))) { foreach ($M as $_k => $_v) { $__ffi_internal_refsM[$_i] = &$M[$_k]; $_[$_i++] = $_v?->getData(); } $__ffi_internal_originalM = $M = $_; } else { foreach ($M as $_v) { $_[$_i++] = $_v?->getData(); } $M = $_; } } } else { $M = $M?->getData(); if ($M !== null) { $M = $this->ffi->cast("struct LLVMOpaqueModule*", $M); } } $__ffi_internal_refsLen = []; if (\\is_array($Len)) { $_ = $this->ffi->new("size_t[" . \\count($Len) . "]"); $_i = 0; if ($Len) { if ($_ref = \\ReflectionReference::fromArrayElement($Len, \\key($Len))) { foreach ($Len as $_k => $_v) { $__ffi_internal_refsLen[$_i] = &$Len[$_k]; $_[$_i++] = $_v ?? 0; } $__ffi_internal_originalLen = $Len = $_; } else { foreach ($Len as $_v) { $_[$_i++] = $_v ?? 0; } $Len = $_; } } } else { $Len = $Len?->getData(); if ($Len !== null) { $Len = $this->ffi->cast("size_t*", $Len); } } $result = $this->ffi->LLVMGetModuleIdentifier($M, $Len); foreach ($__ffi_internal_refsM as $_k => &$__ffi_internal_ref_v) { $__ffi_internal_ref_v = $__ffi_internal_originalM[$_k]; if ($__ffi_internal_ref_v !== null) { $__ffi_internal_ref_v = new struct_LLVMOpaqueModule($__ffi_internal_ref_v); } } foreach ($__ffi_internal_refsLen as $_k => &$__ffi_internal_ref_v) { $__ffi_internal_ref_v = $__ffi_internal_originalLen[$_k]; } return $result === null ? null : new string_($result); } } class string_ implements itest, itest_ptr, \\ArrayAccess { private FFI\\CData $data; public function __construct(FFI\\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\\CData { return $this->data; } public function equals(string_ $other): bool { return $this->data == $other->data; } public function addr(): string_ptr { return new string_ptr(FFI::addr($this->data)); } public function deref(int $n = 0): int { return \\ord($this->data[$n]); } #[\\ReturnTypeWillChange] public function offsetGet($offset): int { return $this->deref($offset); } #[\\ReturnTypeWillChange] public function offsetExists($offset): bool { return !FFI::isNull($this->data); } #[\\ReturnTypeWillChange] public function offsetUnset($offset): void { throw new \\Error("Cannot unset C structures"); } #[\\ReturnTypeWillChange] public function offsetSet($offset, $value): void { $this->data[$offset] = \\chr($value); } public static function array(int $size = 1): self { return testFFI::makeArray(self::class, $size); } /** @return int[] */ public function toArray(?int $length = null): array { $ret = []; if ($length === null) { $i = 0; while ("\\0" !== $cur = $this->data[$i++]) { $ret[] = \\ord($cur); } } else { for ($i = 0; $i < $length; ++$i) { $ret[] = \\ord($this->data[$i]); } } return $ret; } public function toString(?int $length = null): string { return $length === null ? FFI::string($this->data) : FFI::string($this->data, $length); } public static function persistent(string $string): self { $str = new self(FFI::cdef()->new("char[" . \\strlen($string) . "]", false)); FFI::memcpy($str->data, $string, \\strlen($string)); return $str; } public static function owned(string $string): self { $str = new self(FFI::cdef()->new("char[" . \\strlen($string) . "]", true)); FFI::memcpy($str->data, $string, \\strlen($string)); return $str; } public static function persistentZero(string $string): self { return self::persistent("$string\\0"); } public static function ownedZero(string $string): self { return self::owned("$string\\0"); } public function set(int | void_ptr | string_ $value): void { if (\\is_scalar($value)) { $this->data[0] = \\chr($value); } else { FFI::addr($this->data)[0] = $value->getData(); } } public static function getType(): string { return \'char*\'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class string_ptr implements itest, itest_ptr, \\ArrayAccess { private FFI\\CData $data; public function __construct(FFI\\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\\CData { return $this->data; } public function equals(string_ptr $other): bool { return $this->data == $other->data; } public function addr(): string_ptr_ptr { return new string_ptr_ptr(FFI::addr($this->data)); } public function deref(int $n = 0): string_ { return new string_($this->data[$n]); } #[\\ReturnTypeWillChange] public function offsetGet($offset): string_ { return $this->deref($offset); } #[\\ReturnTypeWillChange] public function offsetExists($offset): bool { return !FFI::isNull($this->data); } #[\\ReturnTypeWillChange] public function offsetUnset($offset): void { throw new \\Error("Cannot unset C structures"); } #[\\ReturnTypeWillChange] public function offsetSet($offset, $value): void { $this->data[$offset] = $value->getData(); } public static function array(int $size = 1): self { return testFFI::makeArray(self::class, $size); } /** @return string_[] */ public function toArray(?int $length = null): array { $ret = []; if ($length === null) { $i = 0; while (null !== $cur = $this->data[$i++]) { $ret[] = new string_($cur); } } else { for ($i = 0; $i < $length; ++$i) { $ret[] = new string_($this->data[$i]); } } return $ret; } public function set(void_ptr | string_ptr $value): void { FFI::addr($this->data)[0] = $value->getData(); } public static function getType(): string { return \'char**\'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class string_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class string_ptr_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class void_ptr implements itest, itest_ptr { private FFI\\CData $data; public function __construct(FFI\\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\\CData { return $this->data; } public function equals(void_ptr $other): bool { return $this->data == $other->data; } public function addr(): void_ptr_ptr { return new void_ptr_ptr(FFI::addr($this->data)); } public function set(itest_ptr $value): void { FFI::addr($this->data)[0] = $value->getData(); } public static function getType(): string { return \'void*\'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class void_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class void_ptr_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class void_ptr_ptr_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class size_t_ptr implements itest, itest_ptr, \\ArrayAccess { private FFI\\CData $data; public function __construct(FFI\\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\\CData { return $this->data; } public function equals(size_t_ptr $other): bool { return $this->data == $other->data; } public function addr(): size_t_ptr_ptr { return new size_t_ptr_ptr(FFI::addr($this->data)); } public function deref(int $n = 0): int { return $this->data[$n]; } #[\\ReturnTypeWillChange] public function offsetGet($offset): int { return $this->deref($offset); } #[\\ReturnTypeWillChange] public function offsetExists($offset): bool { return !FFI::isNull($this->data); } #[\\ReturnTypeWillChange] public function offsetUnset($offset): void { throw new \\Error("Cannot unset C structures"); } #[\\ReturnTypeWillChange] public function offsetSet($offset, $value): void { $this->data[$offset] = $value; } public static function array(int $size = 1): self { return testFFI::makeArray(self::class, $size); } /** @return int[] */ public function toArray(int $length): array { $ret = []; for ($i = 0; $i < $length; ++$i) { $ret[] = ($this->data[$i]); } return $ret; } public function set(int | void_ptr | size_t_ptr $value): void { if (\\is_scalar($value)) { $this->data[0] = $value; } else { FFI::addr($this->data)[0] = $value->getData(); } } public static function getType(): string { return \'size_t*\'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class size_t_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class size_t_ptr_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class size_t_ptr_ptr_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} (function() { self::$staticFFI = \\FFI::cdef(testFFI::TYPES_DEF); self::$__arrayWeakMap = new \\WeakMap; })->bindTo(null, testFFI::class)(); \\class_alias(struct_LLVMOpaqueModule_ptr::class, LLVMModuleRef::class); \\class_alias(struct_LLVMOpaqueModule_ptr_ptr::class, LLVMModuleRef_ptr::class); \\class_alias(struct_LLVMOpaqueModule_ptr_ptr_ptr::class, LLVMModuleRef_ptr_ptr::class); \\class_alias(struct_LLVMOpaqueModule_ptr_ptr_ptr_ptr::class, LLVMModuleRef_ptr_ptr_ptr::class);'; protected FFIMe $lib; protected Printer $printer; public function setUp(): void { $this->lib = new class( PHP_OS_FAMILY === "Darwin" ? "/usr/lib/libSystem.B.dylib" : "/lib/x86_64-linux-gnu/libc.so.6", [ __DIR__, __DIR__ . '/../include' ] ) extends FFIMe { // Bypass filtering for tests protected function filterSymbolDeclarations(): void {} }; } public function tearDown(): void { @unlink(__DIR__ . '/char_returnsTest.result.php'); } /** * @textdox Test basic parsing of character returns */ public function testCodeGen() { $this->lib->include(__DIR__ . '/char_returnsTest.h'); $this->lib->codeGen("test\\test", __DIR__ . '/char_returnsTest.result.php'); $this->assertFileExists(__DIR__ . '/char_returnsTest.result.php'); $this->assertStringMatchesFormat(self::EXPECTED, trim(file_get_contents(__DIR__ . '/char_returnsTest.result.php'))); } }
php
MIT
0b7fb71209b192e55a61ec2fb33a932a561dd82a
2026-01-05T04:39:07.148223Z
false
ircmaxell/FFIMe
https://github.com/ircmaxell/FFIMe/blob/0b7fb71209b192e55a61ec2fb33a932a561dd82a/test/generated/basic_enumsTest.php
test/generated/basic_enumsTest.php
<?php declare(strict_types=1); namespace FFIMe\Test; use FFIMe\FFIMe; use PHPUnit\Framework\TestCase; /** * Note: this is a generated file, do not edit this!!! */ class basic_enumsTest extends TestCase { const EXPECTED = '<?php namespace %s; use FFI; use test\\double; interface itest {} interface itest_ptr {} class test { const __%s__ = 1; const __LP64__ = 1; const __GNUC_VA_LIST = 1; const __GNUC__ = 4; const __GNUC_MINOR__ = 2; const __STDC__ = 1; const A1 = (0) + 0 /* enum A */; const A2 = (0) + 1 /* enum A */; const B1 = (0) + 0 /* typedefenum B */; const B2 = (0) + 1 /* typedefenum B */; public static function ffi(?string $pathToSoFile = testFFI::SOFILE): testFFI { return new testFFI($pathToSoFile); } public static function sizeof($classOrObject): int { return testFFI::sizeof($classOrObject); } } class testFFI { const SOFILE = \'%s\'; const TYPES_DEF = \'enum A { A1, A2, }; typedef enum { B1, B2, } B; \'; const HEADER_DEF = self::TYPES_DEF . \'extern void something(B b); \'; private FFI $ffi; private static FFI $staticFFI; private static \\WeakMap $__arrayWeakMap; private array $__literalStrings = []; public function __construct(?string $pathToSoFile = self::SOFILE) { $this->ffi = FFI::cdef(self::HEADER_DEF, $pathToSoFile); } public static function cast(itest $from, string $to): itest { if (!is_a($to, itest::class, true)) { throw new \\LogicException("Cannot cast to a non-wrapper type"); } return new $to(self::$staticFFI->cast($to::getType(), $from->getData())); } public static function makeArray(string $class, int|array $elements): itest { $type = $class::getType(); if (substr($type, -1) !== "*") { throw new \\LogicException("Attempting to make a non-pointer element into an array"); } if (is_int($elements)) { $cdata = self::$staticFFI->new(substr($type, 0, -1) . "[$elements]"); } else { $cdata = self::$staticFFI->new(substr($type, 0, -1) . "[" . count($elements) . "]"); foreach ($elements as $key => $raw) { $cdata[$key] = \\is_scalar($raw) ? \\is_int($raw) && $type === "char*" ? \\chr($raw) : $raw : $raw->getData(); } } $object = new $class(self::$staticFFI->cast($type, \\FFI::addr($cdata))); self::$__arrayWeakMap[$object] = $cdata; return $object; } public static function sizeof($classOrObject): int { if (is_object($classOrObject) && $classOrObject instanceof itest) { return FFI::sizeof($classOrObject->getData()); } elseif (is_a($classOrObject, itest::class, true)) { return FFI::sizeof(self::$staticFFI->type($classOrObject::getType())); } else { throw new \\LogicException("Unknown class/object passed to sizeof()"); } } public function getFFI(): FFI { return $this->ffi; } public function __get(string $name) { switch($name) { default: return $this->ffi->$name; } } public function __set(string $name, $value) { switch($name) { default: return $this->ffi->$name; } } public function __allocCachedString(string $str): FFI\\CData { return $this->__literalStrings[$str] ??= string_::ownedZero($str)->getData(); } public function something(int $b): void { $this->ffi->something($b); } } class string_ implements itest, itest_ptr, \\ArrayAccess { private FFI\\CData $data; public function __construct(FFI\\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\\CData { return $this->data; } public function equals(string_ $other): bool { return $this->data == $other->data; } public function addr(): string_ptr { return new string_ptr(FFI::addr($this->data)); } public function deref(int $n = 0): int { return \\ord($this->data[$n]); } #[\\ReturnTypeWillChange] public function offsetGet($offset): int { return $this->deref($offset); } #[\\ReturnTypeWillChange] public function offsetExists($offset): bool { return !FFI::isNull($this->data); } #[\\ReturnTypeWillChange] public function offsetUnset($offset): void { throw new \\Error("Cannot unset C structures"); } #[\\ReturnTypeWillChange] public function offsetSet($offset, $value): void { $this->data[$offset] = \\chr($value); } public static function array(int $size = 1): self { return testFFI::makeArray(self::class, $size); } /** @return int[] */ public function toArray(?int $length = null): array { $ret = []; if ($length === null) { $i = 0; while ("\\0" !== $cur = $this->data[$i++]) { $ret[] = \\ord($cur); } } else { for ($i = 0; $i < $length; ++$i) { $ret[] = \\ord($this->data[$i]); } } return $ret; } public function toString(?int $length = null): string { return $length === null ? FFI::string($this->data) : FFI::string($this->data, $length); } public static function persistent(string $string): self { $str = new self(FFI::cdef()->new("char[" . \\strlen($string) . "]", false)); FFI::memcpy($str->data, $string, \\strlen($string)); return $str; } public static function owned(string $string): self { $str = new self(FFI::cdef()->new("char[" . \\strlen($string) . "]", true)); FFI::memcpy($str->data, $string, \\strlen($string)); return $str; } public static function persistentZero(string $string): self { return self::persistent("$string\\0"); } public static function ownedZero(string $string): self { return self::owned("$string\\0"); } public function set(int | void_ptr | string_ $value): void { if (\\is_scalar($value)) { $this->data[0] = \\chr($value); } else { FFI::addr($this->data)[0] = $value->getData(); } } public static function getType(): string { return \'char*\'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class string_ptr implements itest, itest_ptr, \\ArrayAccess { private FFI\\CData $data; public function __construct(FFI\\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\\CData { return $this->data; } public function equals(string_ptr $other): bool { return $this->data == $other->data; } public function addr(): string_ptr_ptr { return new string_ptr_ptr(FFI::addr($this->data)); } public function deref(int $n = 0): string_ { return new string_($this->data[$n]); } #[\\ReturnTypeWillChange] public function offsetGet($offset): string_ { return $this->deref($offset); } #[\\ReturnTypeWillChange] public function offsetExists($offset): bool { return !FFI::isNull($this->data); } #[\\ReturnTypeWillChange] public function offsetUnset($offset): void { throw new \\Error("Cannot unset C structures"); } #[\\ReturnTypeWillChange] public function offsetSet($offset, $value): void { $this->data[$offset] = $value->getData(); } public static function array(int $size = 1): self { return testFFI::makeArray(self::class, $size); } /** @return string_[] */ public function toArray(?int $length = null): array { $ret = []; if ($length === null) { $i = 0; while (null !== $cur = $this->data[$i++]) { $ret[] = new string_($cur); } } else { for ($i = 0; $i < $length; ++$i) { $ret[] = new string_($this->data[$i]); } } return $ret; } public function set(void_ptr | string_ptr $value): void { FFI::addr($this->data)[0] = $value->getData(); } public static function getType(): string { return \'char**\'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class string_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class string_ptr_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class void_ptr implements itest, itest_ptr { private FFI\\CData $data; public function __construct(FFI\\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\\CData { return $this->data; } public function equals(void_ptr $other): bool { return $this->data == $other->data; } public function addr(): void_ptr_ptr { return new void_ptr_ptr(FFI::addr($this->data)); } public function set(itest_ptr $value): void { FFI::addr($this->data)[0] = $value->getData(); } public static function getType(): string { return \'void*\'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class void_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class void_ptr_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class void_ptr_ptr_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class int_ptr implements itest, itest_ptr, \\ArrayAccess { private FFI\\CData $data; public function __construct(FFI\\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\\CData { return $this->data; } public function equals(int_ptr $other): bool { return $this->data == $other->data; } public function addr(): int_ptr_ptr { return new int_ptr_ptr(FFI::addr($this->data)); } public function deref(int $n = 0): int { return $this->data[$n]; } #[\\ReturnTypeWillChange] public function offsetGet($offset): int { return $this->deref($offset); } #[\\ReturnTypeWillChange] public function offsetExists($offset): bool { return !FFI::isNull($this->data); } #[\\ReturnTypeWillChange] public function offsetUnset($offset): void { throw new \\Error("Cannot unset C structures"); } #[\\ReturnTypeWillChange] public function offsetSet($offset, $value): void { $this->data[$offset] = $value; } public static function array(int $size = 1): self { return testFFI::makeArray(self::class, $size); } /** @return int[] */ public function toArray(int $length): array { $ret = []; for ($i = 0; $i < $length; ++$i) { $ret[] = ($this->data[$i]); } return $ret; } public function set(int | void_ptr | int_ptr $value): void { if (\\is_scalar($value)) { $this->data[0] = $value; } else { FFI::addr($this->data)[0] = $value->getData(); } } public static function getType(): string { return \'int*\'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class int_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class int_ptr_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class int_ptr_ptr_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} (function() { self::$staticFFI = \\FFI::cdef(testFFI::TYPES_DEF); self::$__arrayWeakMap = new \\WeakMap; })->bindTo(null, testFFI::class)();'; protected FFIMe $lib; protected Printer $printer; public function setUp(): void { $this->lib = new class( PHP_OS_FAMILY === "Darwin" ? "/usr/lib/libSystem.B.dylib" : "/lib/x86_64-linux-gnu/libc.so.6", [ __DIR__, __DIR__ . '/../include' ] ) extends FFIMe { // Bypass filtering for tests protected function filterSymbolDeclarations(): void {} }; } public function tearDown(): void { @unlink(__DIR__ . '/basic_enumsTest.result.php'); } /** * @textdox Test basic parsing of enums */ public function testCodeGen() { $this->lib->include(__DIR__ . '/basic_enumsTest.h'); $this->lib->codeGen("test\\test", __DIR__ . '/basic_enumsTest.result.php'); $this->assertFileExists(__DIR__ . '/basic_enumsTest.result.php'); $this->assertStringMatchesFormat(self::EXPECTED, trim(file_get_contents(__DIR__ . '/basic_enumsTest.result.php'))); } }
php
MIT
0b7fb71209b192e55a61ec2fb33a932a561dd82a
2026-01-05T04:39:07.148223Z
false
ircmaxell/FFIMe
https://github.com/ircmaxell/FFIMe/blob/0b7fb71209b192e55a61ec2fb33a932a561dd82a/test/generated/enum_self_referencesTest.php
test/generated/enum_self_referencesTest.php
<?php declare(strict_types=1); namespace FFIMe\Test; use FFIMe\FFIMe; use PHPUnit\Framework\TestCase; /** * Note: this is a generated file, do not edit this!!! */ class enum_self_referencesTest extends TestCase { const EXPECTED = '<?php namespace %s; use FFI; use test\\double; interface itest {} interface itest_ptr {} class test { const __%s__ = 1; const __LP64__ = 1; const __GNUC_VA_LIST = 1; const __GNUC__ = 4; const __GNUC_MINOR__ = 2; const __STDC__ = 1; const A1 = (1) + 0 /* enum A */; const A2 = (self::A1) + 0 /* enum A */; const A3 = (2) + 0 /* enum A */; const B1 = (1) + 0 /* typedefenum B */; const B2 = (self::B1) + 0 /* typedefenum B */; const B3 = ((self::B1 | self::B2)) + 0 /* typedefenum B */; const B4 = ((self::B1 | self::B2)) + 1 /* typedefenum B */; public static function ffi(?string $pathToSoFile = testFFI::SOFILE): testFFI { return new testFFI($pathToSoFile); } public static function sizeof($classOrObject): int { return testFFI::sizeof($classOrObject); } } class testFFI { const SOFILE = \'%s\'; const TYPES_DEF = \'enum A { A1 = 1, A2 = A1, A3 = 2, }; typedef enum { B1 = 1, B2 = B1, B3 = (B1 | B2), B4, } B; \'; const HEADER_DEF = self::TYPES_DEF . \'\'; private FFI $ffi; private static FFI $staticFFI; private static \\WeakMap $__arrayWeakMap; private array $__literalStrings = []; public function __construct(?string $pathToSoFile = self::SOFILE) { $this->ffi = FFI::cdef(self::HEADER_DEF, $pathToSoFile); } public static function cast(itest $from, string $to): itest { if (!is_a($to, itest::class, true)) { throw new \\LogicException("Cannot cast to a non-wrapper type"); } return new $to(self::$staticFFI->cast($to::getType(), $from->getData())); } public static function makeArray(string $class, int|array $elements): itest { $type = $class::getType(); if (substr($type, -1) !== "*") { throw new \\LogicException("Attempting to make a non-pointer element into an array"); } if (is_int($elements)) { $cdata = self::$staticFFI->new(substr($type, 0, -1) . "[$elements]"); } else { $cdata = self::$staticFFI->new(substr($type, 0, -1) . "[" . count($elements) . "]"); foreach ($elements as $key => $raw) { $cdata[$key] = \\is_scalar($raw) ? \\is_int($raw) && $type === "char*" ? \\chr($raw) : $raw : $raw->getData(); } } $object = new $class(self::$staticFFI->cast($type, \\FFI::addr($cdata))); self::$__arrayWeakMap[$object] = $cdata; return $object; } public static function sizeof($classOrObject): int { if (is_object($classOrObject) && $classOrObject instanceof itest) { return FFI::sizeof($classOrObject->getData()); } elseif (is_a($classOrObject, itest::class, true)) { return FFI::sizeof(self::$staticFFI->type($classOrObject::getType())); } else { throw new \\LogicException("Unknown class/object passed to sizeof()"); } } public function getFFI(): FFI { return $this->ffi; } public function __get(string $name) { switch($name) { default: return $this->ffi->$name; } } public function __set(string $name, $value) { switch($name) { default: return $this->ffi->$name; } } public function __allocCachedString(string $str): FFI\\CData { return $this->__literalStrings[$str] ??= string_::ownedZero($str)->getData(); } } class string_ implements itest, itest_ptr, \\ArrayAccess { private FFI\\CData $data; public function __construct(FFI\\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\\CData { return $this->data; } public function equals(string_ $other): bool { return $this->data == $other->data; } public function addr(): string_ptr { return new string_ptr(FFI::addr($this->data)); } public function deref(int $n = 0): int { return \\ord($this->data[$n]); } #[\\ReturnTypeWillChange] public function offsetGet($offset): int { return $this->deref($offset); } #[\\ReturnTypeWillChange] public function offsetExists($offset): bool { return !FFI::isNull($this->data); } #[\\ReturnTypeWillChange] public function offsetUnset($offset): void { throw new \\Error("Cannot unset C structures"); } #[\\ReturnTypeWillChange] public function offsetSet($offset, $value): void { $this->data[$offset] = \\chr($value); } public static function array(int $size = 1): self { return testFFI::makeArray(self::class, $size); } /** @return int[] */ public function toArray(?int $length = null): array { $ret = []; if ($length === null) { $i = 0; while ("\\0" !== $cur = $this->data[$i++]) { $ret[] = \\ord($cur); } } else { for ($i = 0; $i < $length; ++$i) { $ret[] = \\ord($this->data[$i]); } } return $ret; } public function toString(?int $length = null): string { return $length === null ? FFI::string($this->data) : FFI::string($this->data, $length); } public static function persistent(string $string): self { $str = new self(FFI::cdef()->new("char[" . \\strlen($string) . "]", false)); FFI::memcpy($str->data, $string, \\strlen($string)); return $str; } public static function owned(string $string): self { $str = new self(FFI::cdef()->new("char[" . \\strlen($string) . "]", true)); FFI::memcpy($str->data, $string, \\strlen($string)); return $str; } public static function persistentZero(string $string): self { return self::persistent("$string\\0"); } public static function ownedZero(string $string): self { return self::owned("$string\\0"); } public function set(int | void_ptr | string_ $value): void { if (\\is_scalar($value)) { $this->data[0] = \\chr($value); } else { FFI::addr($this->data)[0] = $value->getData(); } } public static function getType(): string { return \'char*\'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class string_ptr implements itest, itest_ptr, \\ArrayAccess { private FFI\\CData $data; public function __construct(FFI\\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\\CData { return $this->data; } public function equals(string_ptr $other): bool { return $this->data == $other->data; } public function addr(): string_ptr_ptr { return new string_ptr_ptr(FFI::addr($this->data)); } public function deref(int $n = 0): string_ { return new string_($this->data[$n]); } #[\\ReturnTypeWillChange] public function offsetGet($offset): string_ { return $this->deref($offset); } #[\\ReturnTypeWillChange] public function offsetExists($offset): bool { return !FFI::isNull($this->data); } #[\\ReturnTypeWillChange] public function offsetUnset($offset): void { throw new \\Error("Cannot unset C structures"); } #[\\ReturnTypeWillChange] public function offsetSet($offset, $value): void { $this->data[$offset] = $value->getData(); } public static function array(int $size = 1): self { return testFFI::makeArray(self::class, $size); } /** @return string_[] */ public function toArray(?int $length = null): array { $ret = []; if ($length === null) { $i = 0; while (null !== $cur = $this->data[$i++]) { $ret[] = new string_($cur); } } else { for ($i = 0; $i < $length; ++$i) { $ret[] = new string_($this->data[$i]); } } return $ret; } public function set(void_ptr | string_ptr $value): void { FFI::addr($this->data)[0] = $value->getData(); } public static function getType(): string { return \'char**\'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class string_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class string_ptr_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class void_ptr implements itest, itest_ptr { private FFI\\CData $data; public function __construct(FFI\\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\\CData { return $this->data; } public function equals(void_ptr $other): bool { return $this->data == $other->data; } public function addr(): void_ptr_ptr { return new void_ptr_ptr(FFI::addr($this->data)); } public function set(itest_ptr $value): void { FFI::addr($this->data)[0] = $value->getData(); } public static function getType(): string { return \'void*\'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class void_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class void_ptr_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class void_ptr_ptr_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class int_ptr implements itest, itest_ptr, \\ArrayAccess { private FFI\\CData $data; public function __construct(FFI\\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\\CData { return $this->data; } public function equals(int_ptr $other): bool { return $this->data == $other->data; } public function addr(): int_ptr_ptr { return new int_ptr_ptr(FFI::addr($this->data)); } public function deref(int $n = 0): int { return $this->data[$n]; } #[\\ReturnTypeWillChange] public function offsetGet($offset): int { return $this->deref($offset); } #[\\ReturnTypeWillChange] public function offsetExists($offset): bool { return !FFI::isNull($this->data); } #[\\ReturnTypeWillChange] public function offsetUnset($offset): void { throw new \\Error("Cannot unset C structures"); } #[\\ReturnTypeWillChange] public function offsetSet($offset, $value): void { $this->data[$offset] = $value; } public static function array(int $size = 1): self { return testFFI::makeArray(self::class, $size); } /** @return int[] */ public function toArray(int $length): array { $ret = []; for ($i = 0; $i < $length; ++$i) { $ret[] = ($this->data[$i]); } return $ret; } public function set(int | void_ptr | int_ptr $value): void { if (\\is_scalar($value)) { $this->data[0] = $value; } else { FFI::addr($this->data)[0] = $value->getData(); } } public static function getType(): string { return \'int*\'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class int_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class int_ptr_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class int_ptr_ptr_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} (function() { self::$staticFFI = \\FFI::cdef(testFFI::TYPES_DEF); self::$__arrayWeakMap = new \\WeakMap; })->bindTo(null, testFFI::class)();'; protected FFIMe $lib; protected Printer $printer; public function setUp(): void { $this->lib = new class( PHP_OS_FAMILY === "Darwin" ? "/usr/lib/libSystem.B.dylib" : "/lib/x86_64-linux-gnu/libc.so.6", [ __DIR__, __DIR__ . '/../include' ] ) extends FFIMe { // Bypass filtering for tests protected function filterSymbolDeclarations(): void {} }; } public function tearDown(): void { @unlink(__DIR__ . '/enum_self_referencesTest.result.php'); } /** * @textdox Test enum self references */ public function testCodeGen() { $this->lib->include(__DIR__ . '/enum_self_referencesTest.h'); $this->lib->codeGen("test\\test", __DIR__ . '/enum_self_referencesTest.result.php'); $this->assertFileExists(__DIR__ . '/enum_self_referencesTest.result.php'); $this->assertStringMatchesFormat(self::EXPECTED, trim(file_get_contents(__DIR__ . '/enum_self_referencesTest.result.php'))); } }
php
MIT
0b7fb71209b192e55a61ec2fb33a932a561dd82a
2026-01-05T04:39:07.148223Z
false
ircmaxell/FFIMe
https://github.com/ircmaxell/FFIMe/blob/0b7fb71209b192e55a61ec2fb33a932a561dd82a/test/generated/basic_typedefsTest.php
test/generated/basic_typedefsTest.php
<?php declare(strict_types=1); namespace FFIMe\Test; use FFIMe\FFIMe; use PHPUnit\Framework\TestCase; /** * Note: this is a generated file, do not edit this!!! */ class basic_typedefsTest extends TestCase { const EXPECTED = '<?php namespace %s; use FFI; use test\\double; interface itest {} interface itest_ptr {} class test { const __%s__ = 1; const __LP64__ = 1; const __GNUC_VA_LIST = 1; const __GNUC__ = 4; const __GNUC_MINOR__ = 2; const __STDC__ = 1; public static function ffi(?string $pathToSoFile = testFFI::SOFILE): testFFI { return new testFFI($pathToSoFile); } public static function sizeof($classOrObject): int { return testFFI::sizeof($classOrObject); } } class testFFI { const SOFILE = \'%s\'; const TYPES_DEF = \'typedef long int intmax_t; typedef unsigned long int uintmax_t; \'; const HEADER_DEF = self::TYPES_DEF . \'intmax_t foo(intmax_t a); extern uintmax_t blah(); \'; private FFI $ffi; private static FFI $staticFFI; private static \\WeakMap $__arrayWeakMap; private array $__literalStrings = []; public function __construct(?string $pathToSoFile = self::SOFILE) { $this->ffi = FFI::cdef(self::HEADER_DEF, $pathToSoFile); } public static function cast(itest $from, string $to): itest { if (!is_a($to, itest::class, true)) { throw new \\LogicException("Cannot cast to a non-wrapper type"); } return new $to(self::$staticFFI->cast($to::getType(), $from->getData())); } public static function makeArray(string $class, int|array $elements): itest { $type = $class::getType(); if (substr($type, -1) !== "*") { throw new \\LogicException("Attempting to make a non-pointer element into an array"); } if (is_int($elements)) { $cdata = self::$staticFFI->new(substr($type, 0, -1) . "[$elements]"); } else { $cdata = self::$staticFFI->new(substr($type, 0, -1) . "[" . count($elements) . "]"); foreach ($elements as $key => $raw) { $cdata[$key] = \\is_scalar($raw) ? \\is_int($raw) && $type === "char*" ? \\chr($raw) : $raw : $raw->getData(); } } $object = new $class(self::$staticFFI->cast($type, \\FFI::addr($cdata))); self::$__arrayWeakMap[$object] = $cdata; return $object; } public static function sizeof($classOrObject): int { if (is_object($classOrObject) && $classOrObject instanceof itest) { return FFI::sizeof($classOrObject->getData()); } elseif (is_a($classOrObject, itest::class, true)) { return FFI::sizeof(self::$staticFFI->type($classOrObject::getType())); } else { throw new \\LogicException("Unknown class/object passed to sizeof()"); } } public function getFFI(): FFI { return $this->ffi; } public function __get(string $name) { switch($name) { default: return $this->ffi->$name; } } public function __set(string $name, $value) { switch($name) { default: return $this->ffi->$name; } } public function __allocCachedString(string $str): FFI\\CData { return $this->__literalStrings[$str] ??= string_::ownedZero($str)->getData(); } public function foo(int $a): int { $result = $this->ffi->foo($a); return $result; } public function blah(): int { $result = $this->ffi->blah(); return $result; } } class string_ implements itest, itest_ptr, \\ArrayAccess { private FFI\\CData $data; public function __construct(FFI\\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\\CData { return $this->data; } public function equals(string_ $other): bool { return $this->data == $other->data; } public function addr(): string_ptr { return new string_ptr(FFI::addr($this->data)); } public function deref(int $n = 0): int { return \\ord($this->data[$n]); } #[\\ReturnTypeWillChange] public function offsetGet($offset): int { return $this->deref($offset); } #[\\ReturnTypeWillChange] public function offsetExists($offset): bool { return !FFI::isNull($this->data); } #[\\ReturnTypeWillChange] public function offsetUnset($offset): void { throw new \\Error("Cannot unset C structures"); } #[\\ReturnTypeWillChange] public function offsetSet($offset, $value): void { $this->data[$offset] = \\chr($value); } public static function array(int $size = 1): self { return testFFI::makeArray(self::class, $size); } /** @return int[] */ public function toArray(?int $length = null): array { $ret = []; if ($length === null) { $i = 0; while ("\\0" !== $cur = $this->data[$i++]) { $ret[] = \\ord($cur); } } else { for ($i = 0; $i < $length; ++$i) { $ret[] = \\ord($this->data[$i]); } } return $ret; } public function toString(?int $length = null): string { return $length === null ? FFI::string($this->data) : FFI::string($this->data, $length); } public static function persistent(string $string): self { $str = new self(FFI::cdef()->new("char[" . \\strlen($string) . "]", false)); FFI::memcpy($str->data, $string, \\strlen($string)); return $str; } public static function owned(string $string): self { $str = new self(FFI::cdef()->new("char[" . \\strlen($string) . "]", true)); FFI::memcpy($str->data, $string, \\strlen($string)); return $str; } public static function persistentZero(string $string): self { return self::persistent("$string\\0"); } public static function ownedZero(string $string): self { return self::owned("$string\\0"); } public function set(int | void_ptr | string_ $value): void { if (\\is_scalar($value)) { $this->data[0] = \\chr($value); } else { FFI::addr($this->data)[0] = $value->getData(); } } public static function getType(): string { return \'char*\'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class string_ptr implements itest, itest_ptr, \\ArrayAccess { private FFI\\CData $data; public function __construct(FFI\\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\\CData { return $this->data; } public function equals(string_ptr $other): bool { return $this->data == $other->data; } public function addr(): string_ptr_ptr { return new string_ptr_ptr(FFI::addr($this->data)); } public function deref(int $n = 0): string_ { return new string_($this->data[$n]); } #[\\ReturnTypeWillChange] public function offsetGet($offset): string_ { return $this->deref($offset); } #[\\ReturnTypeWillChange] public function offsetExists($offset): bool { return !FFI::isNull($this->data); } #[\\ReturnTypeWillChange] public function offsetUnset($offset): void { throw new \\Error("Cannot unset C structures"); } #[\\ReturnTypeWillChange] public function offsetSet($offset, $value): void { $this->data[$offset] = $value->getData(); } public static function array(int $size = 1): self { return testFFI::makeArray(self::class, $size); } /** @return string_[] */ public function toArray(?int $length = null): array { $ret = []; if ($length === null) { $i = 0; while (null !== $cur = $this->data[$i++]) { $ret[] = new string_($cur); } } else { for ($i = 0; $i < $length; ++$i) { $ret[] = new string_($this->data[$i]); } } return $ret; } public function set(void_ptr | string_ptr $value): void { FFI::addr($this->data)[0] = $value->getData(); } public static function getType(): string { return \'char**\'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class string_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class string_ptr_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class void_ptr implements itest, itest_ptr { private FFI\\CData $data; public function __construct(FFI\\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\\CData { return $this->data; } public function equals(void_ptr $other): bool { return $this->data == $other->data; } public function addr(): void_ptr_ptr { return new void_ptr_ptr(FFI::addr($this->data)); } public function set(itest_ptr $value): void { FFI::addr($this->data)[0] = $value->getData(); } public static function getType(): string { return \'void*\'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class void_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class void_ptr_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class void_ptr_ptr_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class long_int_ptr implements itest, itest_ptr, \\ArrayAccess { private FFI\\CData $data; public function __construct(FFI\\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\\CData { return $this->data; } public function equals(long_int_ptr $other): bool { return $this->data == $other->data; } public function addr(): long_int_ptr_ptr { return new long_int_ptr_ptr(FFI::addr($this->data)); } public function deref(int $n = 0): int { return $this->data[$n]; } #[\\ReturnTypeWillChange] public function offsetGet($offset): int { return $this->deref($offset); } #[\\ReturnTypeWillChange] public function offsetExists($offset): bool { return !FFI::isNull($this->data); } #[\\ReturnTypeWillChange] public function offsetUnset($offset): void { throw new \\Error("Cannot unset C structures"); } #[\\ReturnTypeWillChange] public function offsetSet($offset, $value): void { $this->data[$offset] = $value; } public static function array(int $size = 1): self { return testFFI::makeArray(self::class, $size); } /** @return int[] */ public function toArray(int $length): array { $ret = []; for ($i = 0; $i < $length; ++$i) { $ret[] = ($this->data[$i]); } return $ret; } public function set(int | void_ptr | long_int_ptr $value): void { if (\\is_scalar($value)) { $this->data[0] = $value; } else { FFI::addr($this->data)[0] = $value->getData(); } } public static function getType(): string { return \'long_int*\'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class long_int_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class long_int_ptr_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class long_int_ptr_ptr_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class unsigned_long_int_ptr implements itest, itest_ptr, \\ArrayAccess { private FFI\\CData $data; public function __construct(FFI\\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\\CData { return $this->data; } public function equals(unsigned_long_int_ptr $other): bool { return $this->data == $other->data; } public function addr(): unsigned_long_int_ptr_ptr { return new unsigned_long_int_ptr_ptr(FFI::addr($this->data)); } public function deref(int $n = 0): int { return $this->data[$n]; } #[\\ReturnTypeWillChange] public function offsetGet($offset): int { return $this->deref($offset); } #[\\ReturnTypeWillChange] public function offsetExists($offset): bool { return !FFI::isNull($this->data); } #[\\ReturnTypeWillChange] public function offsetUnset($offset): void { throw new \\Error("Cannot unset C structures"); } #[\\ReturnTypeWillChange] public function offsetSet($offset, $value): void { $this->data[$offset] = $value; } public static function array(int $size = 1): self { return testFFI::makeArray(self::class, $size); } /** @return int[] */ public function toArray(int $length): array { $ret = []; for ($i = 0; $i < $length; ++$i) { $ret[] = ($this->data[$i]); } return $ret; } public function set(int | void_ptr | unsigned_long_int_ptr $value): void { if (\\is_scalar($value)) { $this->data[0] = $value; } else { FFI::addr($this->data)[0] = $value->getData(); } } public static function getType(): string { return \'unsigned_long_int*\'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class unsigned_long_int_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class unsigned_long_int_ptr_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} class unsigned_long_int_ptr_ptr_ptr_ptr implements itest, itest_ptr, \\ArrayAccess {%a} (function() { self::$staticFFI = \\FFI::cdef(testFFI::TYPES_DEF); self::$__arrayWeakMap = new \\WeakMap; })->bindTo(null, testFFI::class)(); \\class_alias(long_int_ptr::class, intmax_t_ptr::class); \\class_alias(long_int_ptr_ptr::class, intmax_t_ptr_ptr::class); \\class_alias(long_int_ptr_ptr_ptr::class, intmax_t_ptr_ptr_ptr::class); \\class_alias(long_int_ptr_ptr_ptr_ptr::class, intmax_t_ptr_ptr_ptr_ptr::class); \\class_alias(unsigned_long_int_ptr::class, uintmax_t_ptr::class); \\class_alias(unsigned_long_int_ptr_ptr::class, uintmax_t_ptr_ptr::class); \\class_alias(unsigned_long_int_ptr_ptr_ptr::class, uintmax_t_ptr_ptr_ptr::class); \\class_alias(unsigned_long_int_ptr_ptr_ptr_ptr::class, uintmax_t_ptr_ptr_ptr_ptr::class);'; protected FFIMe $lib; protected Printer $printer; public function setUp(): void { $this->lib = new class( PHP_OS_FAMILY === "Darwin" ? "/usr/lib/libSystem.B.dylib" : "/lib/x86_64-linux-gnu/libc.so.6", [ __DIR__, __DIR__ . '/../include' ] ) extends FFIMe { // Bypass filtering for tests protected function filterSymbolDeclarations(): void {} }; } public function tearDown(): void { @unlink(__DIR__ . '/basic_typedefsTest.result.php'); } /** * @textdox Test basic parsing of typedefs */ public function testCodeGen() { $this->lib->include(__DIR__ . '/basic_typedefsTest.h'); $this->lib->codeGen("test\\test", __DIR__ . '/basic_typedefsTest.result.php'); $this->assertFileExists(__DIR__ . '/basic_typedefsTest.result.php'); $this->assertStringMatchesFormat(self::EXPECTED, trim(file_get_contents(__DIR__ . '/basic_typedefsTest.result.php'))); } }
php
MIT
0b7fb71209b192e55a61ec2fb33a932a561dd82a
2026-01-05T04:39:07.148223Z
false
ircmaxell/FFIMe
https://github.com/ircmaxell/FFIMe/blob/0b7fb71209b192e55a61ec2fb33a932a561dd82a/examples/03-multiple-headers/example.php
examples/03-multiple-headers/example.php
<?php require __DIR__ . '/../../vendor/autoload.php'; $libc = (new FFIMe\FFIMe(\FFIMe\FFIMe::LIBC)) ->include("stdio.h") ->include("ctype.h") ->build(); // from stdio.h $libc->printf("test\n"); // from ctype.h if ($libc->isalpha(ord("h"))) { echo "It's alpha\n"; } else { echo "It's not alpha\n"; }
php
MIT
0b7fb71209b192e55a61ec2fb33a932a561dd82a
2026-01-05T04:39:07.148223Z
false
ircmaxell/FFIMe
https://github.com/ircmaxell/FFIMe/blob/0b7fb71209b192e55a61ec2fb33a932a561dd82a/examples/02-stdio-codegen/example.php
examples/02-stdio-codegen/example.php
<?php require __DIR__ . '/../../vendor/autoload.php'; (new FFIMe\FFIMe(\FFIMe\FFIMe::LIBC)) ->include("stdio.h") ->codeGen('stdio\\stdio', __DIR__ . '/stdio.php'); require __DIR__ . '/stdio.php'; $libc = stdio\stdio::ffi(); $libc->printf("test\n");
php
MIT
0b7fb71209b192e55a61ec2fb33a932a561dd82a
2026-01-05T04:39:07.148223Z
false
ircmaxell/FFIMe
https://github.com/ircmaxell/FFIMe/blob/0b7fb71209b192e55a61ec2fb33a932a561dd82a/examples/02-stdio-codegen/stdio.php
examples/02-stdio-codegen/stdio.php
<?php namespace stdio; use FFI; use stdio\double; interface istdio {} interface istdio_ptr {} /** * @property struct___sFILE_ptr $__stdinp * @property struct___sFILE_ptr $__stdoutp * @property struct___sFILE_ptr $__stderrp * @property int $sys_nerr */ class stdio { const __x86_64__ = 1; const __LP64__ = 1; const __GNUC_VA_LIST = 1; const __GNUC__ = 4; const __GNUC_MINOR__ = 2; const __STDC__ = 1; const __DARWIN_ONLY_64_BIT_INO_T = 0; const __DARWIN_ONLY_UNIX_CONFORMANCE = 1; const __DARWIN_ONLY_VERS_1050 = 0; const __DARWIN_UNIX03 = 1; const __DARWIN_64_BIT_INO_T = 1; const __DARWIN_VERS_1050 = 1; const __DARWIN_NON_CANCELABLE = 0; const __DARWIN_C_ANSI = 010000; const __DARWIN_C_FULL = 900000; const __STDC_WANT_LIB_EXT1__ = 1; const __DARWIN_NO_LONG_LONG = 0; const _DARWIN_FEATURE_64_BIT_INODE = 1; const _DARWIN_FEATURE_ONLY_UNIX_CONFORMANCE = 1; const _DARWIN_FEATURE_UNIX_CONFORMANCE = 3; const __has_ptrcheck = 0; const __API_TO_BE_DEPRECATED = 100000; const __API_TO_BE_DEPRECATED_MACOS = 100000; const __API_TO_BE_DEPRECATED_IOS = 100000; const __API_TO_BE_DEPRECATED_TVOS = 100000; const __API_TO_BE_DEPRECATED_WATCHOS = 100000; const __API_TO_BE_DEPRECATED_MACCATALYST = 100000; const __API_TO_BE_DEPRECATED_DRIVERKIT = 100000; const __MAC_10_0 = 1000; const __MAC_10_1 = 1010; const __MAC_10_2 = 1020; const __MAC_10_3 = 1030; const __MAC_10_4 = 1040; const __MAC_10_5 = 1050; const __MAC_10_6 = 1060; const __MAC_10_7 = 1070; const __MAC_10_8 = 1080; const __MAC_10_9 = 1090; const __MAC_10_10 = 101000; const __MAC_10_10_2 = 101002; const __MAC_10_10_3 = 101003; const __MAC_10_11 = 101100; const __MAC_10_11_2 = 101102; const __MAC_10_11_3 = 101103; const __MAC_10_11_4 = 101104; const __MAC_10_12 = 101200; const __MAC_10_12_1 = 101201; const __MAC_10_12_2 = 101202; const __MAC_10_12_4 = 101204; const __MAC_10_13 = 101300; const __MAC_10_13_1 = 101301; const __MAC_10_13_2 = 101302; const __MAC_10_13_4 = 101304; const __MAC_10_14 = 101400; const __MAC_10_14_1 = 101401; const __MAC_10_14_4 = 101404; const __MAC_10_14_6 = 101406; const __MAC_10_15 = 101500; const __MAC_10_15_1 = 101501; const __MAC_10_15_4 = 101504; const __MAC_10_16 = 101600; const __MAC_11_0 = 110000; const __MAC_11_1 = 110100; const __MAC_11_3 = 110300; const __MAC_11_4 = 110400; const __MAC_11_5 = 110500; const __MAC_11_6 = 110600; const __MAC_12_0 = 120000; const __MAC_12_1 = 120100; const __MAC_12_2 = 120200; const __MAC_12_3 = 120300; const __MAC_13_0 = 130000; const __MAC_13_1 = 130100; const __MAC_13_2 = 130200; const __MAC_13_3 = 130300; const __IPHONE_2_0 = 20000; const __IPHONE_2_1 = 20100; const __IPHONE_2_2 = 20200; const __IPHONE_3_0 = 30000; const __IPHONE_3_1 = 30100; const __IPHONE_3_2 = 30200; const __IPHONE_4_0 = 40000; const __IPHONE_4_1 = 40100; const __IPHONE_4_2 = 40200; const __IPHONE_4_3 = 40300; const __IPHONE_5_0 = 50000; const __IPHONE_5_1 = 50100; const __IPHONE_6_0 = 60000; const __IPHONE_6_1 = 60100; const __IPHONE_7_0 = 70000; const __IPHONE_7_1 = 70100; const __IPHONE_8_0 = 80000; const __IPHONE_8_1 = 80100; const __IPHONE_8_2 = 80200; const __IPHONE_8_3 = 80300; const __IPHONE_8_4 = 80400; const __IPHONE_9_0 = 90000; const __IPHONE_9_1 = 90100; const __IPHONE_9_2 = 90200; const __IPHONE_9_3 = 90300; const __IPHONE_10_0 = 100000; const __IPHONE_10_1 = 100100; const __IPHONE_10_2 = 100200; const __IPHONE_10_3 = 100300; const __IPHONE_11_0 = 110000; const __IPHONE_11_1 = 110100; const __IPHONE_11_2 = 110200; const __IPHONE_11_3 = 110300; const __IPHONE_11_4 = 110400; const __IPHONE_12_0 = 120000; const __IPHONE_12_1 = 120100; const __IPHONE_12_2 = 120200; const __IPHONE_12_3 = 120300; const __IPHONE_12_4 = 120400; const __IPHONE_13_0 = 130000; const __IPHONE_13_1 = 130100; const __IPHONE_13_2 = 130200; const __IPHONE_13_3 = 130300; const __IPHONE_13_4 = 130400; const __IPHONE_13_5 = 130500; const __IPHONE_13_6 = 130600; const __IPHONE_13_7 = 130700; const __IPHONE_14_0 = 140000; const __IPHONE_14_1 = 140100; const __IPHONE_14_2 = 140200; const __IPHONE_14_3 = 140300; const __IPHONE_14_5 = 140500; const __IPHONE_14_6 = 140600; const __IPHONE_14_7 = 140700; const __IPHONE_14_8 = 140800; const __IPHONE_15_0 = 150000; const __IPHONE_15_1 = 150100; const __IPHONE_15_2 = 150200; const __IPHONE_15_3 = 150300; const __IPHONE_15_4 = 150400; const __IPHONE_16_0 = 160000; const __IPHONE_16_1 = 160100; const __IPHONE_16_2 = 160200; const __IPHONE_16_3 = 160300; const __IPHONE_16_4 = 160400; const __TVOS_9_0 = 90000; const __TVOS_9_1 = 90100; const __TVOS_9_2 = 90200; const __TVOS_10_0 = 100000; const __TVOS_10_0_1 = 100001; const __TVOS_10_1 = 100100; const __TVOS_10_2 = 100200; const __TVOS_11_0 = 110000; const __TVOS_11_1 = 110100; const __TVOS_11_2 = 110200; const __TVOS_11_3 = 110300; const __TVOS_11_4 = 110400; const __TVOS_12_0 = 120000; const __TVOS_12_1 = 120100; const __TVOS_12_2 = 120200; const __TVOS_12_3 = 120300; const __TVOS_12_4 = 120400; const __TVOS_13_0 = 130000; const __TVOS_13_2 = 130200; const __TVOS_13_3 = 130300; const __TVOS_13_4 = 130400; const __TVOS_14_0 = 140000; const __TVOS_14_1 = 140100; const __TVOS_14_2 = 140200; const __TVOS_14_3 = 140300; const __TVOS_14_5 = 140500; const __TVOS_14_6 = 140600; const __TVOS_14_7 = 140700; const __TVOS_15_0 = 150000; const __TVOS_15_1 = 150100; const __TVOS_15_2 = 150200; const __TVOS_15_3 = 150300; const __TVOS_15_4 = 150400; const __TVOS_16_0 = 160000; const __TVOS_16_1 = 160100; const __TVOS_16_2 = 160200; const __TVOS_16_3 = 160300; const __TVOS_16_4 = 160400; const __WATCHOS_1_0 = 10000; const __WATCHOS_2_0 = 20000; const __WATCHOS_2_1 = 20100; const __WATCHOS_2_2 = 20200; const __WATCHOS_3_0 = 30000; const __WATCHOS_3_1 = 30100; const __WATCHOS_3_1_1 = 30101; const __WATCHOS_3_2 = 30200; const __WATCHOS_4_0 = 40000; const __WATCHOS_4_1 = 40100; const __WATCHOS_4_2 = 40200; const __WATCHOS_4_3 = 40300; const __WATCHOS_5_0 = 50000; const __WATCHOS_5_1 = 50100; const __WATCHOS_5_2 = 50200; const __WATCHOS_5_3 = 50300; const __WATCHOS_6_0 = 60000; const __WATCHOS_6_1 = 60100; const __WATCHOS_6_2 = 60200; const __WATCHOS_7_0 = 70000; const __WATCHOS_7_1 = 70100; const __WATCHOS_7_2 = 70200; const __WATCHOS_7_3 = 70300; const __WATCHOS_7_4 = 70400; const __WATCHOS_7_5 = 70500; const __WATCHOS_7_6 = 70600; const __WATCHOS_8_0 = 80000; const __WATCHOS_8_1 = 80100; const __WATCHOS_8_3 = 80300; const __WATCHOS_8_4 = 80400; const __WATCHOS_8_5 = 80500; const __WATCHOS_9_0 = 90000; const __WATCHOS_9_1 = 90100; const __WATCHOS_9_2 = 90200; const __WATCHOS_9_3 = 90300; const __WATCHOS_9_4 = 90400; const MAC_OS_X_VERSION_10_0 = 1000; const MAC_OS_X_VERSION_10_1 = 1010; const MAC_OS_X_VERSION_10_2 = 1020; const MAC_OS_X_VERSION_10_3 = 1030; const MAC_OS_X_VERSION_10_4 = 1040; const MAC_OS_X_VERSION_10_5 = 1050; const MAC_OS_X_VERSION_10_6 = 1060; const MAC_OS_X_VERSION_10_7 = 1070; const MAC_OS_X_VERSION_10_8 = 1080; const MAC_OS_X_VERSION_10_9 = 1090; const MAC_OS_X_VERSION_10_10 = 101000; const MAC_OS_X_VERSION_10_10_2 = 101002; const MAC_OS_X_VERSION_10_10_3 = 101003; const MAC_OS_X_VERSION_10_11 = 101100; const MAC_OS_X_VERSION_10_11_2 = 101102; const MAC_OS_X_VERSION_10_11_3 = 101103; const MAC_OS_X_VERSION_10_11_4 = 101104; const MAC_OS_X_VERSION_10_12 = 101200; const MAC_OS_X_VERSION_10_12_1 = 101201; const MAC_OS_X_VERSION_10_12_2 = 101202; const MAC_OS_X_VERSION_10_12_4 = 101204; const MAC_OS_X_VERSION_10_13 = 101300; const MAC_OS_X_VERSION_10_13_1 = 101301; const MAC_OS_X_VERSION_10_13_2 = 101302; const MAC_OS_X_VERSION_10_13_4 = 101304; const MAC_OS_X_VERSION_10_14 = 101400; const MAC_OS_X_VERSION_10_14_1 = 101401; const MAC_OS_X_VERSION_10_14_4 = 101404; const MAC_OS_X_VERSION_10_14_6 = 101406; const MAC_OS_X_VERSION_10_15 = 101500; const MAC_OS_X_VERSION_10_15_1 = 101501; const MAC_OS_X_VERSION_10_16 = 101600; const MAC_OS_VERSION_11_0 = 110000; const MAC_OS_VERSION_12_0 = 120000; const MAC_OS_VERSION_13_0 = 130000; const __DRIVERKIT_19_0 = 190000; const __DRIVERKIT_20_0 = 200000; const __DRIVERKIT_21_0 = 210000; const __PTHREAD_SIZE__ = 8176; const __PTHREAD_ATTR_SIZE__ = 56; const __PTHREAD_MUTEXATTR_SIZE__ = 8; const __PTHREAD_MUTEX_SIZE__ = 56; const __PTHREAD_CONDATTR_SIZE__ = 8; const __PTHREAD_COND_SIZE__ = 40; const __PTHREAD_ONCE_SIZE__ = 8; const __PTHREAD_RWLOCK_SIZE__ = 192; const __PTHREAD_RWLOCKATTR_SIZE__ = 16; const __DARWIN_WCHAR_MAX = 0x7fffffff; const _FORTIFY_SOURCE = 2; const RENAME_SECLUDE = 0x00000001; const RENAME_SWAP = 0x00000002; const RENAME_EXCL = 0x00000004; const RENAME_RESERVED1 = 0x00000008; const RENAME_NOFOLLOW_ANY = 0x00000010; const __SLBF = 0x0001; const __SNBF = 0x0002; const __SRD = 0x0004; const __SWR = 0x0008; const __SRW = 0x0010; const __SEOF = 0x0020; const __SERR = 0x0040; const __SMBF = 0x0080; const __SAPP = 0x0100; const __SSTR = 0x0200; const __SOPT = 0x0400; const __SNPT = 0x0800; const __SOFF = 0x1000; const __SMOD = 0x2000; const __SALC = 0x4000; const __SIGN = 0x8000; const _IOFBF = 0; const _IOLBF = 1; const _IONBF = 2; const BUFSIZ = 1024; const FOPEN_MAX = 20; const FILENAME_MAX = 1024; const L_tmpnam = 1024; const TMP_MAX = 308915776; const SEEK_SET = 0; const SEEK_CUR = 1; const SEEK_END = 2; const L_ctermid = 1024; const _USE_FORTIFY_LEVEL = 2; public static function ffi(?string $pathToSoFile = stdioFFI::SOFILE): stdioFFI { return new stdioFFI($pathToSoFile); } public static function sizeof($classOrObject): int { return stdioFFI::sizeof($classOrObject); } } class stdioFFI { const SOFILE = '/usr/lib/libSystem.B.dylib'; const TYPES_DEF = 'typedef signed char __int8_t; typedef unsigned char __uint8_t; typedef short __int16_t; typedef unsigned short __uint16_t; typedef int __int32_t; typedef unsigned int __uint32_t; typedef long long __int64_t; typedef unsigned long long __uint64_t; typedef long __darwin_intptr_t; typedef unsigned int __darwin_natural_t; typedef int __darwin_ct_rune_t; typedef union { char __mbstate8[128]; long long _mbstateL; } __mbstate_t; typedef __mbstate_t __darwin_mbstate_t; typedef long int __darwin_ptrdiff_t; typedef long unsigned int __darwin_size_t; typedef __builtin_va_list __darwin_va_list; typedef int __darwin_wchar_t; typedef __darwin_wchar_t __darwin_rune_t; typedef unsigned int __darwin_wint_t; typedef unsigned long __darwin_clock_t; typedef __uint32_t __darwin_socklen_t; typedef long __darwin_ssize_t; typedef long __darwin_time_t; typedef __int64_t __darwin_blkcnt_t; typedef __int32_t __darwin_blksize_t; typedef __int32_t __darwin_dev_t; typedef unsigned int __darwin_fsblkcnt_t; typedef unsigned int __darwin_fsfilcnt_t; typedef __uint32_t __darwin_gid_t; typedef __uint32_t __darwin_id_t; typedef __uint64_t __darwin_ino64_t; typedef __darwin_ino64_t __darwin_ino_t; typedef __darwin_natural_t __darwin_mach_port_name_t; typedef __darwin_mach_port_name_t __darwin_mach_port_t; typedef __uint16_t __darwin_mode_t; typedef __int64_t __darwin_off_t; typedef __int32_t __darwin_pid_t; typedef __uint32_t __darwin_sigset_t; typedef __int32_t __darwin_suseconds_t; typedef __uint32_t __darwin_uid_t; typedef __uint32_t __darwin_useconds_t; typedef unsigned char __darwin_uuid_t[16]; typedef char __darwin_uuid_string_t[37]; struct __darwin_pthread_handler_rec { void (*__routine)(void *); void *__arg; struct __darwin_pthread_handler_rec *__next; }; struct _opaque_pthread_attr_t { long __sig; char __opaque[56]; }; struct _opaque_pthread_cond_t { long __sig; char __opaque[40]; }; struct _opaque_pthread_condattr_t { long __sig; char __opaque[8]; }; struct _opaque_pthread_mutex_t { long __sig; char __opaque[56]; }; struct _opaque_pthread_mutexattr_t { long __sig; char __opaque[8]; }; struct _opaque_pthread_once_t { long __sig; char __opaque[8]; }; struct _opaque_pthread_rwlock_t { long __sig; char __opaque[192]; }; struct _opaque_pthread_rwlockattr_t { long __sig; char __opaque[16]; }; struct _opaque_pthread_t { long __sig; struct __darwin_pthread_handler_rec *__cleanup_stack; char __opaque[8176]; }; typedef struct _opaque_pthread_attr_t __darwin_pthread_attr_t; typedef struct _opaque_pthread_cond_t __darwin_pthread_cond_t; typedef struct _opaque_pthread_condattr_t __darwin_pthread_condattr_t; typedef unsigned long __darwin_pthread_key_t; typedef struct _opaque_pthread_mutex_t __darwin_pthread_mutex_t; typedef struct _opaque_pthread_mutexattr_t __darwin_pthread_mutexattr_t; typedef struct _opaque_pthread_once_t __darwin_pthread_once_t; typedef struct _opaque_pthread_rwlock_t __darwin_pthread_rwlock_t; typedef struct _opaque_pthread_rwlockattr_t __darwin_pthread_rwlockattr_t; typedef struct _opaque_pthread_t *__darwin_pthread_t; typedef int __darwin_nl_item; typedef int __darwin_wctrans_t; typedef __uint32_t __darwin_wctype_t; typedef unsigned char u_int8_t; typedef unsigned short u_int16_t; typedef unsigned int u_int32_t; typedef unsigned long long u_int64_t; typedef int64_t register_t; typedef __darwin_intptr_t intptr_t; typedef unsigned long uintptr_t; typedef u_int64_t user_addr_t; typedef u_int64_t user_size_t; typedef int64_t user_ssize_t; typedef int64_t user_long_t; typedef u_int64_t user_ulong_t; typedef int64_t user_time_t; typedef int64_t user_off_t; typedef u_int64_t syscall_arg_t; typedef __darwin_va_list va_list; typedef __darwin_off_t fpos_t; struct __sbuf { unsigned char *_base; int _size; }; struct __sFILEX; typedef struct __sFILE { unsigned char *_p; int _r; int _w; short _flags; short _file; struct __sbuf _bf; int _lbfsize; void *_cookie; int (*_close)(void *); int (*_read)(void *, char *, int); fpos_t (*_seek)(void *, fpos_t, int); int (*_write)(void *, char *, int); struct __sbuf _ub; struct __sFILEX *_extra; int _ur; unsigned char _ubuf[3]; unsigned char _nbuf[1]; struct __sbuf _lb; int _blksize; fpos_t _offset; } FILE; typedef __darwin_off_t off_t; typedef __darwin_ssize_t ssize_t; '; const HEADER_DEF = self::TYPES_DEF . 'int renameat(int, char *, int, char *); int renamex_np(char *, char *, unsigned int); int renameatx_np(int, char *, int, char *, unsigned int); extern FILE *__stdinp; extern FILE *__stdoutp; extern FILE *__stderrp; void clearerr(FILE *); int fclose(FILE *); int feof(FILE *); int ferror(FILE *); int fflush(FILE *); int fgetc(FILE *); int fgetpos(FILE *, fpos_t *); char *fgets(char *, int, FILE *); FILE *fopen(char *__filename, char *__mode) __asm__ ("_fopen"); int fprintf(FILE *, char *, ...); int fputc(int, FILE *); int fputs(char *, FILE *) __asm__ ("_fputs"); size_t fread(void *__ptr, size_t __size, size_t __nitems, FILE *__stream); FILE *freopen(char *, char *, FILE *) __asm__ ("_freopen"); int fscanf(FILE *, char *, ...); int fseek(FILE *, long, int); int fsetpos(FILE *, fpos_t *); long ftell(FILE *); size_t fwrite(void *__ptr, size_t __size, size_t __nitems, FILE *__stream) __asm__ ("_fwrite"); int getc(FILE *); int getchar(void); __attribute__((__deprecated__)) char *gets(char *); void perror(char *); int printf(char *, ...); int putc(int, FILE *); int putchar(int); int puts(char *); int remove(char *); int rename(char *__old, char *__new); void rewind(FILE *); int scanf(char *, ...); void setbuf(FILE *, char *); int setvbuf(FILE *, char *, int, size_t); __attribute__((__deprecated__)) int sprintf(char *, char *, ...); int sscanf(char *, char *, ...); FILE *tmpfile(void); __attribute__((__deprecated__)) char *tmpnam(char *); int ungetc(int, FILE *); int vfprintf(FILE *, char *, va_list); int vprintf(char *, va_list); __attribute__((__deprecated__)) int vsprintf(char *, char *, va_list); char *ctermid(char *); FILE *fdopen(int, char *) __asm__ ("_fdopen"); int fileno(FILE *); int pclose(FILE *); FILE *popen(char *, char *) __asm__ ("_popen"); int __srget(FILE *); int __svfscanf(FILE *, char *, va_list); int __swbuf(int, FILE *); void flockfile(FILE *); int ftrylockfile(FILE *); void funlockfile(FILE *); int getc_unlocked(FILE *); int getchar_unlocked(void); int putc_unlocked(int, FILE *); int putchar_unlocked(int); int getw(FILE *); int putw(int, FILE *); __attribute__((__deprecated__)) char *tempnam(char *__dir, char *__prefix) __asm__ ("_tempnam"); int fseeko(FILE *__stream, off_t __offset, int __whence); off_t ftello(FILE *__stream); int snprintf(char *__str, size_t __size, char *__format, ...); int vfscanf(FILE *__stream, char *__format, va_list); int vscanf(char *__format, va_list); int vsnprintf(char *__str, size_t __size, char *__format, va_list); int vsscanf(char *__str, char *__format, va_list); int dprintf(int, char *, ...); int vdprintf(int, char *, va_list); ssize_t getdelim(char **__linep, size_t *__linecapp, int __delimiter, FILE *__stream); ssize_t getline(char **__linep, size_t *__linecapp, FILE *__stream); FILE *fmemopen(void *__buf, size_t __size, char *__mode); FILE *open_memstream(char **__bufp, size_t *__sizep); extern int sys_nerr; int asprintf(char **, char *, ...); char *ctermid_r(char *); char *fgetln(FILE *, size_t *); char *fmtcheck(char *, char *); int fpurge(FILE *); void setbuffer(FILE *, char *, int); int setlinebuf(FILE *); int vasprintf(char **, char *, va_list); FILE *funopen(void *, int (*)(void *, char *, int), int (*)(void *, char *, int), fpos_t (*)(void *, fpos_t, int), int (*)(void *)); extern int __sprintf_chk(char *, int, size_t, char *, ...); extern int __snprintf_chk(char *, size_t, int, size_t, char *, ...); extern int __vsprintf_chk(char *, int, size_t, char *, va_list); extern int __vsnprintf_chk(char *, size_t, int, size_t, char *, va_list); '; private FFI $ffi; private static FFI $staticFFI; private static \WeakMap $__arrayWeakMap; private array $__literalStrings = []; public function __construct(?string $pathToSoFile = self::SOFILE) { $this->ffi = FFI::cdef(self::HEADER_DEF, $pathToSoFile); } public static function cast(istdio $from, string $to): istdio { if (!is_a($to, istdio::class, true)) { throw new \LogicException("Cannot cast to a non-wrapper type"); } return new $to(self::$staticFFI->cast($to::getType(), $from->getData())); } public static function makeArray(string $class, int|array $elements): istdio { $type = $class::getType(); if (substr($type, -1) !== "*") { throw new \LogicException("Attempting to make a non-pointer element into an array"); } if (is_int($elements)) { $cdata = self::$staticFFI->new(substr($type, 0, -1) . "[$elements]"); } else { $cdata = self::$staticFFI->new(substr($type, 0, -1) . "[" . count($elements) . "]"); foreach ($elements as $key => $raw) { $cdata[$key] = \is_scalar($raw) ? \is_int($raw) && $type === "char*" ? \chr($raw) : $raw : $raw->getData(); } } $object = new $class(self::$staticFFI->cast($type, \FFI::addr($cdata))); self::$__arrayWeakMap[$object] = $cdata; return $object; } public static function sizeof($classOrObject): int { if (is_object($classOrObject) && $classOrObject instanceof istdio) { return FFI::sizeof($classOrObject->getData()); } elseif (is_a($classOrObject, istdio::class, true)) { return FFI::sizeof(self::$staticFFI->type($classOrObject::getType())); } else { throw new \LogicException("Unknown class/object passed to sizeof()"); } } public function getFFI(): FFI { return $this->ffi; } public function __get(string $name) { switch($name) { case '__stdinp': return new struct___sFILE_ptr($this->ffi->__stdinp); case '__stdoutp': return new struct___sFILE_ptr($this->ffi->__stdoutp); case '__stderrp': return new struct___sFILE_ptr($this->ffi->__stderrp); case 'sys_nerr': return $this->ffi->sys_nerr; default: return $this->ffi->$name; } } public function __set(string $name, $value) { switch($name) { case '__stdinp': (new struct___sFILE_ptr($this->ffi->__stdinp))->set($value); break; case '__stdoutp': (new struct___sFILE_ptr($this->ffi->__stdoutp))->set($value); break; case '__stderrp': (new struct___sFILE_ptr($this->ffi->__stderrp))->set($value); break; case 'sys_nerr': $this->ffi->sys_nerr = $value; break; default: return $this->ffi->$name; } } public function __allocCachedString(string $str): FFI\CData { return $this->__literalStrings[$str] ??= string_::ownedZero($str)->getData(); } public function renameat(int $_0, void_ptr | string_ | null | string | array $_1, int $_2, void_ptr | string_ | null | string | array $_3): int { $__ffi_internal_refs_1 = []; if (\is_string($_1)) { $_1 = string_::ownedZero($_1)->getData(); } elseif (\is_array($_1)) { $_ = $this->ffi->new("char[" . \count($_1) . "]"); $_i = 0; if ($_1) { if ($_ref = \ReflectionReference::fromArrayElement($_1, \key($_1))) { foreach ($_1 as $_k => $_v) { $__ffi_internal_refs_1[$_i] = &$_1[$_k]; $_[$_i++] = $_v ?? 0; } $__ffi_internal_original_1 = $_1 = $_; } else { foreach ($_1 as $_v) { $_[$_i++] = $_v ?? 0; } $_1 = $_; } } } else { $_1 = $_1?->getData(); if ($_1 !== null) { $_1 = $this->ffi->cast("char*", $_1); } } $__ffi_internal_refs_3 = []; if (\is_string($_3)) { $_3 = string_::ownedZero($_3)->getData(); } elseif (\is_array($_3)) { $_ = $this->ffi->new("char[" . \count($_3) . "]"); $_i = 0; if ($_3) { if ($_ref = \ReflectionReference::fromArrayElement($_3, \key($_3))) { foreach ($_3 as $_k => $_v) { $__ffi_internal_refs_3[$_i] = &$_3[$_k]; $_[$_i++] = $_v ?? 0; } $__ffi_internal_original_3 = $_3 = $_; } else { foreach ($_3 as $_v) { $_[$_i++] = $_v ?? 0; } $_3 = $_; } } } else { $_3 = $_3?->getData(); if ($_3 !== null) { $_3 = $this->ffi->cast("char*", $_3); } } $result = $this->ffi->renameat($_0, $_1, $_2, $_3); foreach ($__ffi_internal_refs_1 as $_k => &$__ffi_internal_ref_v) { $__ffi_internal_ref_v = $__ffi_internal_original_1[$_k]; } foreach ($__ffi_internal_refs_3 as $_k => &$__ffi_internal_ref_v) { $__ffi_internal_ref_v = $__ffi_internal_original_3[$_k]; } return $result; } public function renamex_np(void_ptr | string_ | null | string | array $_0, void_ptr | string_ | null | string | array $_1, int $_2): int { $__ffi_internal_refs_0 = []; if (\is_string($_0)) { $_0 = string_::ownedZero($_0)->getData(); } elseif (\is_array($_0)) { $_ = $this->ffi->new("char[" . \count($_0) . "]"); $_i = 0; if ($_0) { if ($_ref = \ReflectionReference::fromArrayElement($_0, \key($_0))) { foreach ($_0 as $_k => $_v) { $__ffi_internal_refs_0[$_i] = &$_0[$_k]; $_[$_i++] = $_v ?? 0; } $__ffi_internal_original_0 = $_0 = $_; } else { foreach ($_0 as $_v) { $_[$_i++] = $_v ?? 0; } $_0 = $_; } } } else { $_0 = $_0?->getData(); if ($_0 !== null) { $_0 = $this->ffi->cast("char*", $_0); } } $__ffi_internal_refs_1 = []; if (\is_string($_1)) { $_1 = string_::ownedZero($_1)->getData(); } elseif (\is_array($_1)) { $_ = $this->ffi->new("char[" . \count($_1) . "]"); $_i = 0; if ($_1) { if ($_ref = \ReflectionReference::fromArrayElement($_1, \key($_1))) { foreach ($_1 as $_k => $_v) { $__ffi_internal_refs_1[$_i] = &$_1[$_k]; $_[$_i++] = $_v ?? 0; } $__ffi_internal_original_1 = $_1 = $_; } else { foreach ($_1 as $_v) { $_[$_i++] = $_v ?? 0; } $_1 = $_; } } } else { $_1 = $_1?->getData(); if ($_1 !== null) { $_1 = $this->ffi->cast("char*", $_1); } } $result = $this->ffi->renamex_np($_0, $_1, $_2); foreach ($__ffi_internal_refs_0 as $_k => &$__ffi_internal_ref_v) { $__ffi_internal_ref_v = $__ffi_internal_original_0[$_k]; } foreach ($__ffi_internal_refs_1 as $_k => &$__ffi_internal_ref_v) { $__ffi_internal_ref_v = $__ffi_internal_original_1[$_k]; } return $result; } public function renameatx_np(int $_0, void_ptr | string_ | null | string | array $_1, int $_2, void_ptr | string_ | null | string | array $_3, int $_4): int { $__ffi_internal_refs_1 = []; if (\is_string($_1)) { $_1 = string_::ownedZero($_1)->getData(); } elseif (\is_array($_1)) { $_ = $this->ffi->new("char[" . \count($_1) . "]"); $_i = 0; if ($_1) { if ($_ref = \ReflectionReference::fromArrayElement($_1, \key($_1))) { foreach ($_1 as $_k => $_v) { $__ffi_internal_refs_1[$_i] = &$_1[$_k]; $_[$_i++] = $_v ?? 0; } $__ffi_internal_original_1 = $_1 = $_; } else { foreach ($_1 as $_v) { $_[$_i++] = $_v ?? 0; } $_1 = $_; } } } else { $_1 = $_1?->getData(); if ($_1 !== null) { $_1 = $this->ffi->cast("char*", $_1); } } $__ffi_internal_refs_3 = []; if (\is_string($_3)) { $_3 = string_::ownedZero($_3)->getData(); } elseif (\is_array($_3)) { $_ = $this->ffi->new("char[" . \count($_3) . "]"); $_i = 0; if ($_3) { if ($_ref = \ReflectionReference::fromArrayElement($_3, \key($_3))) { foreach ($_3 as $_k => $_v) { $__ffi_internal_refs_3[$_i] = &$_3[$_k]; $_[$_i++] = $_v ?? 0; } $__ffi_internal_original_3 = $_3 = $_; } else { foreach ($_3 as $_v) { $_[$_i++] = $_v ?? 0; } $_3 = $_; } } } else { $_3 = $_3?->getData(); if ($_3 !== null) { $_3 = $this->ffi->cast("char*", $_3); } } $result = $this->ffi->renameatx_np($_0, $_1, $_2, $_3, $_4); foreach ($__ffi_internal_refs_1 as $_k => &$__ffi_internal_ref_v) { $__ffi_internal_ref_v = $__ffi_internal_original_1[$_k]; } foreach ($__ffi_internal_refs_3 as $_k => &$__ffi_internal_ref_v) { $__ffi_internal_ref_v = $__ffi_internal_original_3[$_k]; } return $result; } public function clearerr(void_ptr | struct___sFILE_ptr | null | array $_0): void { $__ffi_internal_refs_0 = []; if (\is_array($_0)) { $_ = $this->ffi->new("struct __sFILE[" . \count($_0) . "]"); $_i = 0; if ($_0) { if ($_ref = \ReflectionReference::fromArrayElement($_0, \key($_0))) { foreach ($_0 as $_k => $_v) { $__ffi_internal_refs_0[$_i] = &$_0[$_k]; $_[$_i++] = $_v?->getData(); } $__ffi_internal_original_0 = $_0 = $_; } else { foreach ($_0 as $_v) { $_[$_i++] = $_v?->getData(); } $_0 = $_; } } } else { $_0 = $_0?->getData(); if ($_0 !== null) { $_0 = $this->ffi->cast("struct __sFILE*", $_0); } } $this->ffi->clearerr($_0); foreach ($__ffi_internal_refs_0 as $_k => &$__ffi_internal_ref_v) { $__ffi_internal_ref_v = $__ffi_internal_original_0[$_k]; } } public function fclose(void_ptr | struct___sFILE_ptr | null | array $_0): int { $__ffi_internal_refs_0 = []; if (\is_array($_0)) { $_ = $this->ffi->new("struct __sFILE[" . \count($_0) . "]"); $_i = 0; if ($_0) { if ($_ref = \ReflectionReference::fromArrayElement($_0, \key($_0))) { foreach ($_0 as $_k => $_v) { $__ffi_internal_refs_0[$_i] = &$_0[$_k]; $_[$_i++] = $_v?->getData(); } $__ffi_internal_original_0 = $_0 = $_; } else { foreach ($_0 as $_v) { $_[$_i++] = $_v?->getData(); } $_0 = $_; } } } else { $_0 = $_0?->getData(); if ($_0 !== null) { $_0 = $this->ffi->cast("struct __sFILE*", $_0); } } $result = $this->ffi->fclose($_0); foreach ($__ffi_internal_refs_0 as $_k => &$__ffi_internal_ref_v) { $__ffi_internal_ref_v = $__ffi_internal_original_0[$_k]; } return $result; } public function feof(void_ptr | struct___sFILE_ptr | null | array $_0): int { $__ffi_internal_refs_0 = []; if (\is_array($_0)) { $_ = $this->ffi->new("struct __sFILE[" . \count($_0) . "]"); $_i = 0; if ($_0) { if ($_ref = \ReflectionReference::fromArrayElement($_0, \key($_0))) { foreach ($_0 as $_k => $_v) { $__ffi_internal_refs_0[$_i] = &$_0[$_k]; $_[$_i++] = $_v?->getData(); } $__ffi_internal_original_0 = $_0 = $_; } else { foreach ($_0 as $_v) { $_[$_i++] = $_v?->getData(); } $_0 = $_; } } } else { $_0 = $_0?->getData(); if ($_0 !== null) { $_0 = $this->ffi->cast("struct __sFILE*", $_0); } } $result = $this->ffi->feof($_0); foreach ($__ffi_internal_refs_0 as $_k => &$__ffi_internal_ref_v) { $__ffi_internal_ref_v = $__ffi_internal_original_0[$_k]; } return $result; }
php
MIT
0b7fb71209b192e55a61ec2fb33a932a561dd82a
2026-01-05T04:39:07.148223Z
true
ircmaxell/FFIMe
https://github.com/ircmaxell/FFIMe/blob/0b7fb71209b192e55a61ec2fb33a932a561dd82a/examples/00-basic/example.php
examples/00-basic/example.php
<?php require __DIR__ . '/../../vendor/autoload.php'; (new FFIMe\FFIMe(FFIMe\FFIMe::LIBC)) ->include(__DIR__ . "/test.h") ->codeGen('test\\test', __DIR__ . '/test.php'); require __DIR__ . '/test.php'; $test = Test\Test::ffi(); var_dump($test->add2(1, 2)); echo "Done\n";
php
MIT
0b7fb71209b192e55a61ec2fb33a932a561dd82a
2026-01-05T04:39:07.148223Z
false
ircmaxell/FFIMe
https://github.com/ircmaxell/FFIMe/blob/0b7fb71209b192e55a61ec2fb33a932a561dd82a/examples/00-basic/test.php
examples/00-basic/test.php
<?php namespace test; use FFI; use test\double; interface itest {} interface itest_ptr {} class test { const __x86_64__ = 1; const __LP64__ = 1; const __GNUC_VA_LIST = 1; const __GNUC__ = 4; const __GNUC_MINOR__ = 2; const __STDC__ = 1; public static function ffi(?string $pathToSoFile = testFFI::SOFILE): testFFI { return new testFFI($pathToSoFile); } public static function sizeof($classOrObject): int { return testFFI::sizeof($classOrObject); } } class testFFI { const SOFILE = '/usr/lib/libSystem.B.dylib'; const TYPES_DEF = ''; const HEADER_DEF = self::TYPES_DEF . ''; private FFI $ffi; private static FFI $staticFFI; private static \WeakMap $__arrayWeakMap; private array $__literalStrings = []; public function __construct(?string $pathToSoFile = self::SOFILE) { $this->ffi = FFI::cdef(self::HEADER_DEF, $pathToSoFile); } public static function cast(itest $from, string $to): itest { if (!is_a($to, itest::class, true)) { throw new \LogicException("Cannot cast to a non-wrapper type"); } return new $to(self::$staticFFI->cast($to::getType(), $from->getData())); } public static function makeArray(string $class, int|array $elements): itest { $type = $class::getType(); if (substr($type, -1) !== "*") { throw new \LogicException("Attempting to make a non-pointer element into an array"); } if (is_int($elements)) { $cdata = self::$staticFFI->new(substr($type, 0, -1) . "[$elements]"); } else { $cdata = self::$staticFFI->new(substr($type, 0, -1) . "[" . count($elements) . "]"); foreach ($elements as $key => $raw) { $cdata[$key] = \is_scalar($raw) ? \is_int($raw) && $type === "char*" ? \chr($raw) : $raw : $raw->getData(); } } $object = new $class(self::$staticFFI->cast($type, \FFI::addr($cdata))); self::$__arrayWeakMap[$object] = $cdata; return $object; } public static function sizeof($classOrObject): int { if (is_object($classOrObject) && $classOrObject instanceof itest) { return FFI::sizeof($classOrObject->getData()); } elseif (is_a($classOrObject, itest::class, true)) { return FFI::sizeof(self::$staticFFI->type($classOrObject::getType())); } else { throw new \LogicException("Unknown class/object passed to sizeof()"); } } public function getFFI(): FFI { return $this->ffi; } public function __get(string $name) { switch($name) { default: return $this->ffi->$name; } } public function __set(string $name, $value) { switch($name) { default: return $this->ffi->$name; } } public function __allocCachedString(string $str): FFI\CData { return $this->__literalStrings[$str] ??= string_::ownedZero($str)->getData(); } public function add2(int $a, int $b): int { $result = $this->_ffi_internal_add2($a, $b); return $result; } private function _ffi_internal_add2(int $a, int $b): int { $a = (function ($cdata, $val) { $cdata->cdata = $val; return $cdata; })($this->ffi->new("int"), $a); $b = (function ($cdata, $val) { $cdata->cdata = $val; return $cdata; })($this->ffi->new("int"), $b); return (($a)->cdata + ($b)->cdata); } } class string_ implements itest, itest_ptr, \ArrayAccess { private FFI\CData $data; public function __construct(FFI\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\CData { return $this->data; } public function equals(string_ $other): bool { return $this->data == $other->data; } public function addr(): string_ptr { return new string_ptr(FFI::addr($this->data)); } public function deref(int $n = 0): int { return \ord($this->data[$n]); } #[\ReturnTypeWillChange] public function offsetGet($offset): int { return $this->deref($offset); } #[\ReturnTypeWillChange] public function offsetExists($offset): bool { return !FFI::isNull($this->data); } #[\ReturnTypeWillChange] public function offsetUnset($offset): void { throw new \Error("Cannot unset C structures"); } #[\ReturnTypeWillChange] public function offsetSet($offset, $value): void { $this->data[$offset] = \chr($value); } public static function array(int $size = 1): self { return testFFI::makeArray(self::class, $size); } /** @return int[] */ public function toArray(?int $length = null): array { $ret = []; if ($length === null) { $i = 0; while ("\0" !== $cur = $this->data[$i++]) { $ret[] = \ord($cur); } } else { for ($i = 0; $i < $length; ++$i) { $ret[] = \ord($this->data[$i]); } } return $ret; } public function toString(?int $length = null): string { return $length === null ? FFI::string($this->data) : FFI::string($this->data, $length); } public static function persistent(string $string): self { $str = new self(FFI::cdef()->new("char[" . \strlen($string) . "]", false)); FFI::memcpy($str->data, $string, \strlen($string)); return $str; } public static function owned(string $string): self { $str = new self(FFI::cdef()->new("char[" . \strlen($string) . "]", true)); FFI::memcpy($str->data, $string, \strlen($string)); return $str; } public static function persistentZero(string $string): self { return self::persistent("$string\0"); } public static function ownedZero(string $string): self { return self::owned("$string\0"); } public function set(int | void_ptr | string_ $value): void { if (\is_scalar($value)) { $this->data[0] = \chr($value); } else { FFI::addr($this->data)[0] = $value->getData(); } } public static function getType(): string { return 'char*'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class string_ptr implements itest, itest_ptr, \ArrayAccess { private FFI\CData $data; public function __construct(FFI\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\CData { return $this->data; } public function equals(string_ptr $other): bool { return $this->data == $other->data; } public function addr(): string_ptr_ptr { return new string_ptr_ptr(FFI::addr($this->data)); } public function deref(int $n = 0): string_ { return new string_($this->data[$n]); } #[\ReturnTypeWillChange] public function offsetGet($offset): string_ { return $this->deref($offset); } #[\ReturnTypeWillChange] public function offsetExists($offset): bool { return !FFI::isNull($this->data); } #[\ReturnTypeWillChange] public function offsetUnset($offset): void { throw new \Error("Cannot unset C structures"); } #[\ReturnTypeWillChange] public function offsetSet($offset, $value): void { $this->data[$offset] = $value->getData(); } public static function array(int $size = 1): self { return testFFI::makeArray(self::class, $size); } /** @return string_[] */ public function toArray(?int $length = null): array { $ret = []; if ($length === null) { $i = 0; while (null !== $cur = $this->data[$i++]) { $ret[] = new string_($cur); } } else { for ($i = 0; $i < $length; ++$i) { $ret[] = new string_($this->data[$i]); } } return $ret; } public function set(void_ptr | string_ptr $value): void { FFI::addr($this->data)[0] = $value->getData(); } public static function getType(): string { return 'char**'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class string_ptr_ptr implements itest, itest_ptr, \ArrayAccess { private FFI\CData $data; public function __construct(FFI\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\CData { return $this->data; } public function equals(string_ptr_ptr $other): bool { return $this->data == $other->data; } public function addr(): string_ptr_ptr_ptr { return new string_ptr_ptr_ptr(FFI::addr($this->data)); } public function deref(int $n = 0): string_ptr { return new string_ptr($this->data[$n]); } #[\ReturnTypeWillChange] public function offsetGet($offset): string_ptr { return $this->deref($offset); } #[\ReturnTypeWillChange] public function offsetExists($offset): bool { return !FFI::isNull($this->data); } #[\ReturnTypeWillChange] public function offsetUnset($offset): void { throw new \Error("Cannot unset C structures"); } #[\ReturnTypeWillChange] public function offsetSet($offset, $value): void { $this->data[$offset] = $value->getData(); } public static function array(int $size = 1): self { return testFFI::makeArray(self::class, $size); } /** @return string_ptr[] */ public function toArray(?int $length = null): array { $ret = []; if ($length === null) { $i = 0; while (null !== $cur = $this->data[$i++]) { $ret[] = new string_ptr($cur); } } else { for ($i = 0; $i < $length; ++$i) { $ret[] = new string_ptr($this->data[$i]); } } return $ret; } public function set(void_ptr | string_ptr_ptr $value): void { FFI::addr($this->data)[0] = $value->getData(); } public static function getType(): string { return 'char***'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class string_ptr_ptr_ptr implements itest, itest_ptr, \ArrayAccess { private FFI\CData $data; public function __construct(FFI\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\CData { return $this->data; } public function equals(string_ptr_ptr_ptr $other): bool { return $this->data == $other->data; } public function addr(): string_ptr_ptr_ptr_ptr { return new string_ptr_ptr_ptr_ptr(FFI::addr($this->data)); } public function deref(int $n = 0): string_ptr_ptr { return new string_ptr_ptr($this->data[$n]); } #[\ReturnTypeWillChange] public function offsetGet($offset): string_ptr_ptr { return $this->deref($offset); } #[\ReturnTypeWillChange] public function offsetExists($offset): bool { return !FFI::isNull($this->data); } #[\ReturnTypeWillChange] public function offsetUnset($offset): void { throw new \Error("Cannot unset C structures"); } #[\ReturnTypeWillChange] public function offsetSet($offset, $value): void { $this->data[$offset] = $value->getData(); } public static function array(int $size = 1): self { return testFFI::makeArray(self::class, $size); } /** @return string_ptr_ptr[] */ public function toArray(?int $length = null): array { $ret = []; if ($length === null) { $i = 0; while (null !== $cur = $this->data[$i++]) { $ret[] = new string_ptr_ptr($cur); } } else { for ($i = 0; $i < $length; ++$i) { $ret[] = new string_ptr_ptr($this->data[$i]); } } return $ret; } public function set(void_ptr | string_ptr_ptr_ptr $value): void { FFI::addr($this->data)[0] = $value->getData(); } public static function getType(): string { return 'char***'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class void_ptr implements itest, itest_ptr { private FFI\CData $data; public function __construct(FFI\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\CData { return $this->data; } public function equals(void_ptr $other): bool { return $this->data == $other->data; } public function addr(): void_ptr_ptr { return new void_ptr_ptr(FFI::addr($this->data)); } public function set(itest_ptr $value): void { FFI::addr($this->data)[0] = $value->getData(); } public static function getType(): string { return 'void*'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class void_ptr_ptr implements itest, itest_ptr, \ArrayAccess { private FFI\CData $data; public function __construct(FFI\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\CData { return $this->data; } public function equals(void_ptr_ptr $other): bool { return $this->data == $other->data; } public function addr(): void_ptr_ptr_ptr { return new void_ptr_ptr_ptr(FFI::addr($this->data)); } public function deref(int $n = 0): void_ptr { return new void_ptr($this->data[$n]); } #[\ReturnTypeWillChange] public function offsetGet($offset): void_ptr { return $this->deref($offset); } #[\ReturnTypeWillChange] public function offsetExists($offset): bool { return !FFI::isNull($this->data); } #[\ReturnTypeWillChange] public function offsetUnset($offset): void { throw new \Error("Cannot unset C structures"); } #[\ReturnTypeWillChange] public function offsetSet($offset, $value): void { $this->data[$offset] = $value->getData(); } public static function array(int $size = 1): self { return testFFI::makeArray(self::class, $size); } /** @return void_ptr[] */ public function toArray(?int $length = null): array { $ret = []; if ($length === null) { $i = 0; while (null !== $cur = $this->data[$i++]) { $ret[] = new void_ptr($cur); } } else { for ($i = 0; $i < $length; ++$i) { $ret[] = new void_ptr($this->data[$i]); } } return $ret; } public function set(void_ptr | void_ptr_ptr $value): void { FFI::addr($this->data)[0] = $value->getData(); } public static function getType(): string { return 'void**'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class void_ptr_ptr_ptr implements itest, itest_ptr, \ArrayAccess { private FFI\CData $data; public function __construct(FFI\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\CData { return $this->data; } public function equals(void_ptr_ptr_ptr $other): bool { return $this->data == $other->data; } public function addr(): void_ptr_ptr_ptr_ptr { return new void_ptr_ptr_ptr_ptr(FFI::addr($this->data)); } public function deref(int $n = 0): void_ptr_ptr { return new void_ptr_ptr($this->data[$n]); } #[\ReturnTypeWillChange] public function offsetGet($offset): void_ptr_ptr { return $this->deref($offset); } #[\ReturnTypeWillChange] public function offsetExists($offset): bool { return !FFI::isNull($this->data); } #[\ReturnTypeWillChange] public function offsetUnset($offset): void { throw new \Error("Cannot unset C structures"); } #[\ReturnTypeWillChange] public function offsetSet($offset, $value): void { $this->data[$offset] = $value->getData(); } public static function array(int $size = 1): self { return testFFI::makeArray(self::class, $size); } /** @return void_ptr_ptr[] */ public function toArray(?int $length = null): array { $ret = []; if ($length === null) { $i = 0; while (null !== $cur = $this->data[$i++]) { $ret[] = new void_ptr_ptr($cur); } } else { for ($i = 0; $i < $length; ++$i) { $ret[] = new void_ptr_ptr($this->data[$i]); } } return $ret; } public function set(void_ptr | void_ptr_ptr_ptr $value): void { FFI::addr($this->data)[0] = $value->getData(); } public static function getType(): string { return 'void***'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class void_ptr_ptr_ptr_ptr implements itest, itest_ptr, \ArrayAccess { private FFI\CData $data; public function __construct(FFI\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\CData { return $this->data; } public function equals(void_ptr_ptr_ptr_ptr $other): bool { return $this->data == $other->data; } public function addr(): void_ptr_ptr_ptr_ptr_ptr { return new void_ptr_ptr_ptr_ptr_ptr(FFI::addr($this->data)); } public function deref(int $n = 0): void_ptr_ptr_ptr { return new void_ptr_ptr_ptr($this->data[$n]); } #[\ReturnTypeWillChange] public function offsetGet($offset): void_ptr_ptr_ptr { return $this->deref($offset); } #[\ReturnTypeWillChange] public function offsetExists($offset): bool { return !FFI::isNull($this->data); } #[\ReturnTypeWillChange] public function offsetUnset($offset): void { throw new \Error("Cannot unset C structures"); } #[\ReturnTypeWillChange] public function offsetSet($offset, $value): void { $this->data[$offset] = $value->getData(); } public static function array(int $size = 1): self { return testFFI::makeArray(self::class, $size); } /** @return void_ptr_ptr_ptr[] */ public function toArray(?int $length = null): array { $ret = []; if ($length === null) { $i = 0; while (null !== $cur = $this->data[$i++]) { $ret[] = new void_ptr_ptr_ptr($cur); } } else { for ($i = 0; $i < $length; ++$i) { $ret[] = new void_ptr_ptr_ptr($this->data[$i]); } } return $ret; } public function set(void_ptr | void_ptr_ptr_ptr_ptr $value): void { FFI::addr($this->data)[0] = $value->getData(); } public static function getType(): string { return 'void****'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class long_ptr implements itest, itest_ptr, \ArrayAccess { private FFI\CData $data; public function __construct(FFI\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\CData { return $this->data; } public function equals(long_ptr $other): bool { return $this->data == $other->data; } public function addr(): long_ptr_ptr { return new long_ptr_ptr(FFI::addr($this->data)); } public function deref(int $n = 0): int { return $this->data[$n]; } #[\ReturnTypeWillChange] public function offsetGet($offset): int { return $this->deref($offset); } #[\ReturnTypeWillChange] public function offsetExists($offset): bool { return !FFI::isNull($this->data); } #[\ReturnTypeWillChange] public function offsetUnset($offset): void { throw new \Error("Cannot unset C structures"); } #[\ReturnTypeWillChange] public function offsetSet($offset, $value): void { $this->data[$offset] = $value; } public static function array(int $size = 1): self { return testFFI::makeArray(self::class, $size); } /** @return int[] */ public function toArray(int $length): array { $ret = []; for ($i = 0; $i < $length; ++$i) { $ret[] = ($this->data[$i]); } return $ret; } public function set(int | void_ptr | long_ptr $value): void { if (\is_scalar($value)) { $this->data[0] = $value; } else { FFI::addr($this->data)[0] = $value->getData(); } } public static function getType(): string { return 'long*'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class long_ptr_ptr implements itest, itest_ptr, \ArrayAccess { private FFI\CData $data; public function __construct(FFI\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\CData { return $this->data; } public function equals(long_ptr_ptr $other): bool { return $this->data == $other->data; } public function addr(): long_ptr_ptr_ptr { return new long_ptr_ptr_ptr(FFI::addr($this->data)); } public function deref(int $n = 0): long_ptr { return new long_ptr($this->data[$n]); } #[\ReturnTypeWillChange] public function offsetGet($offset): long_ptr { return $this->deref($offset); } #[\ReturnTypeWillChange] public function offsetExists($offset): bool { return !FFI::isNull($this->data); } #[\ReturnTypeWillChange] public function offsetUnset($offset): void { throw new \Error("Cannot unset C structures"); } #[\ReturnTypeWillChange] public function offsetSet($offset, $value): void { $this->data[$offset] = $value->getData(); } public static function array(int $size = 1): self { return testFFI::makeArray(self::class, $size); } /** @return long_ptr[] */ public function toArray(?int $length = null): array { $ret = []; if ($length === null) { $i = 0; while (null !== $cur = $this->data[$i++]) { $ret[] = new long_ptr($cur); } } else { for ($i = 0; $i < $length; ++$i) { $ret[] = new long_ptr($this->data[$i]); } } return $ret; } public function set(void_ptr | long_ptr_ptr $value): void { FFI::addr($this->data)[0] = $value->getData(); } public static function getType(): string { return 'long**'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class long_ptr_ptr_ptr implements itest, itest_ptr, \ArrayAccess { private FFI\CData $data; public function __construct(FFI\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\CData { return $this->data; } public function equals(long_ptr_ptr_ptr $other): bool { return $this->data == $other->data; } public function addr(): long_ptr_ptr_ptr_ptr { return new long_ptr_ptr_ptr_ptr(FFI::addr($this->data)); } public function deref(int $n = 0): long_ptr_ptr { return new long_ptr_ptr($this->data[$n]); } #[\ReturnTypeWillChange] public function offsetGet($offset): long_ptr_ptr { return $this->deref($offset); } #[\ReturnTypeWillChange] public function offsetExists($offset): bool { return !FFI::isNull($this->data); } #[\ReturnTypeWillChange] public function offsetUnset($offset): void { throw new \Error("Cannot unset C structures"); } #[\ReturnTypeWillChange] public function offsetSet($offset, $value): void { $this->data[$offset] = $value->getData(); } public static function array(int $size = 1): self { return testFFI::makeArray(self::class, $size); } /** @return long_ptr_ptr[] */ public function toArray(?int $length = null): array { $ret = []; if ($length === null) { $i = 0; while (null !== $cur = $this->data[$i++]) { $ret[] = new long_ptr_ptr($cur); } } else { for ($i = 0; $i < $length; ++$i) { $ret[] = new long_ptr_ptr($this->data[$i]); } } return $ret; } public function set(void_ptr | long_ptr_ptr_ptr $value): void { FFI::addr($this->data)[0] = $value->getData(); } public static function getType(): string { return 'long***'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } class long_ptr_ptr_ptr_ptr implements itest, itest_ptr, \ArrayAccess { private FFI\CData $data; public function __construct(FFI\CData $data) { $this->data = $data; } public static function castFrom(itest $data): self { return testFFI::cast($data, self::class); } public function getData(): FFI\CData { return $this->data; } public function equals(long_ptr_ptr_ptr_ptr $other): bool { return $this->data == $other->data; } public function addr(): long_ptr_ptr_ptr_ptr_ptr { return new long_ptr_ptr_ptr_ptr_ptr(FFI::addr($this->data)); } public function deref(int $n = 0): long_ptr_ptr_ptr { return new long_ptr_ptr_ptr($this->data[$n]); } #[\ReturnTypeWillChange] public function offsetGet($offset): long_ptr_ptr_ptr { return $this->deref($offset); } #[\ReturnTypeWillChange] public function offsetExists($offset): bool { return !FFI::isNull($this->data); } #[\ReturnTypeWillChange] public function offsetUnset($offset): void { throw new \Error("Cannot unset C structures"); } #[\ReturnTypeWillChange] public function offsetSet($offset, $value): void { $this->data[$offset] = $value->getData(); } public static function array(int $size = 1): self { return testFFI::makeArray(self::class, $size); } /** @return long_ptr_ptr_ptr[] */ public function toArray(?int $length = null): array { $ret = []; if ($length === null) { $i = 0; while (null !== $cur = $this->data[$i++]) { $ret[] = new long_ptr_ptr_ptr($cur); } } else { for ($i = 0; $i < $length; ++$i) { $ret[] = new long_ptr_ptr_ptr($this->data[$i]); } } return $ret; } public function set(void_ptr | long_ptr_ptr_ptr_ptr $value): void { FFI::addr($this->data)[0] = $value->getData(); } public static function getType(): string { return 'long****'; } public static function size(): int { return testFFI::sizeof(self::class); } public function getDefinition(): string { return static::getType(); } } (function() { self::$staticFFI = \FFI::cdef(testFFI::TYPES_DEF); self::$__arrayWeakMap = new \WeakMap; })->bindTo(null, testFFI::class)();
php
MIT
0b7fb71209b192e55a61ec2fb33a932a561dd82a
2026-01-05T04:39:07.148223Z
false
ircmaxell/FFIMe
https://github.com/ircmaxell/FFIMe/blob/0b7fb71209b192e55a61ec2fb33a932a561dd82a/examples/01-stdio-builder/example.php
examples/01-stdio-builder/example.php
<?php require __DIR__ . '/../../vendor/autoload.php'; $libc = (new FFIMe\FFIMe(\FFIMe\FFIMe::LIBC)) ->include("stdio.h") ->build(); $libc->printf("test\n");
php
MIT
0b7fb71209b192e55a61ec2fb33a932a561dd82a
2026-01-05T04:39:07.148223Z
false
ircmaxell/FFIMe
https://github.com/ircmaxell/FFIMe/blob/0b7fb71209b192e55a61ec2fb33a932a561dd82a/lib/CompiledFunctionType.php
lib/CompiledFunctionType.php
<?php namespace FFIMe; class CompiledFunctionType extends CompiledType { public CompiledType $return; /** @var CompiledType[] */ public array $args; /** @var string[]|null[] */ public array $argNames; public bool $isVariadic; /** @param CompiledType[] $args */ public function __construct(CompiledType $return, array $args, array $argNames, bool $isVariadic, array $indirections = []) { parent::__construct('function type', $indirections); $this->return = $return; if ($args && $args[0]->value === 'void' && $args[0]->indirections() === 0) { $args = $argNames = []; } $this->args = $args; $this->argNames = $argNames; $this->isVariadic = $isVariadic; } public function toValue(?string $compiledBaseType = null): string { return "{$this->return->toValue()}(" . parent::toValue('') . ")(" . implode(', ', array_map(static function(CompiledType $type) { return $type->toValue(); }, $this->args)) . ($this->isVariadic ? ", ..." : "") . ")"; } }
php
MIT
0b7fb71209b192e55a61ec2fb33a932a561dd82a
2026-01-05T04:39:07.148223Z
false
ircmaxell/FFIMe
https://github.com/ircmaxell/FFIMe/blob/0b7fb71209b192e55a61ec2fb33a932a561dd82a/lib/Compiler.php
lib/Compiler.php
<?php declare(strict_types=1); namespace FFIMe; use PHPCParser\Context; use PHPCParser\Node\Decl; use PHPCParser\Node\Stmt; use PHPCParser\Node\Type; use PHPCParser\Printer; use PHPCParser\Node\Stmt\ValueStmt\Expr; use FFI; class Compiler { const IS_REF = 1 << 0; const IS_DATA = 1 << 1; const IS_NOREF = 1 << 2; const IS_STRING = 1 << 3; const IS_ARRAY = 1 << 4; const IS_ARRAY_STRING = 1 << 5; const IS_FOREIGN_FFI = 1 << 6; const ARG_IDX_SHIFT = 12; const COMPILED_PREFIX = "_ffi_internal_"; private string $className; /** @var string[] */ private array $defines; /** @var CompiledType[] */ private array $resolver; /** @var CompiledType[] */ private array $localVariableTypes = []; /** @var CompiledType[] */ private array $globalVariableTypes = []; private array $compiledGlobalVariables = []; /** @var CompiledType[][] */ private array $records = []; /** @var int[][] */ private array $recordBitfieldSizes = []; /** @var int[] */ private array $lowercaseCompiledFunctions = []; /** @var string[] */ private array $classAliases = []; /** @var string[] */ private array $functionNames = []; /** @var Decl\NamedDecl\ValueDecl\DeclaratorDecl\FunctionDecl[] */ private array $knownFunctions = []; /** @var CompiledFunctionType[] */ private array $knownCompiledFunctions = []; /** @var string[] */ private array $usedBuiltinTypes = []; private array $usedBuiltinFunctions = []; /** @var int[] */ private array $baseTypeIndirections = []; // when compiling aliases, there shall be no more than 4 levels private int $switchIndex = 0; private int $activeSwitchIndex = 0; /** @var Stmt\Label\CaseLabel[] */ private array $switchCases = []; /** @var string[]|null */ private ?array $innerGotoLabels = null; /** @var string[]|null */ private ?array $pendingGotoLabels = null; private bool $usedBreak = false; private string $activeBreakTarget = ""; private bool $generateFunctionPtrDefs = false; /** @var string[] */ public array $warnings = []; public function __construct(private bool $instrument = false, private ?array $restrictedCompiledFunctions = null, private ?array $restrictedCompiledClasses = null, private ?array $restrictedCompiledConstants = null, private ?array $restrictedCompiledGlobals = null) {} /** @param Decl[] $decls * @param Decl[] $definitions * @param string[] $defines */ public function compile(string $soFile, array $decls, array $definitions, array $nonCompiledDeclarations, array $defines, string $className): string { foreach (Context::NUMERICAL_DEFINES as $define => $_) { unset($defines[$define]); } $this->defines = $defines; foreach ($defines as $name => &$value) { // remove type qualifiers $value = str_replace(['u', 'l', 'U', 'L'], '', $value); if (strpos($value, '.') !== false) { $value = str_replace(['d', 'f', 'D', 'F'], '', $value); } } unset($value); $this->buildResolver($decls); $this->buildRecordFieldTypeMap($decls); foreach ($nonCompiledDeclarations as $decl) { $this->collectNonCompiledDeclaration($decl); } $parts = explode('\\', $className); $constObservers = []; $class = []; if (isset($parts[1])) { $className = array_pop($parts); $namespace = implode('\\', $parts); $class[] = "namespace " . $namespace . ";"; $class[] = "use FFI;"; $class[] = "use " . $namespace . "\\double;"; // suppress warning } $this->className = $className; $class[] = "interface i{$className} {}"; $class[] = "interface i{$className}_ptr {}"; $classStartIndex = \count($class); [$typeDecls, $nonTypeDecls] = $this->splitDeclsIfType($decls); $class[] = "class $className {"; $declFuncs = []; foreach ($decls as $decl) { try { [$declFunc, $constants] = $this->compileDecl($decl); $defines += $constants; array_push($declFuncs, ...$declFunc); } catch (UnsupportedFeatureException $e) { $this->warnings[] = "{$decl->name} could not be compiled: {$e->getMessage()}"; } catch (\Throwable $t) { throw new \LogicException("Error occurred during compilation of {$decl->name}", 0, $t); } } foreach ($defines as $name => $value) { if ($this->restrictedCompiledConstants !== null && !isset($this->restrictedCompiledConstants[$name])) { continue; } if ($this->instrument) { $constObservers[($namespace ? "$namespace\\" : "") . "$className\\$name"] = "eval('namespace " . ($namespace ? "$namespace\\" : "") . "$className { class $name { const VALUE = $value; } }');"; $value = "$className\\$name::VALUE"; } $class[] = " const {$name} = {$value};"; } $class[] = " public static function ffi(?string \$pathToSoFile = {$className}FFI::SOFILE): {$className}FFI { return new {$className}FFI(\$pathToSoFile); }"; $class[] = ' public static function sizeof($classOrObject): int { return ' . $className . 'FFI::sizeof($classOrObject); }'; $class[] = "}"; $class[] = "class {$className}FFI {"; $class[] = " const SOFILE = " . var_export($soFile, true) . ';'; $class[] = " const TYPES_DEF = " . var_export($this->compileDeclsToCode($typeDecls), true) . ';'; $class[] = " const HEADER_DEF = self::TYPES_DEF . " . var_export($this->compileDeclsToCode($nonTypeDecls), true) . ';'; $class[] = " private FFI \$ffi;"; $class[] = " private static FFI \$staticFFI;"; $class[] = " private static \WeakMap \$__arrayWeakMap;"; // ensure that cdata is not freed as long as the pointer lives $class[] = " private array \$__literalStrings = [];"; if ($this->instrument) { $class[] = " public static \$__visitedClasses = [];"; $class[] = " public static \$__visitedFunctions = [];"; $class[] = " public static \$__visitedConstants = [];"; $class[] = " public static \$__visitedGlobals = [];"; } array_push($class, ...$this->compileConstructor($definitions)); $class[] = $this->compileMethods(); $class[] = " public function __get(string \$name) {"; $class[] = " switch(\$name) {"; foreach ($this->compileCases($decls, false) as $case) { $class[] = " $case"; } foreach ($this->compileCaseDefs($definitions, false) as $case) { $class[] = " $case"; } $class[] = " default: return \$this->ffi->\$name;"; $class[] = " }"; $class[] = " }"; $class[] = " public function __set(string \$name, \$value) {"; $class[] = " switch(\$name) {"; foreach ($this->compileCases($decls, true) as $case) { $class[] = " $case"; } foreach ($this->compileCaseDefs($definitions, true) as $case) { $class[] = " $case"; } $class[] = " default: return \$this->ffi->\$name;"; $class[] = " }"; $class[] = " }"; $class[] = ' public function __allocCachedString(string $str): FFI\CData {'; $class[] = ' return $this->__literalStrings[$str] ??= string_::ownedZero($str)->getData();'; $class[] = ' }'; array_push($class, ...$declFuncs); foreach ($definitions as $def) { try { array_push($class, ...$this->compileDef($def)); } catch (UnsupportedFeatureException $e) { $this->warnings[] = "{$def->name} could not be compiled: {$e->getMessage()}"; } catch (NotExportedFunctionException $e) { $this->warnings[] = "{$def->name} could not be compiled: {$e->getMessage()}"; } catch (\Throwable $t) { throw new \LogicException("Error occurred during compilation of {$def->name}", 0, $t); } } foreach ($this->usedBuiltinFunctions as $function => $_) { array_push($class, ...BuiltinFunction::$registry[$function]->print()); } $class[] = "}"; $class[] = ""; $publicProperties = ["/**"]; foreach ($this->globalVariableTypes as $var => $type) { if ($this->restrictedCompiledGlobals === null || isset($this->restrictedCompiledGlobals[$var])) { $publicProperties[] = " * @property " . $this->toPHPType($type) . ' $' . $var; } } if (\count($publicProperties) > 1) { $publicProperties[] = " */"; array_splice($class, $classStartIndex, 0, $publicProperties); } // we need to compile this early because of the side effects on usedBuiltinTypes $this->classAliases = []; foreach ($decls as $decl) { try { $this->classAliases += $this->compileDeclClass($decl); } catch (UnsupportedFeatureException $e) { $this->warnings[] = "{$decl->name} could not be compiled: {$e->getMessage()}"; } } array_push($class, ...$this->compileDeclClassImpl('string_', new CompiledType('int', [null], 'char'))); array_push($class, ...$this->compileDeclClassImpl('string_ptr', new CompiledType('int', [null, null], 'char'))); array_push($class, ...$this->compileDeclClassImpl('string_ptr_ptr', new CompiledType('int', [null, null, null], 'char'))); array_push($class, ...$this->compileDeclClassImpl('string_ptr_ptr_ptr', new CompiledType('int', [null, null, null], 'char'))); array_push($class, ...$this->compileDeclClassImpl('void_ptr', new CompiledType('void', [null]))); array_push($class, ...$this->compileDeclClassImpl('void_ptr_ptr', new CompiledType('void', [null, null]))); array_push($class, ...$this->compileDeclClassImpl('void_ptr_ptr_ptr', new CompiledType('void', [null, null, null]))); array_push($class, ...$this->compileDeclClassImpl('void_ptr_ptr_ptr_ptr', new CompiledType('void', [null, null, null, null]))); if ($this->generateFunctionPtrDefs) { array_push($class, ...$this->compileFunctionPtrClassImpl(1)); array_push($class, ...$this->compileFunctionPtrClassImpl(2)); array_push($class, ...$this->compileFunctionPtrClassImpl(3)); array_push($class, ...$this->compileFunctionPtrClassImpl(4)); } foreach (array_keys($this->usedBuiltinTypes) as $builtinType) { if (str_starts_with($builtinType, "__builtin_") || str_starts_with($builtinType, "__gnuc_")) { for ($i = 0; $i <= 4; ++$i) { array_push($class, ...$this->compileDeclClassImpl($builtinType . str_repeat('_ptr', $i), new CompiledType($builtinType, array_fill(0, $i, null)))); } } } foreach ($this->records as $record => $fields) { $recordClass = strtr($record, " ", "_"); for ($i = 0; $i <= 4; ++$i) { array_push($class, ...$this->compileDeclClassImpl($recordClass . str_repeat('_ptr', $i), new CompiledType($record, array_fill(0, $i, null)))); } } $nativeTypeGroupings = array_merge(array_values($this->groupNativeTypesOfSameSize(self::INT_TYPES)), array_values($this->groupNativeTypesOfSameSize(self::FLOAT_TYPES))); $nativeClassAliases = []; foreach ($nativeTypeGroupings as $nativeTypeGroup) { $firstNativeTypeMatch = null; foreach ($nativeTypeGroup as $nativeType) { if (isset($this->usedBuiltinTypes[$nativeType])) { $nativeType = strtr($nativeType, " ", "_"); if ($firstNativeTypeMatch) { for ($i = 1; $i <= 4; ++$i) { $nativeClassAliases[$nativeType . str_repeat('_ptr', $i)] = $firstNativeTypeMatch . str_repeat('_ptr', $i); } } else { $firstNativeTypeMatch = $nativeType; for ($i = 1; $i <= 4; ++$i) { array_push($class, ...$this->compileDeclClassImpl($nativeType . str_repeat('_ptr', $i), new CompiledType(in_array($nativeType, self::FLOAT_TYPES) ? 'float' : 'int', array_fill(0, $i, null), $nativeType))); } } } } } $class[] = "(function() { self::\$staticFFI = \FFI::cdef({$className}FFI::TYPES_DEF); self::\$__arrayWeakMap = new \WeakMap; })->bindTo(null, {$className}FFI::class)();"; if ($this->instrument) { $class[] = 'spl_autoload_register(function($class) {'; $class[] = ' switch ($class) {'; foreach ($constObservers as $name => $definition) { $class[] = " case '$name':"; $class[] = " {$className}FFI::\$__visitedConstants['" . substr($name, strrpos($name, "\\") + 1) . "'] = true;"; $class[] = " $definition"; $class[] = " break;"; } $class[] = ' }'; $class[] = '});'; } foreach ($nativeClassAliases + $this->classAliases as $alias => $name) { if ($this->restrictedCompiledClasses === null || isset($this->restrictedCompiledClasses[$name])) { $class[] = '\class_alias(' . $name . '::class, ' . $alias . '::class);'; } } return implode("\n", $class); } /** @param Decl[] $decls * @return string[] */ public function compileCases(array $decls, bool $isSetter): array { $results = []; foreach ($decls as $decl) { if ($decl instanceof Decl\NamedDecl\ValueDecl\DeclaratorDecl\VarDecl) { if ($case = $this->compileCase($decl, "ffi->", $isSetter)) { $results[] = $case; } } } return $results; } /** @param Decl[] $decls * @return string[] */ public function compileCaseDefs(array $decls, bool $isSetter): array { $results = []; foreach ($decls as $decl) { if ($decl instanceof Decl\NamedDecl\ValueDecl\DeclaratorDecl\VarDecl) { if ($case = $this->compileCase($decl, "", $isSetter)) { $results[] = $case; } } } return $results; } private function compileCase(Decl\NamedDecl\ValueDecl\DeclaratorDecl\VarDecl $decl, string $ffiAccess, bool $isSetter): string { if ($this->restrictedCompiledGlobals !== null && isset($this->restrictedCompiledGlobals[$decl->name])) { return ""; } $return = $this->compileType($decl->type); $line = "case " . var_export($decl->name, true) . ": "; if ($this->instrument) { $line .= 'self::$__visitedGlobals[' . var_export($decl->name, true) . '] = true; '; } if ($return->isNative) { if ($isSetter) { $line .= "\$this->$ffiAccess{$decl->name} = " . ($return->rawValue === 'char' ? '\chr($value)' : '$value') . "; break;"; } else { $line .= "return " . ($return->rawValue === 'char' ? "\ord(\$this->$ffiAccess{$decl->name})" : "\$this->$ffiAccess{$decl->name}") . ";"; } } else { $object = $this->toPHPValue($return, '$this->' . $ffiAccess . $decl->name); if ($isSetter) { $line .= "($object)->set(\$value); break;"; } else { $line .= "return $object;"; } } return $line; } /** @param Decl[] $decls * @return string[] */ protected function compileConstructor(array $decls): array { $ctor[] = ' public function __construct(?string $pathToSoFile = self::SOFILE) {'; $ctor[] = ' $this->ffi = FFI::cdef(self::HEADER_DEF, $pathToSoFile);'; foreach ($decls as $decl) { if ($decl instanceof Decl\NamedDecl\ValueDecl\DeclaratorDecl\VarDecl) { $varType = $this->compileType($decl->type); if ($decl->initializer) { // compileInitializer completes incomplete array types $initializer = $decl->initializer instanceof Expr\InitializerExpr && $decl->initializer->explicitType === null ? $this->compileInitializer($varType, $decl->initializer->initializers)->value : $this->compileExpr($decl->initializer)->toValue($varType); } $ctor[] = ' $this->' . $decl->name . ' = $this->ffi->new("' . $varType->toValue() . '");'; if ($decl->initializer) { $ctor[] = ' ' . ($varType->isNative ? '$this->' . $decl->name . '->cdata' : 'FFI::addr($this->' . $decl->name . ')[0]') . ' = ' . $initializer . ';'; } } } $ctor[] = ' }'; return $ctor; } protected function compileMethods(): string { return ' public static function cast(i'. $this->className . ' $from, string $to): i' . $this->className . ' { if (!is_a($to, i' . $this->className . '::class, true)) { throw new \LogicException("Cannot cast to a non-wrapper type"); } return new $to(self::$staticFFI->cast($to::getType(), $from->getData())); } public static function makeArray(string $class, int|array $elements): i'. $this->className . ' { $type = $class::getType(); if (substr($type, -1) !== "*") { throw new \LogicException("Attempting to make a non-pointer element into an array"); } if (is_int($elements)) { $cdata = self::$staticFFI->new(substr($type, 0, -1) . "[$elements]"); } else { $cdata = self::$staticFFI->new(substr($type, 0, -1) . "[" . count($elements) . "]"); foreach ($elements as $key => $raw) { $cdata[$key] = \is_scalar($raw) ? \is_int($raw) && $type === "char*" ? \chr($raw) : $raw : $raw->getData(); } } $object = new $class(self::$staticFFI->cast($type, \FFI::addr($cdata))); self::$__arrayWeakMap[$object] = $cdata; return $object; } public static function sizeof($classOrObject): int { if (is_object($classOrObject) && $classOrObject instanceof i' . $this->className . ') { return FFI::sizeof($classOrObject->getData()); } elseif (is_a($classOrObject, i' . $this->className . '::class, true)) { return FFI::sizeof(self::$staticFFI->type($classOrObject::getType())); } else { throw new \LogicException("Unknown class/object passed to sizeof()"); } } public function getFFI(): FFI { return $this->ffi; } '; } /** @param Decl[] $decls */ public function compileDeclsToCode(array $decls): string { // TODO $printer = new Printer\C; if ($this->restrictedCompiledFunctions !== null || $this->restrictedCompiledConstants !== null) { foreach ($decls as $idx => $decl) { if ($decl instanceof Decl\NamedDecl\ValueDecl\DeclaratorDecl\FunctionDecl && $this->restrictedCompiledFunctions !== null) { if ($this->restrictedCompiledFunctions !== null && !isset($this->restrictedCompiledFunctions[$decl->name])) { unset($decls[$idx]); } } elseif ($decl instanceof Decl\NamedDecl\ValueDecl\DeclaratorDecl\VarDecl) { if ($this->restrictedCompiledGlobals !== null && !isset($this->restrictedCompiledGlobals[$decl->name])) { unset($decls[$idx]); } } elseif ($this->restrictedCompiledConstants !== null) { if ($decl instanceof Decl\NamedDecl\TypeDecl\TagDecl\EnumDecl) { enum_decl: if ($decl->fields !== null) { foreach ($decl->fields as $field) { if (isset($this->defines[$field->name])) { continue; } if (isset($this->restrictedCompiledConstants[$field->name])) { goto print_enum; } } unset($decls[$idx]); print_enum: } } elseif ($decl instanceof Decl\NamedDecl\TypeDecl\TypedefNameDecl && $decl->type instanceof Type\TagType\EnumType) { $decl = $decl->type->decl; goto enum_decl; } } } } $defs = $printer->printNodes($decls, 0); // hack to make _Complex disappear (it's just definitions) // there probably should be a recursive cleanup of everything _Complex ... // FFI sadly does not support _Complex yet $defs = preg_replace('(\b_Complex\b)', '', $defs); // FFI does not support 128 bit wide ints/floats either $defs = preg_replace('(\b__int128\b)', 'int', $defs); $defs = preg_replace('(\b__float128\b)', 'float', $defs); return $defs; } /** @return string[] */ public function compileDef(Decl $def): array { $this->localVariableTypes = []; $return = []; if ($def instanceof Decl\NamedDecl\ValueDecl\DeclaratorDecl\FunctionDecl) { if ($this->restrictedCompiledFunctions !== null && !isset($this->restrictedCompiledClasses[$def->name])) { return []; } try { [$return, $functionType, $preReturnStmts] = $this->compileFunctionStart($def); $this->knownCompiledFunctions[$def->name] = $functionType; $params = $functionType->args; $callParams = []; foreach ($params as $idx => $param) { $varname = $functionType->argNames[$idx]; $this->localVariableTypes[$varname] = $param; $callParams[] = '$' . ($varname ?: "_$idx"); } $returnType = $functionType->return; if ($returnType->value !== 'void' || $returnType->indirections()) { $return[] = ' $result = $this->' . self::COMPILED_PREFIX . $def->name . '(' . implode(', ', $callParams) . ');'; array_push($return, ...$preReturnStmts); if ($returnType->isNative) { $return[] = ' return $result;'; } else { $return[] = ' return $result === null ? null : ' . $this->toPHPValue($returnType, '$result') . ';'; } } else { $return[] = ' $this->' . self::COMPILED_PREFIX . $def->name . '(' . implode(', ', $callParams) . ');'; array_push($return, ...$preReturnStmts); } $return[] = " }"; $nullableReturnType = $returnType->value === 'void' && $returnType->indirections() === 0 ? 'void' : ($returnType->isNative ? $returnType->value : '?FFI\CData'); $paramSignature = []; foreach ($params as $idx => $param) { $varname = $functionType->argNames[$idx] ?: "_$idx"; $paramSignature[] = ($param->isNative ? $param->value : 'FFI\CData') . ' $' . $varname; } $return[] = " private function " . self::COMPILED_PREFIX . "{$this->functionNames[$def->name]}(" . implode(', ', $paramSignature) . "): " . $nullableReturnType . " {"; foreach ($params as $idx => $param) { if ($param->isNative) { $varname = $functionType->argNames[$idx] ?: "_$idx"; $return[] = ' $' . $varname . ' = (function ($cdata, $val) { $cdata->cdata = $val; return $cdata; })($this->ffi->new("' . $param->value . '"), $' . $varname . ');'; } } $stmts = $this->compileStmt($def->stmts); if ($this->innerGotoLabels !== null) { $return[] = ' $' . self::COMPILED_PREFIX . '_goto_label = null;'; } array_push($return, ...$stmts); $return[] = " }"; } catch (\Throwable $t) { unset($this->knownCompiledFunctions[$def->name], $this->functionNames[$def->name]); --$this->lowercaseCompiledFunctions[strtolower($def->name)]; throw $t; } } elseif ($def instanceof Decl\NamedDecl\ValueDecl\DeclaratorDecl\VarDecl) { $this->globalVariableTypes[$def->name] = $this->compileType($def->type); $this->compiledGlobalVariables[$def->name] = true; $return[] = ' private FFI\CData $' . $def->name . ';'; } return $return; } /** @return string[] */ public function compileStmt(Stmt $stmt, $level = 2): array { $result = []; if ($stmt instanceof Stmt\CompoundStmt) { foreach ($stmt->stmts as $stmt) { array_push($result, ...$this->compileStmt($stmt, $level)); } } else { foreach ($stmt->labels as $label) { if ($label instanceof Stmt\Label\CaseLabel) { $labelname = '_ffi_switch_' . $this->activeSwitchIndex . '_case_' . \count($this->switchCases); $this->switchCases[] = $label; } elseif ($label instanceof Stmt\Label\DefaultLabel) { $labelname = '_ffi_switch_' . $this->activeSwitchIndex . '_case_' . \count($this->switchCases); $this->switchCases[] = null; } elseif ($label instanceof Stmt\Label\IdentifiedLabel) { $labelname = $label->label; } else { var_dump($label); continue; } if (isset($this->pendingGotoLabels[$labelname])) { unset($this->pendingGotoLabels[$labelname]); $result[] = $labelname . ':'; } else { $this->innerGotoLabels[$labelname] = $level; $result[] = self::COMPILED_PREFIX . '_' . $level . '_' . $labelname . ': $' . self::COMPILED_PREFIX . '_goto_label = null;'; } } if ($stmt instanceof Stmt\ReturnStmt) { $result[] = str_repeat(' ', $level * 4) . 'return' . ($stmt->result ? ' ' . $this->compileExpr($stmt->result)->toValue(\end($this->knownCompiledFunctions)->return) : '') . ';'; } elseif ($stmt instanceof Expr) { $result[] = str_repeat(' ', $level * 4) . $this->compileExpr($stmt)->value . ';'; } elseif ($stmt instanceof Stmt\DeclStmt) { foreach ($this->compileDeclStmt($stmt) as $declResult) { $result[] = str_repeat(' ', $level * 4) . $declResult . ';'; } } elseif ($stmt instanceof Stmt\IfStmt) { $result[] = str_repeat(' ', $level * 4) . 'if (' . $this->compileExpr($stmt->condition)->toBool() . ') {'; array_push($result, ...$this->compileStmt($stmt->trueStmt, $level + 1)); if ($stmt->falseStmt) { $result[] = str_repeat(' ', $level * 4) . '} else {'; array_push($result, ...$this->compileStmt($stmt->falseStmt, $level + 1)); } $result[] = str_repeat(' ', $level * 4) . '}'; } elseif ($stmt instanceof Stmt\LoopStmt || $stmt instanceof Stmt\DoLoopStmt) { $pendingGotoLabels = $this->pendingGotoLabels; $innerGotoLabels = $this->innerGotoLabels; $this->innerGotoLabels = []; $initStmt = []; if ($stmt instanceof Stmt\LoopStmt) { if ($stmt->initStmt instanceof Stmt\DeclStmt) { if ($decls = $this->compileDeclStmt($stmt->initStmt)) { foreach ($decls as $decl) { $initStmt[] = str_repeat(' ', $level * 4) . $decl . ';'; } } } elseif ($stmt->initStmt instanceof Expr) { $initStmt[] = str_repeat(' ', $level * 4) . $this->compileExpr($stmt->initStmt)->value . ';'; } } $prevUsedBreak = $this->usedBreak; $prevBreakTarget = $this->activeBreakTarget; $this->activeBreakTarget = 'break;'; $stmts = $this->compileStmt($stmt->loopStmt, $level + 1); $this->activeBreakTarget = $prevBreakTarget; $this->usedBreak = $prevUsedBreak; $condition = ""; if ($stmt->condition) { $condition = $this->compileExpr($stmt->condition)->toBool(); } if ($stmt instanceof Stmt\DoLoopStmt) { $loop = "do"; $loopEnd = " while ($condition);"; } else { $loopEnd = ""; if ($stmt->condition && $this->innerGotoLabels) { $condition = '$' . self::COMPILED_PREFIX . "_goto_label || ($condition)"; } if ($stmt->condition && !$stmt->initStmt && !$stmt->loopExpr) { $loop = "while ($condition)"; } else { array_push($result, ...$initStmt); $loop = "for (; $condition;" . ($stmt->loopExpr ? ' ' . $this->compileExpr($stmt->loopExpr)->value : '') . ')'; } } foreach ($this->innerGotoLabels as $label => $gotoLevel) { if (isset($pendingGotoLabels[$label])) { $labelname = $label; } else { $labelname = self::COMPILED_PREFIX . '_' . $level . '_' . $label; } $result[] = 'if (false) { ' . $labelname . ': $' . self::COMPILED_PREFIX . '_goto_label = "' . $label . '"; }'; } $result[] = str_repeat(' ', $level * 4) . $loop . ' {'; if ($this->innerGotoLabels) { $result[] = 'if ($' . self::COMPILED_PREFIX . '_goto_label !== null) { switch ($' . self::COMPILED_PREFIX . '_goto_label) {'; foreach ($this->innerGotoLabels as $label => $gotoLevel) { $result[] = ' case "' . $label . '": goto ' . self::COMPILED_PREFIX . '_' . $gotoLevel . '_' . $label . ';'; if (isset($pendingGotoLabels[$label])) { unset($this->pendingGotoLabels[$label], $this->innerGotoLabels[$label]); } else { $this->innerGotoLabels[$label] = $level; } } $result[] = '} }'; } array_push($result, ...$stmts); $result[] = str_repeat(' ', $level * 4) . '}' . $loopEnd; if ($innerGotoLabels) { $this->innerGotoLabels += $innerGotoLabels; } } elseif ($stmt instanceof Stmt\ContinueStmt) { // Unlike in PHP, continue applies directly to loops. Given that we deconstruct switches to goto, this is trivial $result[] = str_repeat(' ', $level * 4) . 'continue;'; } elseif ($stmt instanceof Stmt\BreakStmt) { // We have to handle the deconstructed switches here as well $result[] = str_repeat(' ', $level * 4) . $this->activeBreakTarget; $this->usedBreak = true;
php
MIT
0b7fb71209b192e55a61ec2fb33a932a561dd82a
2026-01-05T04:39:07.148223Z
true
ircmaxell/FFIMe
https://github.com/ircmaxell/FFIMe/blob/0b7fb71209b192e55a61ec2fb33a932a561dd82a/lib/FFIMe.php
lib/FFIMe.php
<?php declare(strict_types=1); namespace FFIMe; use PHPCParser\Context; use PHPCParser\CParser; use PHPCParser\Node\Decl; use PHPCParser\Node\Type; use PHPCParser\PreProcessor\Token; use PHPObjectSymbolResolver\Parser as ObjectParser; class FFIMe { const LIBC = PHP_OS_FAMILY === "Darwin" ? "/usr/lib/libSystem.B.dylib" : "/lib/x86_64-linux-gnu/libc.so.6"; const TYPES_TO_REMOVE = [ 'void', 'char', '_Bool', 'int8_t', 'uint8_t', 'int16_t', 'uint16_t', 'int32_t', 'uint32_t', 'int64_t', 'uint64_t', 'float', 'double', ]; const RECORDS_TO_REMOVE = [ '_IO_FILE_plus', ]; const VARS_TO_REMOVE = [ '_IO_2_1_stdin_', '_IO_2_1_stdout_', '_IO_2_1_stderr_', 'sys_errlist', // sigh to FFI ]; const FUNCTIONS_TO_REMOVE = [ ]; private string $sofile; /** @var string[] */ private array $code = []; /** @var Decl[] contains declarations of exported symbols and typedefs */ private array $declarationAst = []; /** @var Decl[] contains declarations of exported symbols which are not in the primary shared objects */ private array $skippedDeclarationAst = []; /** @var Decl[] contains definitions, i.e. functions with statement bodies, non-exported variables */ private array $definitionAst = []; /** @var string[] */ private array $numericDefines = []; private ?array $restrictedCompiledClasses = null; private ?array $restrictedCompiledFunctions = null; private ?array $restrictedCompiledConstants = null; private ?array $restrictedCompiledGlobals = null; private Context $context; private CParser $cparser; /** @var string[] exported symbols */ private array $symbols; private bool $built = false; private bool $showWarnings = true; const DEFAULT_SO_SEARCH_PATHS = [ '/usr/local/lib', '/usr/lib', ]; /** @param string[] $headerSearchPaths * @param string[] $soSearchPaths */ public function __construct(string $sharedObjectFile, array $headerSearchPaths = [], array $soSearchPaths = self::DEFAULT_SO_SEARCH_PATHS) { $this->sofile = $this->findSOFile($sharedObjectFile, $soSearchPaths); $this->context = new Context($headerSearchPaths); $this->cparser = new CParser; $this->symbols = array_flip(ObjectParser::parseFor($this->sofile)->getAllSymbolsRecursively()); } public function defineInt(string $identifier, int $value): void { $this->context->define($identifier, new Token(Token::NUMBER, (string) $value, 'php')); } public function defineIdentifier(string $identifier, string $value): void { $this->context->define($identifier, new Token(Token::IDENTIFIER, $value, 'php')); } public function defineString(string $identifier, string $value): void { $this->context->define($identifier, new Token(Token::LITERAL, $value, 'php')); } public function include(string $header): self { if ($this->built) { throw new \RuntimeException("Already built, cannot include twice"); } $this->filterDeclarations($this->cparser->parse($header, $this->context)->declarations); return $this; } public function showWarnings(bool $show) { $this->showWarnings = $show; return $this; } public function warning(string $message) { if ($this->showWarnings) { echo "[Warning] $message\n"; } } /** @param string class to code map */ public function getCode(): array { return $this->code; } public function codeGen(string $className, string $filename): void { $code = $this->compile($className); file_put_contents($filename, '<?php ' . $code); } public function codeGenWithInstrumentation(string $className, string $filename): void { $code = $this->compile($className, true); file_put_contents($filename, '<?php ' . $code); } public function build(?string $className = null) { $className = $className ?? $this->getDynamicClassName(); eval($this->compile($className)); return $className::ffi(); } public function getDynamicClassName(): string { $class = 'ffime\ffime_'; do { $class .= mt_rand(0, 99); } while (class_exists($class)); return $class; } public function restrictCompiledClasses(?array $classes) { if ($classes && \is_string(current($classes))) { $classes = array_fill_keys($classes, 1); } $this->restrictedCompiledClasses = $classes; } public function restrictCompiledConstants(?array $constants) { if ($constants && \is_string(current($constants))) { $constants = array_fill_keys($constants, 1); } $this->restrictedCompiledConstants = $constants; } public function restrictCompiledGlobals(?array $globals) { if ($globals && \is_string(current($globals))) { $globals = array_fill_keys($globals, 1); } $this->restrictedCompiledGlobals = $globals; } public function restrictCompiledFunctions(?array $functions) { if ($functions && \is_string(current($functions))) { $functions = array_fill_keys($functions, false); } $this->restrictedCompiledFunctions = $functions; } private function checkTypeForClasses(string $namespace, \ReflectionType $type) { if ($type instanceof \ReflectionNamedType && str_starts_with($type->getName(), $namespace)) { $this->restrictedCompiledClasses[substr($type->getName(), \strlen($namespace))] = 1; } else { foreach ($type->getTypes() as $subtype) { $this->checkTypeForClasses($namespace, $subtype); } } } private function checkSignaturesForClasses(string $namespace, \ReflectionFunctionAbstract $func) { if ($ret = $func->getReturnType()) { $this->checkTypeForClasses($namespace, $ret); } foreach ($func->getParameters() as $parameter) { if ($type = $parameter->getType()) { $this->checkTypeForClasses($namespace, $type); } } } public function compile($className, $instrument = false): string { if (isset($this->code[$className]) && !$instrument) { return $this->code[$className]; } $this->filterSymbolDeclarations(); $ffiClass = "{$className}FFI"; if (class_exists($ffiClass, false) && isset($ffiClass::$__visitedClasses)) { $this->restrictCompiledClasses($ffiClass::$__visitedClasses); $this->restrictCompiledConstants($ffiClass::$__visitedConstants); $this->restrictCompiledFunctions($ffiClass::$__visitedFunctions); $this->restrictCompiledGlobals($ffiClass::$__visitedGlobals); } $compiler = new Compiler($instrument, $this->restrictedCompiledFunctions, $this->restrictedCompiledClasses, $this->restrictedCompiledConstants, $this->restrictedCompiledGlobals); $this->numericDefines = $this->context->getNumericDefines(); $code = $compiler->compile($this->sofile, $this->declarationAst, $this->definitionAst, $this->skippedDeclarationAst, $this->numericDefines, $className); foreach ($compiler->warnings as $warning) { $this->warning($warning); } if (!$instrument) { $this->code[$className] = $code; } return $code; } /** @param string[] $searchPaths */ private function findSOFile(string $filename, array $searchPaths): string { if (is_file($filename)) { // no searching needed return $filename; } // Under MacOS dyld (runtime linker) has a cache of specific objects tied to paths, which actually do not exist on disk. They have an equivalent path in the SDK, containing their exported symbol definitions if (PHP_OS_FAMILY === 'Darwin' && str_starts_with($filename, '/usr/lib/')) { if (is_file(str_replace(".dylib", ".tbd", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk$filename"))) { return $filename; } } foreach ($searchPaths as $path) { $test = $path . '/' . $filename; if (file_exists($test)) { return $test; } } throw new \LogicException('Could not find shared object file ' . $filename); } protected function isExternType(Type $type) { while ($type instanceof Type\AttributedType) { if ($type instanceof Type\ExplicitAttributedType && $type->kind === Type\ExplicitAttributedType::KIND_EXTERN) { return true; } $type = $type->parent; } return false; } protected function filterSymbolDeclarations(): void { $result = $skipped = []; foreach ($this->declarationAst as $declaration) { if ($declaration instanceof Decl\NamedDecl\ValueDecl\DeclaratorDecl\FunctionDecl) { if (isset($this->symbols[$declaration->name]) || isset($this->symbols["_{$declaration->name}"])) { $result[] = $declaration; } else { $skipped[] = $declaration; $this->warning("Skipping {$declaration->name}, not found in object file"); } } elseif ($declaration instanceof Decl\NamedDecl\ValueDecl\DeclaratorDecl\VarDecl) { if ($this->isExternType($declaration->type)) { if (isset($this->symbols[$declaration->name]) || isset($this->symbols["_{$declaration->name}"])) { $result[] = $declaration; } else { $skipped[] = $declaration; $this->warning("Skipping {$declaration->name}, not found in object file"); } } else { array_unshift($this->definitionAst, $declaration); } } else { $result[] = $declaration; } } $this->declarationAst = $result; $this->skippedDeclarationAst = $skipped; } /** @param Decl[] $declarations */ protected function filterDeclarations(array $declarations) { $result = []; foreach ($declarations as $declaration) { if ($declaration instanceof Decl\NamedDecl\TypeDecl\TypedefNameDecl\TypedefDecl) { if (!in_array($declaration->name, self::TYPES_TO_REMOVE)) { $result[] = $declaration; } } elseif ($declaration instanceof Decl\NamedDecl\TypeDecl\TagDecl\RecordDecl) { if (!in_array($declaration->name, self::RECORDS_TO_REMOVE)) { $result[] = $declaration; } } elseif ($declaration instanceof Decl\NamedDecl\ValueDecl\DeclaratorDecl\FunctionDecl) { if ($declaration->stmts === null) { // only declarations, not definitions if (!in_array($declaration->name, self::FUNCTIONS_TO_REMOVE)) { // Skip __ functions $result[] = $declaration; } } else { if (!in_array($declaration->name, self::FUNCTIONS_TO_REMOVE)) { // Skip __ functions $this->definitionAst[] = $declaration; } } } elseif ($declaration instanceof Decl\NamedDecl\ValueDecl\DeclaratorDecl\VarDecl) { if (!in_array($declaration->name, self::VARS_TO_REMOVE)) { $result[] = $declaration; } } elseif ($declaration instanceof Decl\NamedDecl\TypeDecl\TagDecl\EnumDecl) { $result[] = $declaration; } else { throw new \LogicException('Unknown declaration type to skip/ignore: ' . get_class($declaration)); } } $this->declarationAst = array_merge($this->declarationAst, $result); } }
php
MIT
0b7fb71209b192e55a61ec2fb33a932a561dd82a
2026-01-05T04:39:07.148223Z
false
ircmaxell/FFIMe
https://github.com/ircmaxell/FFIMe/blob/0b7fb71209b192e55a61ec2fb33a932a561dd82a/lib/UnsupportedFeatureException.php
lib/UnsupportedFeatureException.php
<?php namespace FFIMe; class UnsupportedFeatureException extends \Exception { const COMPLEX = 1; public int $feature; public function __construct(int $feature, string $message = "") { $this->feature = $feature; parent::__construct($message); } }
php
MIT
0b7fb71209b192e55a61ec2fb33a932a561dd82a
2026-01-05T04:39:07.148223Z
false
ircmaxell/FFIMe
https://github.com/ircmaxell/FFIMe/blob/0b7fb71209b192e55a61ec2fb33a932a561dd82a/lib/BuiltinFunction.php
lib/BuiltinFunction.php
<?php namespace FFIMe; class BuiltinFunction { /** @var BuiltinFunction[] */ public static array $registry = []; public string $name; public CompiledType $type; public string $body; public function __construct(string $name, CompiledType $type, string $body) { $this->name = $name; $this->type = $type; $this->body = $body; self::$registry[$name] = $this; } public function print(): array { $return[] = " private function " . Compiler::COMPILED_PREFIX . $this->name . $this->body; return $return; } } new BuiltinFunction("__builtin_expect", new CompiledType("int"), '(int $val, int $expected) { return $val; }'); new BuiltinFunction("__builtin_constant_p", new CompiledType("int"), '(int $val) { return 0; }'); new BuiltinFunction("__builtin_bswap16", new CompiledType("int", rawValue: "uint16_t"), '(int $val) { return ($val >> 8) | (($val << 8) & 0xff00); }'); new BuiltinFunction("__builtin_bswap32", new CompiledType("int", rawValue: "uint32_t"), '(int $val) { return (($val & 0xff000000) >> 24) | (($val & 0xff0000) >> 8) | (($val & 0xff00) << 8) | (($val & 0xff) << 24); }'); new BuiltinFunction("__builtin_bswap64", new CompiledType("int", rawValue: "uint64_t"), '(int $val) { return (($val & 0xff00000000000000) >> 56) | (($val & 0xff000000000000) >> 40) | (($val & 0xff0000000000) >> 24) | (($val & 0xff00000000) >> 8) | (($val & 0xff000000) << 8) | (($val & 0xff0000) << 24) | (($val & 0xff00) << 40) | (($val & 0xff) << 56); }'); new BuiltinFunction("__builtin_object_size", new CompiledType("int", rawValue: "size_t"), '(FFI\CData $ptr, int $type) { return $type <= 1 ? -1 : 0; }'); // Defaults when "conditions not met" new BuiltinFunction("__builtin_huge_val", new CompiledType("float", rawValue: "double"), '() { return INF; }'); new BuiltinFunction("__builtin_inf", new CompiledType("float", rawValue: "double"), '() { return INF; }'); new BuiltinFunction("__builtin_inff", new CompiledType("float"), '() { return INF; }'); new BuiltinFunction("__builtin_infl", new CompiledType("float", rawValue: "long double"), '() { return INF; }'); // __builtin___*_chk functions new BuiltinFunction("__builtin___memcpy_chk", new CompiledType("void", [null]), '(FFI\CData $dest, FFI\CData $src, int $len, int $destlen) { return $this->ffi->memcpy($dest, $src, $len); }'); new BuiltinFunction("__builtin___mempcpy_chk", new CompiledType("void", [null]), '(FFI\CData $dest, FFI\CData $src, int $len, int $destlen) { return $this->ffi->mempcpy($dest, $src, $len); }'); new BuiltinFunction("__builtin___memmove_chk", new CompiledType("void", [null]), '(FFI\CData $dest, FFI\CData $src, int $len, int $destlen) { return $this->ffi->memmove($dest, $src, $len); }'); new BuiltinFunction("__builtin___memset_chk", new CompiledType("void", [null]), '(FFI\CData $dest, int $c, int $len, int $destlen) { return $this->ffi->memset($dest, $c, $len); }'); new BuiltinFunction("__builtin___strcpy_chk", new CompiledType("int", [null], rawValue: "char"), '(FFI\CData $dest, FFI\CData $src, int $destlen) { return $this->ffi->strcpy($dest, $src); }'); new BuiltinFunction("__builtin___strncpy_chk", new CompiledType("int", [null], rawValue: "char"), '(FFI\CData $dest, FFI\CData $src, int $len, int $destlen) { return $this->ffi->strncpy($dest, $src, $len); }'); new BuiltinFunction("__builtin___stpcpy_chk", new CompiledType("int", [null], rawValue: "char"), '(FFI\CData $dest, FFI\CData $src, int $destlen) { return $this->ffi->stpcpy($dest, $src); }'); new BuiltinFunction("__builtin___strcat_chk", new CompiledType("int", [null], rawValue: "char"), '(FFI\CData $dest, FFI\CData $src, int $destlen) { return $this->ffi->strcat($dest, $src); }'); new BuiltinFunction("__builtin___strncat_chk", new CompiledType("int", [null], rawValue: "char"), '(FFI\CData $dest, FFI\CData $src, int $len, int $destlen) { return $this->ffi->strncat($dest, $src, $len); }'); new BuiltinFunction("__builtin___sprintf_chk", new CompiledType("int"), '(FFI\CData $buf, int $flag, int $destlen, FFI\CData $fmt, ...$args) { return $this->ffi->sprintf($buf, $fmt, ...$args); }'); new BuiltinFunction("__builtin___snprintf_chk", new CompiledType("int"), '(FFI\CData $buf, int $maxlen, int $flag, int $destlen, FFI\CData $fmt, ...$args) { return $this->ffi->snprintf($buf, $maxlen, $fmt, ...$args); }'); new BuiltinFunction("__builtin___vsprintf_chk", new CompiledType("int"), '(FFI\CData $buf, int $flag, int $destlen, FFI\CData $fmt, FFI\CData $va_list) { return $this->ffi->vsprintf($buf, $fmt, $va_list); }'); new BuiltinFunction("__builtin___vsnprintf_chk", new CompiledType("int"), '(FFI\CData $buf, int $maxlen, int $flag, int $destlen, FFI\CData $fmt, FFI\CData $va_list) { return $this->ffi->vsnprintf($buf, $maxlen, $fmt, $va_list); }'); new BuiltinFunction("__builtin___printf_chk", new CompiledType("int"), '(int $flag, FFI\CData $fmt, ...$args) { return $this->ffi->printf($fmt, ...$args); }'); new BuiltinFunction("__builtin___vprintf_chk", new CompiledType("int"), '(int $flag, FFI\CData $fmt, FFI\CData $va_list) { return $this->ffi->vprintf($fmt, $va_list); }'); new BuiltinFunction("__builtin___fprintf_chk", new CompiledType("int"), '(FFI\CData $stream, int $flag, FFI\CData $fmt, ...$args) { return $this->ffi->fprintf($fmt, ...$args); }'); new BuiltinFunction("__builtin___vfprintf_chk", new CompiledType("int"), '(FFI\CData $stream, int $flag, FFI\CData $fmt, FFI\CData $va_list) { return $this->ffi->vfprintf($fmt, $va_list); }');
php
MIT
0b7fb71209b192e55a61ec2fb33a932a561dd82a
2026-01-05T04:39:07.148223Z
false
ircmaxell/FFIMe
https://github.com/ircmaxell/FFIMe/blob/0b7fb71209b192e55a61ec2fb33a932a561dd82a/lib/CompiledExpr.php
lib/CompiledExpr.php
<?php namespace FFIMe; class CompiledExpr { public string $value; public bool $cdata; public CompiledType $type; public function __construct(string $value, ?CompiledType $type = null, bool $cdata = false) { $this->value = $value; $this->type = $type ?? new CompiledType('int'); $this->cdata = $cdata; } public function toValue(?CompiledType $type = null, $charConvert = true): string { $val = $this->value; if ($type && $this->type != $type) { if ($this->type->indirections) { $val = '$this->ffi->cast("' . $type->toValue() . '", ' . $val . ')'; } elseif (!$type->indirections && ($this->type->rawValue === 'char') !== ($type->rawValue === 'char')) { if ($type->rawValue === 'char') { $val = '\chr(' . $val . ')'; } else { $val = '\ord(' . $val . ')'; } } return $this->cdata && $type->isNative ? '(' . $val . ')->cdata' : $val; } else { if ($this->cdata && $this->type->isNative) { $val = '(' . $val . ')->cdata'; } if ($charConvert && !$this->type->indirections && $this->type->rawValue === 'char') { $val = '\ord(' . $val . ')'; } return $val; } } public function toBool(): string { $value = $this->value; if ($this->cdata) { if ($this->type->isNative) { $value = '(' . $this->value . ')->cdata'; } else { return '!FFI::isNull(' . $this->value . ')'; } } if ($this->type->rawValue === 'char') { $value = '(' . $value . ' !== "\0")'; } return $value; } public function withCurrent(string $newExpr, int $modifyPointer = 0): self { $type = $this->type; $cdata = $this->cdata; if ($modifyPointer) { if ($modifyPointer < 0) { $indirections = array_slice($type->indirections, 1); } else { $indirections = []; } $type = new CompiledType($type->value, $indirections, $type->rawValue); $cdata = !$type->isNative; } return new self($newExpr, $type, $cdata); } }
php
MIT
0b7fb71209b192e55a61ec2fb33a932a561dd82a
2026-01-05T04:39:07.148223Z
false
ircmaxell/FFIMe
https://github.com/ircmaxell/FFIMe/blob/0b7fb71209b192e55a61ec2fb33a932a561dd82a/lib/CompiledType.php
lib/CompiledType.php
<?php namespace FFIMe; class CompiledType { public string $value; public string $rawValue; /** @var int[]|null[]|false[] */ public array $indirections; public bool $isNative; /** @param int[]|null[]|false[] $indirections */ public function __construct(string $value, array $indirections = [], ?string $rawValue = null) { $this->value = $value; $this->indirections = $indirections; $this->rawValue = $rawValue ?? $value; $this->isNative = !$indirections && $this->baseTypeIsNative(); } public function indirections(): int { return \count($this->indirections); } public function toValue(?string $compiledBaseType = null): string { $value = $compiledBaseType ?? $this->rawValue; foreach ($this->indirections as $indirection) { if ($indirection === null || $indirection === false) { $value .= '*'; } else { $value .= "[$indirection]"; } } return $value; } public function baseTypeIsNative(): bool { return $this->value === 'int' || $this->value === 'float'; } }
php
MIT
0b7fb71209b192e55a61ec2fb33a932a561dd82a
2026-01-05T04:39:07.148223Z
false
ircmaxell/FFIMe
https://github.com/ircmaxell/FFIMe/blob/0b7fb71209b192e55a61ec2fb33a932a561dd82a/lib/NotExportedFunctionException.php
lib/NotExportedFunctionException.php
<?php namespace FFIMe; class NotExportedFunctionException extends \Exception { }
php
MIT
0b7fb71209b192e55a61ec2fb33a932a561dd82a
2026-01-05T04:39:07.148223Z
false
adamgriffiths/ag-auth
https://github.com/adamgriffiths/ag-auth/blob/5e83e14f80fe7ab71a682b27f0ea014c9c10690b/helpers/ag_auth_helper.php
helpers/ag_auth_helper.php
<?php function logged_in() { $CI =& get_instance(); if($CI->ag_auth->logged_in() == TRUE) { return TRUE; } return FALSE; } function username() { $CI =& get_instance(); return $CI->session->userdata('username'); } function user_group($group) { $CI =& get_instance(); $system_group = $CI->ag_auth->config['auth_groups'][$group]; if($system_group === $CI->session->userdata('group_id')) { return TRUE; } } function user_table() { $CI =& get_instance(); return $CI->ag_auth->user_table; } function group_table() { $CI =& get_instance(); return $CI->ag_auth->group_table; } ?>
php
MIT
5e83e14f80fe7ab71a682b27f0ea014c9c10690b
2026-01-05T04:39:19.688431Z
false
adamgriffiths/ag-auth
https://github.com/adamgriffiths/ag-auth/blob/5e83e14f80fe7ab71a682b27f0ea014c9c10690b/controllers/admin/users.php
controllers/admin/users.php
<?php class Users extends Application { public function __construct() { parent::__construct(); $this->ag_auth->restrict('admin'); // restrict this controller to admins only } public function manage() { $this->load->library('table'); $data = $this->db->get($this->ag_auth->config['auth_user_table']); $result = $data->result_array(); $this->table->set_heading('Username', 'Email', 'Actions'); // Setting headings for the table foreach($result as $value => $key) { $actions = anchor("admin/users/delete/".$key['id']."/", "Delete"); // Build actions links $this->table->add_row($key['username'], $key['email'], $actions); // Adding row to table } $this->ag_auth->view('users/manage'); // Load the view } public function delete($id) { $this->db->where('id', $id)->delete($this->ag_auth->config['auth_user_table']); $this->ag_auth->view('users/delete_success'); } // WOKRING ON PROPER IMPLEMENTATION OF ADDING & EDITING USER ACCOUNTS } ?>
php
MIT
5e83e14f80fe7ab71a682b27f0ea014c9c10690b
2026-01-05T04:39:19.688431Z
false
adamgriffiths/ag-auth
https://github.com/adamgriffiths/ag-auth/blob/5e83e14f80fe7ab71a682b27f0ea014c9c10690b/controllers/admin/admin.php
controllers/admin/admin.php
<?php class Admin extends Application { public function __construct() { parent::__construct(); } public function index() { if(logged_in()) { $this->ag_auth->view('dashboard'); } else { $this->login(); } } } /* End of file: dashboard.php */ /* Location: application/controllers/admin/dashboard.php */
php
MIT
5e83e14f80fe7ab71a682b27f0ea014c9c10690b
2026-01-05T04:39:19.688431Z
false
adamgriffiths/ag-auth
https://github.com/adamgriffiths/ag-auth/blob/5e83e14f80fe7ab71a682b27f0ea014c9c10690b/models/ag_auth_model.php
models/ag_auth_model.php
<?php /** * Authentication Library * * @package Authentication * @category Libraries * @author Adam Griffiths * @link http://adamgriffiths.co.uk * @version 2.0.3 * @copyright Adam Griffiths 2011 * * Auth provides a powerful, lightweight and simple interface for user authentication . */ class AG_Auth_model extends CI_Model { var $user_table; // The user table (prefix + config) var $group_table; // The group table (prefix + config) public function __construct() { parent::__construct(); log_message('debug', 'Auth Model Loaded'); $this->config->load('ag_auth'); $this->load->database(); $this->user_table = $this->config->item('auth_user_table'); $this->group_table = $this->config->item('auth_group_table'); } public function login_check($username, $field_type) { $query = $this->db->get_where($this->user_table, array($field_type => $username)); $result = $query->row_array(); return $result; } public function register($username, $password, $email) { if($this->db->set('username', $username)->set('password', $password)->set('email', $email)->set('group_id', '100')->insert($this->user_table)) { return TRUE; } return FALSE; } public function field_exists($value) { $field_name = (valid_email($value) ? 'email' : 'username'); $query = $this->db->get_where($this->user_table, array($field_name => $value)); if($query->num_rows() <> 0) { return FALSE; } return TRUE; } } /* End of file: ag_auth_model.php */ /* Location: application/models/auth_model.php */
php
MIT
5e83e14f80fe7ab71a682b27f0ea014c9c10690b
2026-01-05T04:39:19.688431Z
false
adamgriffiths/ag-auth
https://github.com/adamgriffiths/ag-auth/blob/5e83e14f80fe7ab71a682b27f0ea014c9c10690b/views/auth/footer.php
views/auth/footer.php
</div> </body> </html>
php
MIT
5e83e14f80fe7ab71a682b27f0ea014c9c10690b
2026-01-05T04:39:19.688431Z
false
adamgriffiths/ag-auth
https://github.com/adamgriffiths/ag-auth/blob/5e83e14f80fe7ab71a682b27f0ea014c9c10690b/views/auth/index.php
views/auth/index.php
<?php $this->load->view($this->config->item('auth_views_root') . 'header'); if(isset($data)) { $this->load->view($this->config->item('auth_views_root') . 'pages/'.$page, $data); } else { $this->load->view($this->config->item('auth_views_root') . 'pages/'.$page); } $this->load->view($this->config->item('auth_views_root') . 'footer'); ?>
php
MIT
5e83e14f80fe7ab71a682b27f0ea014c9c10690b
2026-01-05T04:39:19.688431Z
false
adamgriffiths/ag-auth
https://github.com/adamgriffiths/ag-auth/blob/5e83e14f80fe7ab71a682b27f0ea014c9c10690b/views/auth/header.php
views/auth/header.php
<!DOCTYPE HTML> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <style type="text/css"> body{background-image:none;background-color:white;color:#231e18;background-repeat:no-repeat;margin:0;font-family:Helvetica;font-size:12px;} #container{width:1000px;margin:0 auto;} #header{width:100%;margin:0;padding:0;} #logo{width:1000px;margin:0 auto;color:#231e18;} #nav_bg{background:#231e18;width:100%;height:52px;} ul#navigation{list-style-type:none;width:1000px;margin:0 auto;} ul#navigation li a{color:white;font-size:18px;float:left;padding:15px 20px 20px 20px;margin-right:10px;} ul#navigation li a:hover{color:#231e18;background:white;font-size:18px;float:left;padding:15px 20px 20px 20px;margin-right:10px;} ul#navigation li a.selected{color:#231e18;background:white;font-size:18px;float:left;padding:15px 20px 20px 20px;} #login{margin:0 auto;margin-left:40px;} .box{width:726px;margin:0;padding:0;} p{margin-left:40px;} input.clean{padding:4px;border:1px solid #231e18;} table{width:900px;text-align:left;margin:20px 0 0 0;} table tr.alt{background:#ECECEC;} a{color:#231e18;margin-right:10px;} </style> <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.7.0/build/fonts/fonts-min.css" /> <title>The Authentication Library Control Panel</title> </head> <body> <div id="header"> <div id="logo"> <h1>The Authentication Library Admin Panel</h1> </div> </div> <div id="nav_bg"> <?php $this->load->view($this->config->item('auth_views_root') . 'nav'); ?> </div> <div id="container">
php
MIT
5e83e14f80fe7ab71a682b27f0ea014c9c10690b
2026-01-05T04:39:19.688431Z
false
adamgriffiths/ag-auth
https://github.com/adamgriffiths/ag-auth/blob/5e83e14f80fe7ab71a682b27f0ea014c9c10690b/views/auth/nav.php
views/auth/nav.php
<ul id="navigation"> <?php if(logged_in()) { ?> <li><?php echo anchor('admin/dashboard', 'Dashboard'); ?></li> <li><?php if(user_group('admin')) { echo anchor('admin/users/manage', 'Manage Users'); } ?></li> <li><?php echo anchor('logout', 'Logout'); ?></li> <?php } else { ?> <li><?php echo anchor('login', 'Login'); ?></li> <li><?php echo anchor('register', 'Register'); ?></li> <?php } ?> </ul>
php
MIT
5e83e14f80fe7ab71a682b27f0ea014c9c10690b
2026-01-05T04:39:19.688431Z
false
adamgriffiths/ag-auth
https://github.com/adamgriffiths/ag-auth/blob/5e83e14f80fe7ab71a682b27f0ea014c9c10690b/views/auth/pages/logout.php
views/auth/pages/logout.php
<div id="login"> <h2>Logout</h2> <div class="box"> You have been successfully logged out! </div> </div>
php
MIT
5e83e14f80fe7ab71a682b27f0ea014c9c10690b
2026-01-05T04:39:19.688431Z
false
adamgriffiths/ag-auth
https://github.com/adamgriffiths/ag-auth/blob/5e83e14f80fe7ab71a682b27f0ea014c9c10690b/views/auth/pages/login.php
views/auth/pages/login.php
<div id="login"> <h2>Login</h2> <div class="box"> <?php echo form_open(); ?> Username/Email:<br /> <input type="text" name="username" value="<?php echo set_value('username'); ?>" size="50" class="form" /><?php echo form_error('username'); ?><br /><br /> Password:<br /> <input type="password" name="password" value="<?php echo set_value('password'); ?>" size="50" class="form" /><?php echo form_error('password'); ?><br /><br /> <input type="submit" value="Login" name="login" /> </form> </div> </div>
php
MIT
5e83e14f80fe7ab71a682b27f0ea014c9c10690b
2026-01-05T04:39:19.688431Z
false
adamgriffiths/ag-auth
https://github.com/adamgriffiths/ag-auth/blob/5e83e14f80fe7ab71a682b27f0ea014c9c10690b/views/auth/pages/register.php
views/auth/pages/register.php
<div id="login"> <?php if(empty($username)) { ?> <h2>Register</h2> <?php } else { ?> <h2>Update</h2> <?php } ?> <div class="box"> <?php echo form_open(); ?> <?php if(empty($username)) { ?> Username:<br /> <input type="text" name="username" size="50" class="form" value="<?php echo set_value('username'); ?>" /><br /><?php echo form_error('username'); ?><br /> Password:<br /> <input type="password" name="password" size="50" class="form" value="<?php echo set_value('password'); ?>" /><?php echo form_error('password'); ?><br /><br /> Password confirmation:<br /> <input type="password" name="password_conf" size="50" class="form" value="<?php echo set_value('conf_password'); ?>" /><?php echo form_error('conf_password'); ?><br /><br /> <?php } ?> Email:<br /> <?php if(empty($username)){ ?> <input type="text" name="email" size="50" class="form" value="<?php echo set_value('email'); ?>" /><?php echo form_error('email'); ?><br /><br /> <?php }else{ ?> <input type="text" name="email" size="50" class="form" value="<?php echo set_value('email', $email); ?>" /><?php echo form_error('email'); ?><br /><br /> <?php } if(empty($username)) { ?> <input type="submit" value="Register" name="register" /> <?php } else { ?> <input type="submit" value="Update" name="register" /> <?php } ?> </form> </div> </div>
php
MIT
5e83e14f80fe7ab71a682b27f0ea014c9c10690b
2026-01-05T04:39:19.688431Z
false
adamgriffiths/ag-auth
https://github.com/adamgriffiths/ag-auth/blob/5e83e14f80fe7ab71a682b27f0ea014c9c10690b/views/auth/pages/message.php
views/auth/pages/message.php
<h2>Message</h2> <p><?php echo $message; ?></p>
php
MIT
5e83e14f80fe7ab71a682b27f0ea014c9c10690b
2026-01-05T04:39:19.688431Z
false
adamgriffiths/ag-auth
https://github.com/adamgriffiths/ag-auth/blob/5e83e14f80fe7ab71a682b27f0ea014c9c10690b/views/auth/pages/reg_success.php
views/auth/pages/reg_success.php
<div id="login"> <h2>Success!</h2> <div class="box"> <?php echo $msg; ?> </div> </div>
php
MIT
5e83e14f80fe7ab71a682b27f0ea014c9c10690b
2026-01-05T04:39:19.688431Z
false
adamgriffiths/ag-auth
https://github.com/adamgriffiths/ag-auth/blob/5e83e14f80fe7ab71a682b27f0ea014c9c10690b/views/auth/pages/dashboard.php
views/auth/pages/dashboard.php
<h2>Dashboard</h2> <p>Welcome <?php echo username(); ?>.</p>
php
MIT
5e83e14f80fe7ab71a682b27f0ea014c9c10690b
2026-01-05T04:39:19.688431Z
false
adamgriffiths/ag-auth
https://github.com/adamgriffiths/ag-auth/blob/5e83e14f80fe7ab71a682b27f0ea014c9c10690b/views/auth/pages/users/manage.php
views/auth/pages/users/manage.php
<h2>Manage Users</h2> <?php echo $this->table->generate(); ?>
php
MIT
5e83e14f80fe7ab71a682b27f0ea014c9c10690b
2026-01-05T04:39:19.688431Z
false
adamgriffiths/ag-auth
https://github.com/adamgriffiths/ag-auth/blob/5e83e14f80fe7ab71a682b27f0ea014c9c10690b/views/auth/pages/users/delete_success.php
views/auth/pages/users/delete_success.php
<h2>User Successfully Deleted</h2> <p>The user has now been deleted.</p>
php
MIT
5e83e14f80fe7ab71a682b27f0ea014c9c10690b
2026-01-05T04:39:19.688431Z
false
adamgriffiths/ag-auth
https://github.com/adamgriffiths/ag-auth/blob/5e83e14f80fe7ab71a682b27f0ea014c9c10690b/libraries/ag_auth.php
libraries/ag_auth.php
<?php /** * Authentication Library * * @package Authentication * @category Libraries * @author Adam Griffiths * @link http://adamgriffiths.co.uk * @version 2.0.3 * @copyright Adam Griffiths 2011 * * Auth provides a powerful, lightweight and simple interface for user authentication . */ ob_start(); class AG_Auth { var $CI; // The CI object var $config; // The config items /** * @author Adam Griffiths * @param array * * The constructor public function loads the libraries dependancies and creates the * login attempts cookie if it does not already exist. */ public function __construct($config) { log_message('debug', 'Auth Library Loaded'); $this->config = $config; $this->CI =& get_instance(); $this->CI->load->database(); $this->CI->load->library('session'); $this->CI->load->helper('email'); $this->CI->load->model('ag_auth_model'); $this->CI->lang->load('ag_auth', 'english'); if($this->logged_in() == FALSE) { if(!array_key_exists('login_attempts', $_COOKIE)) { setcookie("login_attempts", 0, time()+900, '/'); } } } /** * Restricts access to a page * * Takes a user level (e.g. admin, user etc) and restricts access to that user and above. * Example, users can access a profile page, but so can admins (who are above users) * * @access public * @param string * @return bool */ public function restrict($group = NULL, $single = NULL) { if($group === NULL) { if($this->logged_in() == TRUE) { return TRUE; } else { show_error($this->CI->lang->line('insufficient_privs')); } } elseif($this->logged_in() == TRUE) { $level = $this->config['auth_groups'][$group]; $user_level = $this->CI->session->userdata('group_id'); if($user_level > $level OR $single == TRUE && $user_level !== $level) { show_error($this->CI->lang->line('insufficient_privs')); } return TRUE; } else { redirect($this->config['auth_incorrect_login'], 'refresh'); } } // public function restrict() /** * @author Adam Griffiths * @return bool * * Checks the session data as to whether or not a user is logged in. */ public function logged_in() { if($this->CI->session->userdata('logged_in') === TRUE) { return TRUE; } else { return FALSE; } } /** * @author Adam Griffiths * @param string * @return string * * Uses the encryption key set in application/config/config.php to salt the password passed. */ public function salt($password) { return hash("haval256,5", $this->CI->config->item('encryption_key') . $password); } /** * @author Adam Griffiths * @param string * @param string * @return string / bool * * Takes a username & optional username type (email/username) and returns the user data */ public function get_user($username, $field_type = 'username') { $user = $this->CI->ag_auth_model->login_check($username, $field_type); return $user; } /** * @author Adam Griffiths * @param string * @param string * @param string * @return bool * * Creates a new user account */ public function register($username, $password, $email) { return $this->CI->ag_auth_model->register($username, $password, $email); } /** * @author Adam Griffiths * @param array * * Takes the user array, adds the logged_in portion and sets the session data from that. */ public function login_user($user) { $user['logged_in'] = TRUE; $this->CI->session->set_userdata($user); } /** * Destroys the user session. * * @access public */ public function logout() { $this->CI->session->sess_destroy(); redirect($this->CI->config->item('auth_logout')); } /** * Generate a new token/identifier from random.org * * @author Adam Griffiths * @access private * @param string */ private function _generate() { $username = $this->CI->session->userdata('username'); // No love either way, generate a random string ourselves $length = 20; $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $token = ""; for ($i = 0; $i < $length; $i++) { $token .= $characters[mt_rand(0, strlen($characters)-1)]; } $identifier = $username . $token; $identifier = $this->_salt($identifier); $this->CI->db->query("UPDATE `$this->user_table` SET `identifier` = '$identifier', `token` = '$token' WHERE `username` = '$username'"); setcookie("logged_in", $identifier, time()+3600, '/'); } /** * Verify that a user has a cookie, if not generate one. If the cookie doesn't match the database, log the user out and show them an error. * * @access private * @param string */ private function _verify_cookie() { if((array_key_exists('login_attempts', $_COOKIE)) && ($_COOKIE['login_attempts'] <= 5)) { $username = $this->CI->session->userdata('username'); $userdata = $this->CI->db->query("SELECT * FROM `$this->user_table` WHERE `username` = '$username'"); $result = $userdata->row(); $identifier = $result->username . $result->token; $identifier = $this->_salt($identifier); if($identifier !== $_COOKIE['logged_in']) { $this->CI->session->sess_destroy(); show_error($this->CI->lang->line('logout_perms_error')); } } else { $this->_generate(); } } /** * Load an auth specific view * * @access private * @param string */ public function view($page, $params = NULL) { if($params !== NULL) { $data['data'] = $params; } $data['page'] = $page; $this->CI->load->view($this->config['auth_views_root'].'index', $data); } } /* End of file: AG_Auth.php */ /* Location: application/libraries/AG_Auth.php */
php
MIT
5e83e14f80fe7ab71a682b27f0ea014c9c10690b
2026-01-05T04:39:19.688431Z
false
adamgriffiths/ag-auth
https://github.com/adamgriffiths/ag-auth/blob/5e83e14f80fe7ab71a682b27f0ea014c9c10690b/core/MY_Controller.php
core/MY_Controller.php
<?php /** * Authentication Library * * @package Authentication * @category Libraries * @author Adam Griffiths * @link http://adamgriffiths.co.uk * @version 2.0.3 * @copyright Adam Griffiths 2011 * * Auth provides a powerful, lightweight and simple interface for user authentication . */ class Application extends CI_Controller { public function __construct() { parent::__construct(); log_message('debug', 'Application Loaded'); $this->load->library(array('form_validation', 'ag_auth')); $this->load->helper(array('url', 'email', 'ag_auth')); $this->config->load('ag_auth'); } public function field_exists($value) { $field_name = (valid_email($value) ? 'email' : 'username'); $user = $this->ag_auth->get_user($value, $field_name); if(array_key_exists('id', $user)) { $this->form_validation->set_message('field_exists', 'The ' . $field_name . ' provided already exists, please use another.'); return FALSE; } else { return TRUE; } // if($this->field_exists($value) === TRUE) } // public function field_exists($value) public function register() { $this->form_validation->set_rules('username', 'Username', 'required|min_length[6]|callback_field_exists'); $this->form_validation->set_rules('password', 'Password', 'required|min_length[6]|matches[password_conf]'); $this->form_validation->set_rules('password_conf', 'Password Confirmation', 'required|min_length[6]|matches[password]'); $this->form_validation->set_rules('email', 'Email Address', 'required|min_length[6]|valid_email|callback_field_exists'); if($this->form_validation->run() == FALSE) { $this->ag_auth->view('register'); } else { $username = set_value('username'); $password = $this->ag_auth->salt(set_value('password')); $email = set_value('email'); if($this->ag_auth->register($username, $password, $email) === TRUE) { $data['message'] = "The user account has now been created."; $this->ag_auth->view('message', $data); } // if($this->ag_auth->register($username, $password, $email) === TRUE) else { $data['message'] = "The user account has not been created."; $this->ag_auth->view('message', $data); } } // if($this->form_validation->run() == FALSE) } // public function register() public function login($redirect = NULL) { if($redirect === NULL) { $redirect = $this->ag_auth->config['auth_login']; } $this->form_validation->set_rules('username', 'Username', 'required|min_length[6]'); $this->form_validation->set_rules('password', 'Password', 'required|min_length[6]'); if($this->form_validation->run() == FALSE) { $this->ag_auth->view('login'); } else { $username = set_value('username'); $password = $this->ag_auth->salt(set_value('password')); $field_type = (valid_email($username) ? 'email' : 'username'); $user_data = $this->ag_auth->get_user($username, $field_type); if(array_key_exists('password', $user_data) AND $user_data['password'] === $password) { unset($user_data['password']); unset($user_data['id']); $this->ag_auth->login_user($user_data); redirect($redirect); } // if($user_data['password'] === $password) else { $data['message'] = "The username and password did not match."; $this->ag_auth->view('message', $data); } } // if($this->form_validation->run() == FALSE) } // login() public function logout() { $this->ag_auth->logout(); } } /* End of file: MY_Controller.php */ /* Location: application/core/MY_Controller.php */
php
MIT
5e83e14f80fe7ab71a682b27f0ea014c9c10690b
2026-01-05T04:39:19.688431Z
false
adamgriffiths/ag-auth
https://github.com/adamgriffiths/ag-auth/blob/5e83e14f80fe7ab71a682b27f0ea014c9c10690b/config/routes.php
config/routes.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /* | ------------------------------------------------------------------------- | URI ROUTING | ------------------------------------------------------------------------- | This file lets you re-map URI requests to specific controller functions. | | Typically there is a one-to-one relationship between a URL string | and its corresponding controller class/method. The segments in a | URL normally follow this pattern: | | example.com/class/method/id/ | | In some instances, however, you may want to remap this relationship | so that a different class/function is called than the one | corresponding to the URL. | | Please see the user guide for complete details: | | http://codeigniter.com/user_guide/general/routing.html | | ------------------------------------------------------------------------- | RESERVED ROUTES | ------------------------------------------------------------------------- | | There are two reserved routes: | | $route['default_controller'] = 'welcome'; | | This route indicates which controller class should be loaded if the | URI contains no data. In the above example, the "welcome" class | would be loaded. | | $route['scaffolding_trigger'] = 'scaffolding'; | | This route lets you set a "secret" word that will trigger the | scaffolding feature for added security. Note: Scaffolding must be | enabled in the controller in which you intend to use it. The reserved | routes must come before any wildcard or regular expression routes. | */ $route['default_controller'] = "welcome"; $route['scaffolding_trigger'] = ""; // BEGIN AUTHENTICATION LIBRARY ROUTES $route['login'] = "admin/admin/login"; $route['logout'] = "admin/admin/logout"; $route['register'] = "admin/admin/register"; $route['admin/dashboard'] = "admin/admin/index"; // END AUTHENTICATION LIBRARY ROUTES /* End of file routes.php */ /* Location: ./system/application/config/routes.php */
php
MIT
5e83e14f80fe7ab71a682b27f0ea014c9c10690b
2026-01-05T04:39:19.688431Z
false