Commit Graph

35 Commits

Author SHA1 Message Date
4dd7b8ded5
Merge pull request #230 from davidcole1340/function-arg-pass-by-ref
Support function args being passed by reference
2023-10-10 16:13:31 +02:00
4152ffca06 Remove infallible variants 2023-10-10 16:07:39 +02:00
eff7b0195f
Merge pull request #225 from davidcole1340/ini-definitions
Support registering ini definitions for modules
2023-10-10 15:32:00 +02:00
714b1555f8
Fixes 2023-08-27 17:24:25 +02:00
4b821715b1
Update docs 2023-08-27 17:17:42 +02:00
Joe Hoyle
0f4f6f7315 Add docs / guide 2023-07-13 17:16:30 +02:00
Joe Hoyle
68059bdda1 Fix mutable refs 2023-07-13 15:38:49 +02:00
Dirk Stolle
812e7057db
docs: Fix some typos (#234) 2023-03-13 11:51:29 +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
580ad9f462
Describes restrictions on generic parameters for php_class (#194) 2022-11-24 11:11:23 +01: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
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
Dirk Stolle
4bb0559ab8 Fix a few typos 2022-09-10 16:40:38 +02:00
Denzyl Dick
1e4044b423 Fixed some typos 2022-08-26 21:43:01 +02:00
Tobias Bengtsson
231b3005c4 Support for BinarySlice to avoid allocation 2022-07-10 11:24:27 +02:00
David Cole
664981f4fb
Windows support (#128)
* Preliminary Windows support

* Start work on cross-platform build script

* Fix compilation on macOS

* Updated README, tidied up build script

* Check linker version before starting compilation

It doesn't seem like it's possible to change the linker from within the
build script, however, we can retrieve the linker in use and give the
user a suggestion if the linker will not work.

* Switch to using Github repository for bindgen

* Split Windows and Unix implementations into two files

* Fix building on Windows

* Remove `reqwest` and `zip` as dependencies on Unix

* Fix guide tests on Windows

* Started work on Windows CI

* runs -> run

* Use preinstalled LLVM on Windows

* Debugging for Windows CI

* Switch to upstream `rust-bindgen` master branch

* Switch to `rust-lld` for Windows linking

* Don't compile `cargo-php` on Windows

* Switch to using skeptic for tests

* cargo-php: Disable stub generation, fix ext install/remove

The plan is to replace the stub generation by generating them with PHP
code. This is cross-platform and means we don't need to worry about ABI.
We also don't need to embed information into the library.

* cargo-php: Fix on unix OS

* Fix clippy lint

* Updated README

* Re-add CI for Unix + PHP 8.0

* Fix building on thread-safe PHP

* Tidy up build scripts

* Use dynamic lookup on Linux, test with TS Windows

* Define `ZTS` when compiling PHP ZTS

* Combine Windows and Unix CI, fix linking for Win32TS

* Fix exclusions in build CI

* rust-toolchain -> rust

* Set LLVM version

* Only build docs.rs on Ubuntu PHP 8.1

* Fix build on Linux thread-safe

* Update guide example
2022-03-18 16:36:51 +13:00
David Cole
6df362b714
Added CLI crate for stubs, installation and removal (#107)
* started work on stub generator

* Worked on stub CLI tool

* Unused import

* Account for namespaces in function and class names

* Add support for docblocks on structs

* Push Rust comments to stubs

* Add indentation to stub generation

* Add CLI application to install and generate stubs

This time CLI application is defined on user side, called with `cargo
run -- ..args..`

* Export anyhow result

* Add constants to stub file

* Removed stub symbols

No longer required as we are now building while also linking to PHP.
Keeping the stubs causes the stubs to override the real symbols in the
extension.

* Fix stubs for real this time

Removed stub symbols as they were being included in the extension
dylib, fix by loading the PHP executable as a dylib, loading the
required symbols globally.

* Maybe actually fix stubs this time

* Forgot to remove PHP binary loading

* let's give this another go... cargo subcommand

Now called via `cargo php <install,stubs>`.

* Added `remove` command

* Tidied up cargo-php, commented, set up CI

* Fix return types with non-ident types

* define namespace ordering

* Fix tests, replace `Self` when in outer context

* Moved allowed bindings into separate file

* Update guide with CLI instructions
2021-11-20 14:19:02 +13:00
David Cole
b47f8ba160
Allow ZendClassObject as self parameter (#103)
* Allow `ZendClassObject` as `self` parameter

* Fixed tests

* Updated guide

* Updated changelog
2021-10-10 22:46:26 +13:00
David Cole
466c1658e3
Refactor module paths (#101)
* Refactor module layout

* Fixed documentation tests

* Removed skel, moved macro crate

* Ignore folders for crate publish

* Fix builder for zts

* Add `rustfmt.toml`, wrap all comments #96

* Fixed up documentation links, tidied up

* Add `Zend` prefix to callable and hashtable

* Updated guide types

* Updated changelog
2021-10-10 17:51:55 +13:00
David
125ec3bc94
Add ability to add proper object constructor (#83) 2021-10-03 19:53:54 +13:00
David
c16c5d48cb
Add #[derive(ZvalConvert)] macro (#78) 2021-10-03 18:00:50 +13:00
David
aed061d7be
Added section on exceptions to guide (#81) 2021-09-28 02:55:54 +13:00
David
daef57ba91
Remove lifetime from PhpException (#80)
* Remove lifetime from `PhpException`

All class entries are effectively static (module start to module end) so
it's just a hassle carrying the lifetime everywhere.

* Removed forgotten lifetimes

* Implement `IntoZval` for `Result<T, E>`

Fixes function return error with `PhpResult` as the return type

* Updated changelog
2021-09-28 02:23:13 +13:00
David
1e41b50100
Prepared for v0.5.0 release (#79)
- Bumped versions
- Updated changelog
- Updated docs.rs bindings
- Updated documentation about rename methods
2021-09-28 01:31:55 +13:00
David
afdac8e4b3
Add support for field and method properties (#69)
* Rough implementation of struct properties

* Store properties hashtable once

* Tidy up handler functions with exceptions

* Add stub `get_properties` function for codegen structs

* Remove nightly features

* Revert storing properties

Technically, the zend object _could_ move in memory, leaving dangling
references in the properties hashtable. We will just build the hashtable
when required.

* Added `#[prop]` attribute

* Add pointer type to zval, tidy up zend string

* Add support for method properties

* Add `#[getter]` and `#[setter]` attributes

* Update documentation with method properties

* Tidy up macros code

* Remove string gc checks (done on PHP side)

* Move `RegisteredClass` implementation to module, update docs

* Fix read property `rv` segfault

* Fixed doctests
2021-09-28 00:54:23 +13:00
David Cole
5bf24588c9 v0.4.0: bump version 2021-09-05 18:46:38 +12:00
David
4a4370c817
Add ability to send Rust closures to PHP (#58)
* Start work on returning new objects

Change `IntoZval` to consume `self`

* Add conversion from vector reference to PHP hashtable through clones

* `set_binary` now only takes `Vec`

Used to take `AsRef<[T]>` to allow users to pass arrays, however, this
causes the data to be cloned even if the user passes a `Vec`.

* Rename `as_zval` to `into_zval` to match Rust conventions

* Started work on closures

* Finish implementation of closures

* Document closures, add to prelude, feature gate

* Fixed closure example
2021-09-05 13:45:59 +12:00
David
faad01b59d
Add ability to define properties when using macros (#56)
* Panic instead of return result when adding property

This will almost always be unwrapped

* Remove unused `set_refcount` function

Wasn't valid either way

* Add ability to get and set properties on class objects

* Updated documentation adding properties
2021-08-28 15:54:26 +12:00
David
3ea6f0c0bc
Allow returning of object references (#55)
* Allow returning of object references

`TYPE` is now also on `IntoZval` which means `FromZval` does not need to
be implemented on return types

* Clippy lints
2021-08-27 14:04:22 +12:00
David
1193cc0537
Replace struct derive macro with attribute macro (#54)
* Replace `ZendObjectOverride` derive macro with `#[php_class]`

* Updated guide with `#[php_class]` macro

* Panic rather than return error when implementing interface

It's gonna panic either way so might as well make it easier for the
builder

* Remove `libc` dependency
2021-08-26 01:04:33 +12:00
David Cole
07e8d32538 Automatically check for optional parameters
No longer need to annotate the optional parameter
2021-08-23 20:59:44 +12:00
David Cole
d025311ca6 Fix failing tests 2021-08-23 16:44:30 +12:00
David
4ec03d1abe
Add hello world example (#53) 2021-08-23 16:36:13 +12:00
David
bd84f28054
Added ext-php-rs guide (#52)
* Started work on guide, added types

* Rewrite argument parser to allow referencs

Primarly so that `&str` is a valid parameter type.

* Remove generic `Into<String>` conversion to exception

* Worked on guide, added macros

* Build guide when building docs

* Allow manual trigger of docs build

* `cargo fmt`
2021-08-22 01:00:14 +12:00