Browse Source

Update php to support both 5 and 7

master
Artyom Beilis 7 years ago
parent
commit
2ccdac8e04
16 changed files with 3801 additions and 6 deletions
  1. +0
    -0
      contrib/integration/session/php/php5/build_ext.sh
  2. +0
    -0
      contrib/integration/session/php/php5/cppcms.php
  3. +0
    -0
      contrib/integration/session/php/php5/cppcms_api.c
  4. +0
    -0
      contrib/integration/session/php/php5/cppcms_api.php
  5. +0
    -0
      contrib/integration/session/php/php5/php_cppcms_api.h
  6. +14
    -0
      contrib/integration/session/php/php7/build_ext.sh
  7. +170
    -0
      contrib/integration/session/php/php7/cppcms.php
  8. +3176
    -0
      contrib/integration/session/php/php7/cppcms_api.c
  9. +343
    -0
      contrib/integration/session/php/php7/cppcms_api.php
  10. +77
    -0
      contrib/integration/session/php/php7/php_cppcms_api.h
  11. +1
    -1
      contrib/integration/session/php/test/run.sh
  12. +2
    -0
      contrib/integration/session/php/test/run7.sh
  13. +4
    -2
      contrib/integration/session/php/test/unit_test.php
  14. +0
    -2
      contrib/integration/session/swig/cppcms.i
  15. +6
    -1
      contrib/integration/session/swig/gen-php.sh
  16. +8
    -0
      contrib/integration/session/swig/gen-php7.sh

contrib/integration/session/php/build_ext.sh → contrib/integration/session/php/php5/build_ext.sh View File


contrib/integration/session/php/cppcms.php → contrib/integration/session/php/php5/cppcms.php View File


contrib/integration/session/php/cppcms_api.c → contrib/integration/session/php/php5/cppcms_api.c View File


contrib/integration/session/php/cppcms_api.php → contrib/integration/session/php/php5/cppcms_api.php View File


contrib/integration/session/php/php_cppcms_api.h → contrib/integration/session/php/php5/php_cppcms_api.h View File


+ 14
- 0
contrib/integration/session/php/php7/build_ext.sh View File

@@ -0,0 +1,14 @@
#!/bin/bash

rm -f cppcms_api.so

if [ "$CPPCMS_PATH" != "" ]
then
CPPCMS_INC=-I$CPPCMS_PATH/include
CPPCMS_LIB=-L$CPPCMS_PATH/lib
CPPCMS_LINK_FLAGS=-Wl,-rpath=$CPPCMS_PATH/lib
fi

PHP_FLAGS=`php-config --includes`

gcc -fPIC -shared -O2 -g $CPPCMS_INC $PHP_FLAGS $CPPCMS_LIB cppcms_api.c -o cppcms_api.so $CPPCMS_LINK_FLAGS -lcppcms -lbooster

+ 170
- 0
contrib/integration/session/php/php7/cppcms.php View File

@@ -0,0 +1,170 @@
<?php
include 'cppcms_api.php';

class CppCMS_SessioBase {
protected $api = null;
protected function check()
{
$code = $this->api->error();
if($code == 0)
return;
$msg = $this->api->error_clear();
switch($code) {
case cppcms_api::ERROR_INVALID_ARGUMENT;
throw new InvalidArgumentException($msg);
case cppcms_api::ERROR_LOGIC;
throw new LogicException($msg);
default:
throw new RuntimeException($msg);
}
}
};

class CppCMS_SessionPool extends CppCMS_SessioBase {
private function __construct()
{
$this->api = new CppCMSAPIPool;
}
public static function from_config($path)
{
$pool=new CppCMS_SessionPool();
$pool->api->init($path);
$pool->check();
return $pool;
}
public static function from_json($json)
{
$pool=new CppCMS_SessionPool();
$pool->api->init_from_json($json);
$pool->check();
return $pool;
}
public function session()
{
return new CppCMS_Session($this);
}
}

class CppCMS_Cookie {
private $c=null;
public function __construct($c)
{
$this->c=$c;
}

function header() { return $this->c->header(); }
function header_content() { return $this->c->header_content(); }
function name() { return $this->c->name(); }
function value() { return $this->c->value(); }
function path() { return $this->c->path(); }
function domain() { return $this->c->domain(); }
function max_age_defined() { return $this->c->max_age_defined() != 0; }
function max_age() { return $this->c->max_age(); }
function expires_defined() { return $this->c->expires_defined() != 0; }
function expires() { return $this->c->expires(); }
function is_secure() { return $this->c->is_secure(); }
function __toString() { return $this->header(); }
}


