Commit Graph

237 Commits

Author SHA1 Message Date
David Cole
d9e40ea4d2
Ensure CLI-Extension compatibility (#108)
* Change describe types to C ABI, check ext-php-rs version

Rust doesn't have a stable ABI so the describe function and types are
now C ABI compatible, however, the internal types `Cow`, `Vec`, `Option`
aren't.

Check `ext-php-rs` versions to check compatibility between the CLI and
the extension.

* CLI requires 0.7.1

* Bump versions

* Replace standard library types with ABI-stable replacements

* Change option type
2021-11-21 17:27:12 +13:00
David Cole
fa05703c08 Release v0.7.0 2021-11-20 14:33:41 +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
bedade8bb3
Fix builds on aarch64 Linux (#106) 2021-11-14 16:01:00 +13:00
David Cole
d74b5d54b7 Clean up clippy lints 2021-11-05 23:45:58 +13:00
David Cole
d0d05678b3 Replace box with in-struct object when building class 2021-11-05 23:41:30 +13:00
David Cole
88b84b9a17
Disable serialization and unserialization on classes (#105)
* Disable serialization and unserialization on classes

Classes that have associated Rust types cannot be serialized for
obvious reasons so these need to be disabled. Disabling these actions
changes in PHP 8.1 to use a flag, so that will need to be solved with
PHP 8.1 support. Closes #97

* update docs stubs
2021-10-19 02:10:02 +13:00
David Cole
b92202c89b Release v0.6.0 2021-10-10 23:21:39 +13:00
David Cole
7812b7ff1e Test docs.rs stub file in lint build 2021-10-10 22:57:38 +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 Cole
f8b57274fb Version 0.5.3 2021-10-07 04:25:10 +13:00
David Cole
50b70c28cc Fix doc bindings 2021-10-07 04:22:50 +13:00
David Cole
88e0d7b668 Version 0.5.2 2021-10-07 04:13:00 +13:00
David Cole
39790191e8
Fixed ArgParser lifetimes (#100)
* Fixed `ArgParser` lifetimes

Now stores a mutable reference to the underlying zval. Instead of
passing the execution data to the arg parser, a vector of args is now
passed to prevent a shared lifetime issue with the `$this` object.

* Implememt from traits for classes
2021-10-07 04:02:59 +13:00
David
3403cba7bf
Add ZBox<T> to replace owned variants (#94)
* Added `ZBox` and `ZBoxable`

* Implement `ZBoxable` for `ZendStr`

Build for all f eatures on CI

* Replace `OwnedZendObject` with `ZBox<ZendObject>`

* Replace `ClassObject` with `ZBox<ZendClassObject>`

Fixed deserialization bug

Panic when uninitialized - better than UB

* Replace `OwnedHashTable` with `ZBox<HashTable>`

* Remove `MaybeUninit` from `ZendClassObject`
2021-10-05 16:59:41 +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
Simon Gomizelj
0f2cabbd95
Add Display impl for ZendObject (#74)
* Add support to capture execptions from PHP

* Add extract function to Zval

* Add FromZendObject trait for casting objects to other types
2021-10-03 14:37:55 +13:00
David Cole
a64d8896a2 Release v0.5.1 2021-09-29 01:09:20 +13:00
David
a404df8fed
Fixed ZendString missing one character (#82) 2021-09-29 01:07:30 +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
aea8717456
Refactor Zend strings (#77)
* Call zval destructor when changing zval type and dropping

* Remove `ZendHashTable` wrapper

Replaced by returning references to the actual hashtable, and having a
new type `OwnedHashTable` when creating a new hashtable.

* Refactor `ZendString` into a borrowed and owned variant

`&ZendStr` is now equivalent to `&str`, while `ZendString` is equivalent
to `String`.

* Tidy up `ZendString`, add `Debug` implementation
2021-09-28 00:33:16 +13:00
David
7c484a0e18
Refactor ZendHashTable and Zval (#76)
* Call zval destructor when changing zval type and dropping

* Remove zval return from array insert functions #73

The functions actually returned references to the new zval value, so
there's not much point in returning.

* Remove `ZendHashTable` wrapper

Replaced by returning references to the actual hashtable, and having a
new type `OwnedHashTable` when creating a new hashtable.

* Remove pointless `drop` field from `OwnedHashTable`

* Added `Values` iterator for Zend hashtable

* Change iterators to double ended and exact size
2021-09-21 21:22:05 +12:00
Simon Gomizelj
ff231ec912
Naively change the case of method identifiers to comply with PSR-1 (#63)
* Change the case of method identifiers to comply with PSR-1

* Expose methods as camelCase and add attributes for controlling renaming

Add an attribute to methods to control the name they're exported under
and an attribute to php_impl to override automatic case conversion
conventions.

* Cargo fmt

* Add option for no method renaming

Default to camel case renaming

Co-authored-by: David Cole <david.cole1340@gmail.com>
2021-09-19 22:15:01 +12:00
David Cole
1483ef7219 Remove old file 2021-09-17 03:30:47 +12:00
David Cole
766582b04e Fix lifetimes for zval arrays 2021-09-16 13:11:55 +12:00
David
dec4d8c93b
Fix alignment of class objects (#66)
* Fix alignment of class objects

* Clippy
2021-09-09 16:48:20 +12:00
David
f506a41b3c
Pass class object type to PHP when taking object parameter (#64)
* Pass class object type to PHP when taking object parameter

* Fix test

* Update docs.rs stub bindings
2021-09-08 22:21:21 +12:00
David Cole
8b3ed08882 Change datatype of unit type to void
Null is invalid type apparently
2021-09-07 23:21:08 +12:00
David
8b0adf1de6
Add try_from into FromZval trait (#62)
Allows generic implementations of the trait
2021-09-07 13:56:11 +12:00
David Cole
72b04915cc Improve debug for ClassEntry 2021-09-05 20:31:32 +12:00
David Cole
5bf24588c9 v0.4.0: bump version 2021-09-05 18:46:38 +12:00
David Cole
356c1fdd97 Add support for docs.rs (hopefully) 2021-09-05 18:18:09 +12:00
David Cole
0056db3392 Fix docs build 2021-09-05 18:00:52 +12:00
David
b50a6c64bf
Allowlist types generated by bindgen (#60)
* Allowlist types generated by bindgen

Tidied up build script as well, layout tests are no longer generated
unless `EXT_PHP_RS_TEST` env variable is set. Much quicker build times
and smaller output size.

* Fix build

* Override Rust toolchain when running CI
2021-09-05 17:56:29 +12:00
David
52fae5c6d4
Use configuration tags instead of features for flags (#59)
e.g. PHP debug or ZTS mode are no longer features, but just simply
configuration flags.
2021-09-05 14:49:50 +12:00
David Cole
20e8c16ff0 Build docs on nightly 2021-09-05 14:24:56 +12:00
David Cole
31a1e3d5e1 Document features, fix documentation links 2021-09-05 14:18:03 +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
73526d62b5
Drop object contents rather than deallocating whole object (#57)
The object memory is automatically deallocated, however, anything that
has been allocated on the heap (strings, vectors etc.) must be
deallocated while we are freeing the object.
2021-09-05 00:53:29 +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 Cole
6abe209525 v0.3.0 bump version 2021-08-26 20:47:46 +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
7f1e952083 Remove usage of unstable stdlib features 2021-08-24 14:18:03 +12:00
David Cole
ca50b98acf Fix class deallocation memory leak
Store handlers statically like they always should have been
2021-08-24 14:09:26 +12:00