porifera
PHP AST instrumentation for collecting runtime values at supported expression sites. The name comes from the sponge phylum Porifera.
Install
pip install porifera
Requires Python >=3.10.
Usage
The example requires a php executable on PATH; it is the target, and its php -l is the compile check of the staged bytes.
import subprocess
from collections.abc import Mapping
from pathlib import Path
from tempfile import TemporaryDirectory
from php_parser_py import Parser, PHPVersion
import porifera
VERSION = "echo PHP_MAJOR_VERSION, ' ', PHP_MINOR_VERSION;"
def php_version() -> PHPVersion:
found = subprocess.run(
["php", "-r", VERSION], capture_output=True, text=True, check=True
)
major, minor = found.stdout.split()
return PHPVersion(int(major), int(minor))
def compile_check(target: PHPVersion, staged: Mapping[Path, bytes]) -> Mapping[Path, str]:
if php_version() != target:
raise RuntimeError(f"php on PATH is not PHP {target}")
refused = {}
for path, content in staged.items():
checked = subprocess.run(["php", "-l"], input=content, capture_output=True)
if checked.returncode:
refused[path] = (checked.stderr + checked.stdout).decode("utf-8", errors="replace")
return refused
with TemporaryDirectory() as directory:
source = Path(directory) / "example.php"
source.write_text("<?php\n$price = 40 + 2;\n", encoding="utf-8")
target = php_version()
ast = Parser(target_php=target).parse_file(str(source))
node = ast.first_node(lambda item: item.node_type == "Expr_BinaryOp_Plus")
assert node is not None
with porifera.session(
{node.id: "price"}, ast, target_php=target, compile_check=compile_check
) as active:
subprocess.run(["php", str(source)], check=True)
print(active.collect()["price"].values)
See session states and exit cleanup.
Probe strategies, outcome types and deployment callbacks are specified in the public API. Target admission selects Expression Wrap, Wrap-Assign, Statement Probe or a refusal.
Documentation
- Concepts — problem context, core terminology, data flow
- Design — class structure, session API, exception types
- Lifecycle and reference checks — transaction steps and reference contexts
- Wrap safety — expression context checks
- Statement probes — assignment capture and placement
- Implementation — [@php-parser-py] API, developer notes
For Agents
Start at the agent usage index.
License
GPL-2.0 — see LICENSE.
Metadata
Release files for porifera 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| porifera-0.2.1.tar.gz | 92.7 kB | Without provenance | Details for porifera-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| porifera-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for porifera-0.2.1-py3-none-any.whl |
Total release size: 211.3 kB
Release files / porifera-0.2.1.tar.gz
| Download URL | porifera-0.2.1.tar.gz |
|---|---|
| Size | 92.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f701062173758286c53c48ab8ba6df2465a5f35c9a626aeb41cee70906843b14
|
|
BLAKE2b-256 checksum How to use checksums |
91b65bb193869f34813ed1bb2f55692417f9b932bc8458dec6433ca22c224ddc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / porifera-0.2.1-py3-none-any.whl
| Download URL | porifera-0.2.1-py3-none-any.whl |
|---|---|
| Size | 118.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
64c224130422c64eb91607ec7acf52db5c7c0810d86d9937b7ca5bb2b2f3be77
|
|
BLAKE2b-256 checksum How to use checksums |
ad470f4d876f9e2b3ee495707ac666ee65067dfdb6554da14761b01d1ce59d93
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Security for porifera 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.