class CppCMS_Session extends CppCMS_SessioBase implements ArrayAccess {

public function __construct($pool)
{
$this->api = new CppCMSAPISession;
$this->api->init($pool->api);
$this->check();
}
function clear() { $this->api->clear(); $this->check(); }

function is_set($key) { $r = $this->api->is_set($key)!=0; $this->check(); return $r; }
function erase($key) { $this->api->erase($key); $this->check(); }
function set($key,$value) {
$this->api->set_binary_as_hex($key,bin2hex($value));
$this->check();
}
function get($key) {
$r=$this->api->get_binary_as_hex($key);
$this->check();
if($r==null)
return null;
return hex2bin($r);
}

/// ArrayAccess API
function offsetExists($key) { return $this->is_set($key); }
function offsetUnset($key) { $this->erase($key); }
function offsetGet($key) { return $this->get($key); }
function offsetSet($key,$value) { $this->set($key,$value); }

function get_exposed($key) { $r=$this->api->get_exposed($key)!=0; $this->check(); return $r; }
function set_exposed($key,$is_exposed) { $this->api->set_exposed($key,$is_exposed?1:0 ); $this->check(); }

function keys() {
$r=array();
$k=$this->api->get_first_key();
while($k!=null) {
$r[]=$k;
$k=$this->api->get_next_key();
}
$this->check();
return $r;
}

function get_csrf_token() { $r=$this->api->get_csrf_token(); $this->check(); return $r; }

function reset_session() { $this->api->reset_session(); $this->check(); }
function set_default_age() { $this->api->set_default_age(); $this->check(); }
function set_age($t) { $this->api->set_age($t); $this->check(); }
function get_age() { $r=$this->api->get_age(); $this->check(); return $r; }
function set_default_expiration() { $this->api->set_default_expiration(); $this->check(); }
function set_expiration($t) { $this->api->set_expiration($t); $this->check(); }
function get_expiration() { $r = $this->api->get_expiration(); $this->check(); return $r; }
function set_on_server($is_on_server) { $this->api->set_on_server($is_on_server ? 1 : 0); $this->check(); }
function get_on_server() { $r = $this->api->get_on_server(); $this->check(); return $r!=0; }
function get_session_cookie_name() { $r=$this->api->get_session_cookie_name(); $this->check(); return $r; }

function load($session_cookie_value = null) {
if($session_cookie_value == null) {
$name = $this->get_session_cookie_name();
if(isset($_COOKIE[$name])) {
$session_cookie_value = $_COOKIE[$name];
}
foreach($_COOKIE as $key => $value)
$this->api->add_cookie_name($key);
}
if($session_cookie_value == null)
$session_cookie_value = "";
$this->api->set_session_cookie($session_cookie_value);
$this->api->load();
$this->check();
}

function cookies() {
$r=array();
$c=$this->api->cookie_first();
$this->check();
while($c!=null) {
$r[]=new CppCMS_Cookie($c);
$c=$this->api->cookie_next();
$this->check();
}
return $r;
}

function save($set_headers = true) {
$this->api->save();
$this->check();
if($set_headers) {
$c=$this->api->cookie_first();
$this->check();
while($c!=null) {
header($c->header(),false);
$c=$this->api->cookie_next();
$this->check();
}
}
}

}


+ 3176
- 0
contrib/integration/session/php/php7/cppcms_api.c
File diff suppressed because it is too large
View File


+ 343
- 0
contrib/integration/session/php/php7/cppcms_api.php View File

@@ -0,0 +1,343 @@
<?php

/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 3.0.12
*
* This file is not intended to be easily readable and contains a number of
* coding conventions designed to improve portability and efficiency. Do not make
* changes to this file unless you know what you are doing--modify the SWIG
* interface file instead.
* ----------------------------------------------------------------------------- */

