Commit Graph

152 Commits

Author SHA1 Message Date
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
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 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 Cole
d2b0418020 Rust highlighting for README example 2021-08-22 02:11:06 +12:00
David Cole
dfee61f969 Run macro doctests, use readme in docs 2021-08-22 02:03:45 +12:00
David Cole
46de219ea9 Run cargo and mdbook tests on build 2021-08-22 01:33:22 +12:00
David Cole
a2cc921ab0 Use binary mdbook rather than compiling 2021-08-22 01:24:51 +12:00
David Cole
c9feb86901 Added links to guide 2021-08-22 01:18:51 +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 Cole
81dacc8cb0 Add From<Vec<T>> for binary types, tidy up 2021-08-20 16:19:07 +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
496e3501e1 Bumped ext-php-rs-derive version 2021-08-11 12:41:31 +12:00
David Cole
8259a49520 v0.1.0 not v1.0.0 2021-08-11 12:39:56 +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 Cole
0031df1604 ClassEntry::build now returns a reference
Useful for when you want to throw a custom exception. Store the
reference to the class (which should extend one of the base exceptions)
in a static mutable variable, and then use `throw`.
2021-07-31 20:44:46 +12:00
David Cole
e946066598 Change extends to take a reference rather than pointer 2021-07-28 21:31:31 +12:00
David
317201bbb9
Update Discord image location 2021-06-10 08:44:42 +12:00
David Cole
5e0466f343 Added iter function on ZendHashTable
We cannot implement `IntoIterator` for the `ZendHashTable` object as we
do not manage the memory, therefore we don't actually 'consume' the
object as the trait intends. Therefore, `IntoIterator` is implemented on
`&'a ZendHashTable`. This `ZendHashTable::iter` function simply forwards
the call.
2021-06-09 12:40:15 +12:00
David Cole
196ddb3e20 Zval::reference should return a reference 2021-06-02 14:09:08 +12:00
David
c98bf495ea
v0.0.7: bumped version (#43) 2021-05-21 17:16:36 +12:00
David
b23b678a3d
Better interactions with objects (#41)
* Object functions now return references to objects

Added ability to get object class name as well as hashtable of
properties

* Return mutable reference to objects

* Optimized `unwrap_or_else` calls
2021-05-21 17:11:15 +12:00
David Cole
4946613b5d Fixed docs link for ZendString 2021-05-21 15:14:17 +12:00
David Cole
f4d0bd7ea9 Updated README 2021-05-21 15:12:35 +12:00
David
de326e3171
Added ability to get and set properties (#39)
* Fixed adding properties to classes

* Removed unused function from wrapper header

* Moved property functions into `ZendObject`

* Introduced `ZendString` wrapper for raw pointer

* Set refcount of Zval to 0 when setting string properties

* Added ability to check if a property exists

Made some lifetimes explicit, check if property exists before attempting
to get.

* Removed unused file

* Removed unused lifetimes

Clippy was complaining, they were added to ensure that a `'static`
lifetime wasn't returned.
2021-05-21 15:08:10 +12:00
David
4d364d9765
Removed unused #[macro_use] attributes (#38) 2021-05-19 20:54:08 +12:00
David
0db6888c46
Added support for PHP ZTS (#37)
* Added support for PHP ZTS

* Added GitHub action for ZTS

Runs seperate from the other tests, as the setup-php action does not
support ZTS, therefore we run the tests in a Docker container.

* Source Rust env file before building

* No `source` command on docker

* Another attempt at fixing Rust in Docker
2021-05-19 20:45:39 +12:00
David Cole
5ac8aeecc4 Moved contribution section of README 2021-05-16 15:27:32 +12:00
David Cole
ee2c394102 v0.0.6: bumped version and changelog 2021-05-11 21:49:09 +12:00
Will Browning
e0743b1589
Remove default-features=false from bindgen (#36) 2021-05-07 10:35:46 +12:00
David
a75fcb50d2
Added ability to unpack and pack from Rust (#32)
* Added ability to `unpack` and `pack` from Rust

* Updated `Pack::pack_into` documentation

* Replaced constant with new flags, fixed example

* Accept slices/arrays when using `Zval::set_binary`
2021-05-05 22:43:06 +12:00
David
fcdd9332f5
Build and deploy docs to Github pages (#35)
* Added Github action for building and publishing docs

* Create index redirect page for docs

* Only deploy on master, fixed redirect
2021-05-04 11:42:52 +12:00