Skip to content

Commit

Permalink
Fix PyClass, Added Helper
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Sep 6, 2024
1 parent bca7b42 commit dbe4905
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
17 changes: 17 additions & 0 deletions lib/phpy/Helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace phpy;

use PyCore;

class Helper
{
public static function printTraceback($traceback): void
{
$frame = $traceback;
while ($frame) {
PyCore::print($frame->tb_frame);
$frame = $frame->tb_next;
}
}
}
22 changes: 21 additions & 1 deletion lib/phpy/PyClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@ class PyClass
protected string $_proxyClass;
private string $_proxyFile;

const IGNORE_METHODS = [
'__construct',
'__destruct',
'__call',
'__callStatic',
'__get',
'__set',
'__isset',
'__unset',
'__sleep',
'__wakeup',
'__toString',
'__invoke',
'__set_state',
'__clone',
'__debugInfo',
'self',
'super',
];

/**
* @throws \Exception
*/
Expand Down Expand Up @@ -71,7 +91,7 @@ private function makeProxy(): void
$methods = [];
foreach ($refMethods as $method) {
$modifiers = $method->getModifiers();
if (str_starts_with($method->name, '__')
if (in_array($method->name, self::IGNORE_METHODS)
or ($modifiers & ReflectionMethod::IS_STATIC)
or ($modifiers & ReflectionMethod::IS_PRIVATE)
or ($modifiers & ReflectionMethod::IS_ABSTRACT)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/phpy/proxy.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ class <?=$this->_proxyClass?>(<?=implode(', ', $parents)?>):

<?php foreach($methods as $m):?>
def <?=$m['name']?>(self, <?=$m['argv']?>):
self.__this.call('<?=$m['name']?>', <?=$m['argv']?>)
return self.__this.call('<?=$m['name']?>', <?=$m['argv']?>)

<?php endforeach; ?>

0 comments on commit dbe4905

Please sign in to comment.