// Try to load our extension if it's not already loaded.
if (!extension_loaded('cppcms_api')) {
if (strtolower(substr(PHP_OS, 0, 3)) === 'win') {
if (!dl('php_cppcms_api.dll')) return;
} else {
// PHP_SHLIB_SUFFIX gives 'dylib' on MacOS X but modules are 'so'.
if (PHP_SHLIB_SUFFIX === 'dylib') {
if (!dl('cppcms_api.so')) return;
} else {
if (!dl('cppcms_api.'.PHP_SHLIB_SUFFIX)) return;
}
}
}



abstract class cppcms_api {
const SESSION_FIXED = SESSION_FIXED;

const SESSION_RENEW = SESSION_RENEW;

const SESSION_BROWSER = SESSION_BROWSER;

const ERROR_OK = ERROR_OK;

const ERROR_GENERAL = ERROR_GENERAL;

const ERROR_RUNTIME = ERROR_RUNTIME;

const ERROR_INVALID_ARGUMENT = ERROR_INVALID_ARGUMENT;

const ERROR_LOGIC = ERROR_LOGIC;

const ERROR_ALLOC = ERROR_ALLOC;
}

/* PHP Proxy Classes */
class CppCMSAPIPool {
public $_cPtr=null;
protected $_pData=array();

function __set($var,$value) {
if ($var === 'thisown') return swig_cppcms_api_alter_newobject($this->_cPtr,$value);
$this->_pData[$var] = $value;
}

function __get($var) {
if ($var === 'thisown') return swig_cppcms_api_get_newobject($this->_cPtr);
return $this->_pData[$var];
}

function __isset($var) {
if ($var === 'thisown') return true;
return array_key_exists($var, $this->_pData);
}

function __construct($res=null) {
if (is_resource($res) && get_resource_type($res) === '_p_cppcms_capi_session_pool') {
$this->_cPtr=$res;
return;
}
$this->_cPtr=new_CppCMSAPIPool();
}

function error() {
return CppCMSAPIPool_error($this->_cPtr);
}

function error_message() {
return CppCMSAPIPool_error_message($this->_cPtr);
}

function error_clear() {
return CppCMSAPIPool_error_clear($this->_cPtr);
}

function init($conf) {
return CppCMSAPIPool_init($this->_cPtr,$conf);
}

function init_from_json($conf) {
return CppCMSAPIPool_init_from_json($this->_cPtr,$conf);
}
}

class CppCMSAPISession {
public $_cPtr=null;
protected $_pData=array();

function __set($var,$value) {
if ($var === 'thisown') return swig_cppcms_api_alter_newobject($this->_cPtr,$value);
$this->_pData[$var] = $value;
}

function __get($var) {
if ($var === 'thisown') return swig_cppcms_api_get_newobject($this->_cPtr);
return $this->_pData[$var];
}

function __isset($var) {
if ($var === 'thisown') return true;
return array_key_exists($var, $this->_pData);
}

function __construct($res=null) {
if (is_resource($res) && get_resource_type($res) === '_p_cppcms_capi_session') {
$this->_cPtr=$res;
return;
}
$this->_cPtr=new_CppCMSAPISession();
}

function error() {
return CppCMSAPISession_error($this->_cPtr);
}

function error_message() {
return CppCMSAPISession_error_message($this->_cPtr);
}

function error_clear() {
return CppCMSAPISession_error_clear($this->_cPtr);
}

function init($pool) {
return CppCMSAPISession_init($this->_cPtr,$pool);
}

function clear() {
return CppCMSAPISession_clear($this->_cPtr);
}

function is_set($key) {
return CppCMSAPISession_is_set($this->_cPtr,$key);
}

function erase($key) {
return CppCMSAPISession_erase($this->_cPtr,$key);
}

function get_exposed($key) {
return CppCMSAPISession_get_exposed($this->_cPtr,$key);
}

function set_exposed($key,$is_exposed) {
return CppCMSAPISession_set_exposed($this->_cPtr,$key,$is_exposed);
}

function get_first_key() {
return CppCMSAPISession_get_first_key($this->_cPtr);
}

function get_next_key() {
return CppCMSAPISession_get_next_key($this->_cPtr);
}

function get_csrf_token() {
return CppCMSAPISession_get_csrf_token($this->_cPtr);
}

function set($key,$value) {
return CppCMSAPISession_set($this->_cPtr,$key,$value);
}

function get($key) {
return CppCMSAPISession_get($this->_cPtr,$key);
}

function set_binary_as_hex($key,$value) {
return CppCMSAPISession_set_binary_as_hex($this->_cPtr,$key,$value);
}

function get_binary_as_hex($key) {
return CppCMSAPISession_get_binary_as_hex($this->_cPtr,$key);
}

function get_binary_len($key) {
return CppCMSAPISession_get_binary_len($this->_cPtr,$key);
}

function reset_session() {
return CppCMSAPISession_reset_session($this->_cPtr);
}

function set_default_age() {
return CppCMSAPISession_set_default_age($this->_cPtr);
}

function set_age($t) {
return CppCMSAPISession_set_age($this->_cPtr,$t);
}

function get_age() {
return CppCMSAPISession_get_age($this->_cPtr);
}

function set_default_expiration() {
return CppCMSAPISession_set_default_expiration($this->_cPtr);
}

function set_expiration($t) {
return CppCMSAPISession_set_expiration($this->_cPtr,$t);
}

function get_expiration() {
return CppCMSAPISession_get_expiration($this->_cPtr);
}

function set_on_server($is_on_server) {
return CppCMSAPISession_set_on_server($this->_cPtr,$is_on_server);
}

function get_on_server() {
return CppCMSAPISession_get_on_server($this->_cPtr);
}

function get_session_cookie_name() {
return CppCMSAPISession_get_session_cookie_name($this->_cPtr);
}

function add_cookie_name($key) {
return CppCMSAPISession_add_cookie_name($this->_cPtr,$key);
}

function set_session_cookie($value) {
return CppCMSAPISession_set_session_cookie($this->_cPtr,$value);
}

function load() {
return CppCMSAPISession_load($this->_cPtr);
}

function save() {
return CppCMSAPISession_save($this->_cPtr);
}

function cookie_first() {
$r=CppCMSAPISession_cookie_first($this->_cPtr);
if (is_resource($r)) {
$c=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3));
if (class_exists($c)) return new $c($r);
return new CppCMSAPICookie($r);
}
return $r;
}

