Commit Graph

254 Commits

Author SHA1 Message Date
Joe Hoyle
99439bf7f5 Clippy 2023-07-13 15:24:29 +02:00
Joe Hoyle
a7780753dc Support registering ini definitions for modules
PHP extensions that want to provide ini settings can do so using `IniEntryDef::register()`; values can then be fetched via `GlobalExecutor::ini_values()`.
2023-07-13 14:42:08 +02:00
Pierre Tondereau
8b87e4038e
Bump cargo-php to 0.1.8 (#248)
* Bump cargo-php to 0.1.8

* Fix docker zts installation
2023-06-26 21:34:45 +02:00
Pierre Tondereau
654692d879
Prepare 0.10.1 (#243) 2023-05-16 23:41:08 +02:00
Pierre Tondereau
eaab5f0694
chore: deps upgrade (#242) 2023-05-16 23:22:20 +02:00
Pierre Tondereau
63a76846d2
chore: Update bindgen to 0.65.1 (#241) 2023-05-16 22:49:57 +02:00
Joe Hoyle
1f9946f105
Switch to use zend apis for array iteration (#240) 2023-05-16 22:33:45 +02:00
Pierre Tondereau
6b6489fddb
chore: fix clippy warnings. (#235) 2023-03-13 18:00:45 +01:00
Dirk Stolle
5d775a5e91
docs(badge): Fix URL of shields.io badges in README.md (#233)
See <https://github.com/badges/shields/issues/8671> for more
information about the breaking change in the URL scheme.

[ci skip]
2023-03-13 11:52:00 +01:00
Dirk Stolle
812e7057db
docs: Fix some typos (#234) 2023-03-13 11:51:29 +01:00
Ryan McCue
c5eaeb242b
Stop watching Cargo.lock for changes (#232)
When loaded via Cargo, there's no Cargo.lock directly in this crate, so
the lack of file existence causes unnecessary rebuilds every time.
2023-02-24 16:24:19 +01:00
Pierre Tondereau
e6afecbddd
chore(clippy): Fix clippy warnings. (#228) 2023-02-07 22:52:56 +01:00
Joe Hoyle
0b27dc349f
Fix Zval IS_PTR type detection (#223) 2023-02-07 22:25:15 +01:00
Joe Hoyle
1875e99e93
Pass args to startup function (#226) 2023-02-07 22:24:33 +01:00
Joe Hoyle
831b3c8597
Mate GlobalExecutor::get_mut() public (#227) 2023-02-07 22:21:53 +01:00
Christian Rades
87ac43d05e
Add is_identical for zvals (#217) 2023-01-19 12:40:24 +01:00
Pierre Tondereau
7ed31ebda9
chore: Prepare 0.10.0 (#215) 2022-12-22 22:55:07 +01:00
Pierre Tondereau
11e0998bc4
feat: Add support for PHP 8.2 (#212)
## Small Fixes due to PHP8.2 upgrade:
- Internal PHP `ZendHashmap` changed the way that we access to the bucket ([commit](90b7bde615 (diff-dca4782c62f10b418ea7193e4641e688ffd7a9c97869f2b1a3a96e28da5653aaL371)))
- Internal PHP `ArrayIterator` doesn't support parent `get_iterator` ([commit](15bbf6f337 (diff-bc002b59b592b4d44c13d898f9dc3ca60b1b1c8505a51a2a3557dfde51dfeb61L273)))
2022-12-20 17:11:35 +01:00
Pierre Tondereau
6965f4a198
Prepare v0.9.0 (#211) 2022-12-11 22:10:25 +01:00
ju1ius
4ca5c0d06e
honour PHP_CONFIG & rebuild automatically when env vars change (#210)
Closes https://github.com/davidcole1340/ext-php-rs/issues/208
Closes https://github.com/davidcole1340/ext-php-rs/issues/209

## Summary of the changes

### Build scripts
* the `unix_build.rs` script now honors the `PHP_CONFIG` environment variable, like `cargo php install`
* use `cargo:rerun-if-env-changed` for the `PHP`, `PHP_CONFIG` and `PATH` environment variables, to avoid needless recompilation of the whole dependency tree.

### Documentation
While trying to document the aforementioned changes, I realized that there was no chapter about installing and setting up a PHP environment to develop PHP extensions. So, I refactored the first chapters of the book into a `Getting Started` section, including instructions on how to quickly set up a PHP environment.
2022-12-11 20:08:50 +01:00
ju1ius
d52a878e7b
feat: allows ZendStr to contain null bytes (#202)
Closes https://github.com/davidcole1340/ext-php-rs/issues/200

## Rationale
In PHP zend_strings are binary strings with no encoding information. They can contain any byte at any position.
The current implementation use `CString` to transfer zend_strings between Rust and PHP, which prevents zend_strings containing null-bytes to roundtrip through the ffi layer. Moreover, `ZendStr::new()` accepts only a `&str`, which is incorrect since a zend_string is not required to be valid UTF8.

When reading the PHP source code, it is apparent that  most functions marked with `ZEND_API` that accept a `const *char` are convenience wrappers that convert the `const *char` to a zend_string and delegate to another function. For example [zend_throw_exception()](eb83e0206c/Zend/zend_exceptions.c (L823)) takes a `const *char message`, and just converts it to a zend_string before delegating to [zend_throw_exception_zstr()](eb83e0206c/Zend/zend_exceptions.c (L795)).

I kept this PR focused around `ZendStr` and it's usages in the library, but it should be seen as the first step of a more global effort to remove usages of `CString` everywhere possible.

Also, I didn't change the return type of the string related methods of `Zval` (e.g. I could have made `Zval::set_string()` 
 accept an `impl AsRef<[u8]>` instead of `&str` and return `()` instead of `Result<()>`). If I get feedback that it should be done in this PR, I'll do it.

## Summary of the changes:
### ZendStr
* [BC break]: `ZendStr::new()` and `ZendStr::new_interned()` now accept an `impl AsRef<[u8]>` instead of just `&str`, and are therefore infaillible (outside of the cases where we panic, e.g. when allocation fails). This is a BC break, but it's impact shouldn't be huge (users will most likely just have to remove a bunch of `?` or add a few `Ok()`).
* [BC break]: Conversely, `ZendStr::as_c_str()` now returns a `Result<&CStr>` since it can fail on strings containing null bytes.
* [BC break]: `ZensStr::as_str()` now returns a `Result<&str>` instead of an `Option<&str>` since we have to return an error in case of invalid UTF8.
* adds method `ZendStr::as_bytes()` to return the underlying byte slice.
* adds convenience methods `ZendStr::as_ptr()` and `ZendStr::as_mut_ptr()` to return raw pointers to the zend_string.

 ### ZendStr conversion traits
* adds `impl AsRef<[u8]> for ZendStr`
* [BC break]: replaces `impl TryFrom<String> for ZBox<ZendStr>` by `impl From<String> for ZBox<ZendStr>`.
* [BC break]: replaces `impl TryFrom<&str> for ZBox<ZendStr>` by `impl From<&str> for ZBox<ZendStr>`.
* [BC break]: replaces `impl From<&ZendStr> for &CStr` by `impl TryFrom<&ZendStr> for &CStr`.

### Error
* adds new enum member `Error::InvalidUtf8` used when converting a `ZendStr` to `String` or `&str`
2022-12-09 10:54:17 +01:00
Pierre Tondereau
9e08e253dc
Update Cargo.toml (#207) 2022-11-28 21:08:00 +01:00
Pierre Tondereau
7423da060d
Revert "chore: use php-discovery to find matching PHP build" (#206) 2022-11-28 14:57:34 +01:00
Saif Eddin Gmati
31712066c8
chore: use php-discovery to find matching PHP build (#201) 2022-11-26 13:09:59 -08:00
ju1ius
a331213670
Add instance_of() and get_class_entry() methods on ZendObject (#197)
* adds `ZendObject::get_class_entry()` to retrieve the class entry of an object without casting pointers
* adds `ZendObject::instance_of()` to allow more idiomatic instanceof checks.
* adds a mention that `ZendObject::is_instance::<T>()` does not check the parent classes or interfaces. This bit me when I tried to check if `my_object.is_instance::<MyInterface>()` and it didn't work.
2022-11-24 11:17:12 +01:00
ju1ius
580ad9f462
Describes restrictions on generic parameters for php_class (#194) 2022-11-24 11:11:23 +01:00
ju1ius
3d742262c8
Add get_id() and hash() methods on ZendObject (#196) 2022-11-24 11:07:37 +01:00
ju1ius
9a105abb63
fixes CI workflow configuration (#195)
* upgrades LLVM to v14
* migrates from the unmaintained `action-rs/*` actions to [dtolnay/rust-toolchain](https://github.com/dtolnay/rust-toolchain), using [Swatinem/rust-cache](https://github.com/Swatinem/rust-cache/) as a cache layer.
* adds a cache layer for LLVM build
* adds a weekly cron schedule for all workflows
* fixes an issue in the docblocks
2022-11-24 09:05:36 +01:00
David Cole
8d2ad7d418
fix binary slice lifetimes (#181) 2022-11-19 08:58:18 +01:00
ju1ius
4ea01f8d98
fixes inifinte loop in ClassEntry::instance_of (#188) 2022-11-16 07:25:42 +01:00
David Cole
3b1e2e3848
check docs warnings in CI (#180)
* check docs warnings in CI

* works

* format
2022-11-13 21:13:25 +13:00
David Cole
a160f2a2a0 Bump version to v0.8.2 2022-11-11 12:11:33 +13:00
David Cole
eafd3b4471
fix type links in docs.rs (#179)
[ci skip]
2022-11-11 12:08:23 +13:00
Pierre Tondereau
b72d0555d6
chore(cli): Bump Clap for CLI tool (#177) 2022-11-10 10:59:49 +01:00
David Cole
4133a0fe78
add ability to define abstract methods (#171)
* add ability to define abstract methods

`new_abstract` can be used for interface and abstract class methods.

* rustfmt
2022-11-10 13:51:20 +13:00
David Cole
5f33598fcf
add before flag to #[php_startup] (#170)
* add `before` flag to `#[php_startup]`

this calls the user-provided startup function _before_ the classes and
constants registered by the macro system are registered with PHP. by
default the behaviour is to run this function after, which means you
cannot define an interface and use it on a struct.

* cargo fmt
2022-11-10 13:51:05 +13:00
Niklas Mollenhauer
997fded715
Add example that shows how to implement an interface (#167)
* Add example that shows how to implement an interface

* Add missing uses

* Fix some compilation issues
2022-10-23 13:09:56 +13:00
David Cole
76358ede3c rustfmt... 2022-10-23 12:06:22 +13:00
David Cole
1f0582b10d
fix describe when using #[implements] (#169)
[ci skip]
2022-10-23 12:02:00 +13:00
Denzyl Dick
ad048d0e05
Update lib.rs (#168)
Correct field name.

[ci skip]
2022-10-22 21:33:48 +13:00
David Cole
296c3add84 add note to update docs.rs bindings
[ci skip]
2022-10-16 13:13:17 +13:00
Niklas Mollenhauer
24d703d955
Add some standard zend interfaces (#164)
* Add some standard zend interfaces

The zend API also has some standard interfaces it exposes:
c8c09b4aae/Zend/zend_interfaces.h (L27-L33)
```
extern ZEND_API zend_class_entry *zend_ce_traversable;
extern ZEND_API zend_class_entry *zend_ce_aggregate;
extern ZEND_API zend_class_entry *zend_ce_iterator;
extern ZEND_API zend_class_entry *zend_ce_arrayaccess;
extern ZEND_API zend_class_entry *zend_ce_serializable;
extern ZEND_API zend_class_entry *zend_ce_countable;
extern ZEND_API zend_class_entry *zend_ce_stringable;
```

This surfaced in #163 and should make it possible to implement these interfaces.

* Add some links to the php documentation

* update docs.rs bindings

Co-authored-by: David Cole <david.cole1340@gmail.com>
2022-10-16 13:13:09 +13:00
David Cole
6a598ded3d
fix building docs on docs.rs (#165)
* fix building docs on docs.rs

accidentally removed the docs.rs stub bindings feature in
664981f4fb. docs.rs only has php 7.4 and
therefore cannot build ext-php-rs, so stub bindings are generated prior.

* update docs.rs stub bindings
2022-10-16 12:49:02 +13:00
Dirk Stolle
6766786db5
Update changelog for latest versions (#161)
[ci skip]
2022-10-13 10:37:17 +13:00
David Cole
669e024feb Bump version to v0.8.1 2022-10-12 11:18:22 +13:00
Robert O'Rourke
8a81c4b7f8
Allow passing --yes parameter to bypass prompts (#135)
* Allow passing `--yes` parameter to bypass prompts

Makes this tool usable in automated builds such as Docker containers.

Addresses https://github.com/davidcole1340/ext-php-rs/issues/133

* Update readme and guides

* rustfmt

Co-authored-by: David Cole <david.cole1340@gmail.com>
2022-10-01 12:14:15 +13:00
Robert O'Rourke
7dac4010a0
Fix INI file truncation and duplication (#136)
Addresses https://github.com/davidcole1340/ext-php-rs/issues/134

Also prevents adding the extension include line twice.
2022-10-01 11:24:36 +13:00
Bradley Schofield
1da812cf78
Add php-scrypt as a example project (#146) 2022-10-01 11:24:19 +13:00
Joe Hoyle
d4ef116b31
Support marking methods as abstract (#154)
For classes that are registered with `#[php_impl]` this allows functions to be marked as abstract.
2022-10-01 11:24:04 +13:00
Joe Hoyle
5d1fda4666
Support marking classes as interfaces (#155)
* Support marking classes as interfaces

This allows passing flags as part of `#[php_class(flags=Interface]` etc, which allows one to mark a class as being an interface.

When a class is an interface, it also shouldn't get a constructor created for it.

* rustfmt
2022-10-01 11:23:48 +13:00