Commit Graph

31 Commits

Author SHA1 Message Date
David
c16c5d48cb
Add #[derive(ZvalConvert)] macro (#78) 2021-10-03 18:00:50 +13:00
David Cole
a64d8896a2 Release v0.5.1 2021-09-29 01:09:20 +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
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
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
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 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
ca50b98acf Fix class deallocation memory leak
Store handlers statically like they always should have been
2021-08-24 14:09:26 +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
b1787ebd0a v0.2.0 bump version 2021-08-23 16:49:04 +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
David
626c944218
Added #[php_extern] macro (#51)
* Fixed memory leak with `phpinfo()` table

* Added `#[php_extern]` macro
2021-08-19 12:36:33 +12:00
David
a2781b794a
Modify string parameters to be consistent (#50)
* Fix memory leaks with strings and zvals

Add PhpAllocator - not meant for usage, only for memory leak debugging.

* Replace `impl AsRef<str>` with `&str`

* Added `ZendString::as_str()`

* Tidy up

* Replace owned string parameters with `Into<String>`

* Remove backtrace feature, un-import allocator
2021-08-18 23:25:35 +12:00
David
84aaa07d3e
Add abstraction macros (#49)
* Remove uses of `unwrap`, improve library safety

* Started work on `#[php_function]` attribute

* Added `PhantomData` to `ZendHashTable`

Proper lifetimes for `HashTable` type

* `#[php_function]` now accepts `Vec<T>`

Refactored `ZendHashTable` iterators - there is now `Iter` and
`IntoIter` depending on whether it will consume the HashTable or not.

* Add support for nullable types

* Allow `optional` parameter on attribute

* Support primitive and `Option` return types

* Tidied and refactored attribute

* Added documentation for `#[php_function]`

Implemented `IntoZval` for `Option<T>` when `IntoZval` is also
implemented for `T`. `None` resolves to `null`.

* Added `#[php_method]` attribute

* Added `Callable` type, implemented `Drop` on `Zval`

While implementing `Drop`, the `Copy` derivation was removed, however,
this should not have been there in the first place (`Zval` is not valid
for `Copy` if it contains a string).

* Added some macro functions to example

* Add support for boolean arguments

* Added wrapper around binary data

Future support for binary arguments with `#[php_function]` macros.
Unpacking binary data is no longer unsafe. It was never really unsafe in
the beginning, as we were always reading valid memory, just the contents
of the data could not be trusted.

* Added `#[php_module]` attribute, added support for binary arguments

* Added defaults for functions

* Add defaults for methods

* Add startup function macro and prelude

* Refactored method adding

Now done through impl attribute

* Don't rename functions - generate another internal fn

Also hide all generated functions from docs

* Generate startup function when not already defined

* Add support for class and global constants

* Updated `skel` project

* Updated macro documentation, added executor globals

* Remove `Copy` bound for HashMap to Zval

* Updated documentation

* Add `FromZval` trait, updated docs

* Fixed clippy lints

* Fixed ZTS executor globals

* Fix clippy lint
2021-08-18 13:15:25 +12:00
David Cole
ad51a66193 v0.1.0: bumped version 2021-08-11 12:39:20 +12:00
David
2a0e1f8086
Remove uses of unwrap, improve library safety (#47)
* Remove uses of `unwrap`, improve library safety

* `set_array` doesn't return `Result`
2021-08-11 12:34:08 +12:00
David
c98bf495ea
v0.0.7: bumped version (#43) 2021-05-21 17:16:36 +12:00
David Cole
ee2c394102 v0.0.6: bumped version and changelog 2021-05-11 21:49:09 +12:00
David Cole
e5a092d5f7 v0.0.5: bumped version and changelog 2021-04-24 13:39:06 +12:00
David
439f2ae981
Relicense under MIT or Apache 2.0 (#27)
* Relicense under MIT or Apache 2.0

* Updated license in README to match Rust guidelines
2021-04-22 20:01:30 +12:00
David Cole
f1a63c3600 Release 0.0.4 2021-04-17 21:59:59 +12:00
David Cole
e38d987d15 Added gitignore to derive crate 2021-04-17 00:07:37 +12:00
David Cole
91632cd0f3 Published ext-php-rs-derive 2021-04-05 01:47:28 +12:00
David Cole
8763b2314c v0.0.3: bumped version 2021-04-05 01:44:20 +12:00
David
860ffb3587
Created derive macro for ZendObjectHandler (#19)
* Initialize handlers on first touch

In the process of turning the two macros into one derive proc macro

* Changed the object handler macros into derive
2021-04-05 01:43:08 +12:00