function cookie_next() {
$r=CppCMSAPISession_cookie_next($this->_cPtr);
if (is_resource($r)) {
$c=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3));
if (class_exists($c)) return new $c($r);
return new CppCMSAPICookie($r);
}
return $r;
}
}

class CppCMSAPICookie {
public $_cPtr=null;
protected $_pData=array();

function __set($var,$value) {
if ($var === 'thisown') return swig_cppcms_api_alter_newobject($this->_cPtr,$value);
$this->_pData[$var] = $value;
}

function __get($var) {
if ($var === 'thisown') return swig_cppcms_api_get_newobject($this->_cPtr);
return $this->_pData[$var];
}

function __isset($var) {
if ($var === 'thisown') return true;
return array_key_exists($var, $this->_pData);
}

function __construct($res=null) {
if (is_resource($res) && get_resource_type($res) === '_p_cppcms_capi_cookie') {
$this->_cPtr=$res;
return;
}
$this->_cPtr=new_CppCMSAPICookie();
}

function header() {
return CppCMSAPICookie_header($this->_cPtr);
}

function header_content() {
return CppCMSAPICookie_header_content($this->_cPtr);
}

function name() {
return CppCMSAPICookie_name($this->_cPtr);
}

function value() {
return CppCMSAPICookie_value($this->_cPtr);
}

function path() {
return CppCMSAPICookie_path($this->_cPtr);
}

function domain() {
return CppCMSAPICookie_domain($this->_cPtr);
}

function max_age_defined() {
return CppCMSAPICookie_max_age_defined($this->_cPtr);
}

function max_age() {
return CppCMSAPICookie_max_age($this->_cPtr);
}

function expires_defined() {
return CppCMSAPICookie_expires_defined($this->_cPtr);
}

function expires() {
return CppCMSAPICookie_expires($this->_cPtr);
}

function is_secure() {
return CppCMSAPICookie_is_secure($this->_cPtr);
}
}


?>

+ 77
- 0
contrib/integration/session/php/php7/php_cppcms_api.h View File

@@ -0,0 +1,77 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 3.0.12
*
* This file is not intended to be easily readable and contains a number of
* coding conventions designed to improve portability and efficiency. Do not make
* changes to this file unless you know what you are doing--modify the SWIG
* interface file instead.
* ----------------------------------------------------------------------------- */

