porifera
porifera — named after Porifera, the sponge phylum.
PHP AST instrumentation for collecting runtime values at supported expression sites. Targets PHP 5.5 and later.
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.
API
session(targets, project_ast, *, target_php, compile_check, record_tag_expression=None, ...)enters an instrumentation session and yields aSession.Session.collect()returns the exact values of ticketless requests by key;Session.collect_unassigned()returns every record of those requests with its status and Record Tag asUnassignedRecords. Both consume the same output.Session.register_attempt(),Session.collect(attempt)andSession.ack(batch)collect ticketed requests as aCaptureBatchofCaptureRecord.plan_targets(),recover(),recover_capture()andrecorded_session()plan targets and recover a root.require_target_provenance()checks that an AST was parsed under the session's target version;is_declaration_site()tells whether a node is a variable a declaration binds.
Signatures, result types and errors: session API and capture API.
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.
Citation
If you use this project in academic work, please cite our paper. BibTeX (placeholder until the paper is released):
@misc{porifera_placeholder,
title = {{TODO: paper title — not yet released}},
author = {{TODO: authors}},
year = {{TODO}},
note = {Unreleased associated work.}
}
Documentation
- Concepts — problem context, core terminology, data flow
- Domain model — entities, root states and invariants
- Design — class structure, session API, exception types
- Capture design — attempts, dispatch tickets, batches and recovery
- 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
- Glossary — the terms these documents use
For Agents
Agent-consumable documentation index at docs/llms.txt (llmstxt.org format).
License
GPL-2.0 — see LICENSE.
Metadata
Release files for porifera 0.4.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.4.1.tar.gz | 97.6 kB | Without provenance | Details for porifera-0.4.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| porifera-0.4.1-py3-none-any.whl | Python 3 | none | any | Details for porifera-0.4.1-py3-none-any.whl |
Total release size: 221.9 kB
Release files / porifera-0.4.1.tar.gz
| Download URL | porifera-0.4.1.tar.gz |
|---|---|
| Size | 97.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f6aaf30f3f09bfb7514b1aac8177e9919884d06f30392d492c5ee8abd1d87296
|
|
BLAKE2b-256 checksum How to use checksums |
32be213836a10fa6ca0e65c6f7e738a46d2f1d7795cebf599a7893ff5159a43f
|
| 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.4.1-py3-none-any.whl
| Download URL | porifera-0.4.1-py3-none-any.whl |
|---|---|
| Size | 124.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2b68d37b59512897116c84442240d1dc06304e1d4fa8d5b6e3e3de6852481a0c
|
|
BLAKE2b-256 checksum How to use checksums |
d3c91514b23fcae4b0a694e976490d98ab071a5ffc114e4ab362337ce88cff1b
|
| 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.4.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.