-
Notifications
You must be signed in to change notification settings - Fork 6
运行phpsciter
zhanglei edited this page Nov 16, 2020
·
13 revisions
PHPSciter的对象,通过这个类,我们可以实现PHPSciter和sciter-sdk(https://github.com/sciter-sdk/go-sciter)之间进行交互
兼容php5和php7,尽量使用php7的版本
<?php
$oSciter = new PHPSciter();
$oSciter->setResourcePath('file://' . __DIR__ . '/res/');
$oSciter->setWindowFrame(100, 100, 100 + 500 + 1, 100 + 500 + 1);
$oSciter->setWindowTitle('hello');
$oSciter->loadFile('index.php');
$oSciter->setOption(PHPSciter::SCITER_SET_SCRIPT_RUNTIME_FEATURES,
PHPSciter::ALLOW_FILE_IO | PHPSciter::ALLOW_SOCKET_IO | PHPSciter::ALLOW_EVAL |
PHPSciter::ALLOW_SYSINFO);
$oSciter->run(PHPSciter::SW_TITLEBAR | PHPSciter::SW_RESIZEABLE | PHPSciter::SW_MAIN | PHPSciter::SW_ENABLE_DEBUG
|PHPSciter::SW_CONTROLS);
?>
创建一个PHPSciter对象
构造方法。
PHPSciter::__construct();
设置PHPSciter的资源路径
PHPSciter->setResourcePath('file://' . __DIR__ . '/res/')
-
参数
-
string $path
- 功能:PHPSciter资源的加载路径
-
设置PHPSciter的模态对话框的上、下、左、右的高度
PHPSciter->setWindowFrame(100, 100, 100 + 500 + 1, 100 + 500 + 1)
-
参数
-
int $left
- 功能:设置模态对话框左边的长度
-
int $right
- 功能:设置模态对话框右边的长度
-
int $top
- 功能:设置模态对话框上边的长度
-
int $bottom
- 功能:设置模态对话框底部的长度
-
设置PHPSciter的模态对话框的标题
PHPSciter->setWindowTitle("hello")
-
参数
-
int $title
- 功能:设置模态对话框的标题
-
设置PHPSciter的模态对话框的标题
PHPSciter->loadFile("index.php")
-
参数
-
int $file
- 功能:设置setResourcePath资源路径下要加载的文件名字,即入口文件位置
-
设置PHPSciter的选项
PHPSciter->setOption($option, $option_value)
-
参数
-
int $option
- 功能:设置PHPSciter的选项名称
-
int $option_value
- 功能:设置PHPSciter的选项值
-
$option 支持的参数
-
参数 | 名称 |
---|---|
PHPSCITER_SMOOTH_SCROLL | 滚动条,值:TRUE-启用,值:FALSE-禁用,默认启用 |
PHPSCITER_CONNECTION_TIMEOUT | 值:毫秒,http客户端的连接超时 |
PHPSCITER_HTTPS_ERROR | value: 0 - drop connection, 1 - use builtin dialog, 2 - accept connection silently |
PHPSCITER_FONT_SMOOTHING | value: 0 - system default, 1 - no smoothing, 2 - std smoothing, 3 - clear type |
PHPSCITER_TRANSPARENT_WINDOW | Windows Aero support, value: |
PHPSCITER_SET_GPU_BLACKLIST | hWnd = NULL,value = LPCBYTE, json - GPU black list, see: gpu-blacklist.json resource. |
PHPSCITER_SET_SCRIPT_RUNTIME_FEATURES | value - combination of SCRIPT_RUNTIME_FEATURES flags. |
PHPSCITER_SET_GFX_LAYER | hWnd = NULL, value - GFX_LAYER |
PHPSCITER_SET_DEBUG_MODE | hWnd, value - TRUE/FALSE |
PHPSCITER_SET_UX_THEMING | hWnd = NULL, value - BOOL, TRUE - the engine will use "unisex" theme that is common for all platforms. |
PHPSCITER_ALPHA_WINDOW | hWnd, value - TRUE/FALSE - window uses per pixel alpha (e.g. WS_EX_LAYERED/UpdateLayeredWindow() window) |
PHPSCITER_SET_INIT_SCRIPT | hWnd - N/A , value LPCSTR - UTF-8 encoded script source to be loaded into each view before any other script execution. |
PHPSCITER_SET_MAIN_WINDOW | hWnd, value - TRUE/FALSE - window is main, will destroy all other dependent windows on close |
PHPSCITER_SET_MAX_HTTP_DATA_LENGTH | hWnd - N/A , value - max request length in megabytes (1024*1024 bytes) |
- $option_value 支持的参数
参数 | 名称 |
---|---|
PHPSCITER_ALLOW_FILE_IO | 0x00000001 |
PHPSCITER_ALLOW_SOCKET_IO | 0x00000002 |
PHPSCITER_ALLOW_EVAL | 0x00000004 |
PHPSCITER_ALLOW_SYSINFO | 0x00000008 |
获取sciter的版本号
PHPSciter->getVersion()
运行Sciter的渲染引擎
PHPSciter->run($flags)
-
参数
-
int $flag
- 功能:设置sciter的运行标志位
-
-
$flag 支持的参数
参数 | 名称 |
---|---|
PHPSCITER_SW_CHILD | 仅子窗口有效,如果设置了这个标志位,则忽略其他标志位 |
PHPSCITER_SW_TITLEBAR | 顶层窗口有标题栏 |
PHPSCITER_SW_RESIZEABLE | 可调整框架的大小 |
PHPSCITER_SW_TOOL | 是一个工具窗口 |
PHPSCITER_SW_CONTROLS | 具有最小化/最大化按钮 |
PHPSCITER_SW_GLASSY | glassy window - supports "Acrylic" on Windows and "Vibrant" on MacOS. |
PHPSCITER_SW_ALPHA | 透明窗口(例如Windows上的WS_EX_LAYERED) |
PHPSCITER_SW_MAIN | 应用程序的主窗口,将在关闭时终止该应用程序 |
PHPSCITER_SW_POPUP | 该窗口被创建为最上面的窗口。 |
PHPSCITER_SW_ENABLE_DEBUG | 准备此窗口检查器 |
PHPSCITER_SW_OWNS_VM | 具有自己的虚拟机 |
将php静态函数绑定到sciter执行引擎当中,但是我们要注意我们使用defineFunction一定要在使用PHPSciter->run之后使用,不然会被PHPSciter的垃圾回收机制回收,PHPSciter扩展在加载完成页面之后,会回收当前sciter的页面中所使用的变量,用户级别的函数和用户级别的常量
PHPSciter::defineFunction($name, $callable);
-
参数
-
int $name
- 功能:在sciter界面中使用的函数名字
-
int $callable
- 功能:触发的php的静态函数
-
demo:
<?php
class classTest
{
static public function plus($a)
{
return $a + 30;
}
static public function sum($a, $b, $c)
{
return $a + $b + $c;
}
static public function float_($float)
{
var_dump(is_float($float), $float);
return 33.44;
}
static public function contact($str_1, $str_2)
{
return $str_1 . '-' . $str_2;
}
static public function contact_chinese($str_1, $str_2)
{
return $str_1 . '-' . $str_2;
}
static public function response_chinese()
{
return '我是汉字,你好世界';
}
static public function null_($null)
{
var_dump($null == null);
return null;
}
static public function bool_false($false)
{
var_dump($false == false);
return false;
}
static public function bool_true($true)
{
var_dump($true == true);
return true;
}
static public function arrmap($array, $str_1, $str_2, $num_1, $num_2)
{
// var_dump(is_array($array),$array, $str_1, $str_2, $num_1, $num_2);
$str = self::contact($str_1, $str_2);
$num = self::sum($num_1, $num_2, 300);
return array(
$str,
'str' => $str,
'num' => $num,
'this_is_array' => array(
'key_1' => 'this is string a',
'key_2' => 100,
'this_is_array_too' => array(
'key_3' => 'this is string b',
'key_4' => null,
),
),
300,
400 => 'this is string',
'key_5' => null,
);
}
}
PHPSciter::defineFunction('plus', 'classTest::plus');
PHPSciter::defineFunction('sum', 'classTest::sum');
PHPSciter::defineFunction('float', 'classTest::float_');
PHPSciter::defineFunction('contact', 'classTest::contact');
PHPSciter::defineFunction('contact_chinese', 'classTest::contact_chinese');
PHPSciter::defineFunction('response_chinese', 'classTest::response_chinese');
PHPSciter::defineFunction('nul', 'classTest::null_');
PHPSciter::defineFunction('bool_true', 'classTest::bool_true');
PHPSciter::defineFunction('bool_false', 'classTest::bool_false');
PHPSciter::defineFunction('arrmap', 'classTest::arrmap');
?>
- 关于sciter
- 关于phpsciter
- 安装sciter
- 开发phpsciter
- 运行phpsciter
-
sciter开发注意事项
- 常见问题
- tiscript和javascript的区别
- html5的兼容性
- css的兼容性
- 如何做调试
- 内存泄漏