#ifndef PHP_CPPCMS_API_H
#define PHP_CPPCMS_API_H

extern zend_module_entry cppcms_api_module_entry;
#define phpext_cppcms_api_ptr &cppcms_api_module_entry

#ifdef PHP_WIN32
# define PHP_CPPCMS_API_API __declspec(dllexport)
#else
# define PHP_CPPCMS_API_API
#endif

ZEND_NAMED_FUNCTION(_wrap_new_CppCMSAPIPool);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPIPool_error);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPIPool_error_message);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPIPool_error_clear);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPIPool_init);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPIPool_init_from_json);
ZEND_NAMED_FUNCTION(_wrap_new_CppCMSAPISession);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_error);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_error_message);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_error_clear);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_init);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_clear);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_is_set);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_erase);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_get_exposed);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_set_exposed);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_get_first_key);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_get_next_key);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_get_csrf_token);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_set);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_get);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_set_binary_as_hex);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_get_binary_as_hex);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_get_binary_len);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_reset_session);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_set_default_age);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_set_age);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_get_age);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_set_default_expiration);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_set_expiration);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_get_expiration);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_set_on_server);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_get_on_server);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_get_session_cookie_name);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_add_cookie_name);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_set_session_cookie);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_load);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_save);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_cookie_first);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPISession_cookie_next);
ZEND_NAMED_FUNCTION(_wrap_new_CppCMSAPICookie);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPICookie_header);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPICookie_header_content);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPICookie_name);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPICookie_value);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPICookie_path);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPICookie_domain);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPICookie_max_age_defined);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPICookie_max_age);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPICookie_expires_defined);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPICookie_expires);
ZEND_NAMED_FUNCTION(_wrap_CppCMSAPICookie_is_secure);
PHP_MINIT_FUNCTION(cppcms_api);

#endif /* PHP_CPPCMS_API_H */

+ 1
- 1
contrib/integration/session/php/test/run.sh View File

@@ -1,2 +1,2 @@
#!/bin/bash
php5 -S 0.0.0.0:8000 -d enable_dl=On -d extension=../cppcms_api.so -t ./
php5 -S 0.0.0.0:8000 -d enable_dl=On -d extension=../php5/cppcms_api.so -t ./

+ 2
- 0
contrib/integration/session/php/test/run7.sh View File

@@ -0,0 +1,2 @@
#!/bin/bash
php7.0 -S 0.0.0.0:8000 -d enable_dl=On -d extension=../php7/cppcms_api.so -t ./

+ 4
- 2
contrib/integration/session/php/test/unit_test.php View File

@@ -1,6 +1,8 @@
<?php

include_once('../cppcms.php');
if(version_compare(PHP_VERSION, '7.0.0') >= 0)
include_once('../php7/cppcms.php');
else
include_once('../php5/cppcms.php');

$pool=CppCMS_SessionPool::from_config('../../reference/config.js');
$session=$pool->session();


+ 0
- 2
contrib/integration/session/swig/cppcms.i View File

@@ -50,8 +50,6 @@ typedef struct cppcms_capi_cookie{} cppcms_capi_cookie;
char const *get(char const *key);
int set_binary_as_hex(char const *key,char const *value);
char const *get_binary_as_hex(char const *key);
#int set_binary(char const *key,void const *value,int length);
#int get_binary(char const *key,void *buf,int buffer_size);
int get_binary_len(char const *key);
int reset_session();
int set_default_age();


+ 6
- 1
contrib/integration/session/swig/gen-php.sh View File

@@ -1,3 +1,8 @@
#!/bin/bash

swig -module cppcms_api -php -outdir ../php -o ../php/cppcms_api.c cppcms.i
if [ "$SWIG" == "" ]
then
SWIG=swig
fi

$SWIG -php -module cppcms_api -outdir ../php/php5 -o ../php/php5/cppcms_api.c cppcms.i

+ 8
- 0
contrib/integration/session/swig/gen-php7.sh View File

@@ -0,0 +1,8 @@
#!/bin/bash

if [ "$SWIG" == "" ]
then
SWIG=swig
fi

$SWIG -php7 -module cppcms_api -outdir ../php/php7 -o ../php/php7/cppcms_api.c cppcms.i

Loading…
Cancel
Save