Skip to main content

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

For Agents

Start at the agent usage index.

License

GPL-2.0 — see LICENSE.

Metadata

Release files for porifera 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for porifera 0.3.0
File Size Uploaded Provenance Actions
porifera-0.3.0.tar.gz 95.4 kB Without provenance Details for porifera-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for porifera 0.3.0
File Interpreter ABI Platform Actions
porifera-0.3.0-py3-none-any.whl Python 3 none any Details for porifera-0.3.0-py3-none-any.whl

Total release size: 217.3 kB

Release files / porifera-0.3.0.tar.gz

Download URL porifera-0.3.0.tar.gz
Size 95.4 kB
Tags Source
SHA-256 checksum
How to use checksums
25e68ea96c566b12fcab5266371f35206ad9a9bd66979c257076668f4d6b0bd0
BLAKE2b-256 checksum
How to use checksums
5fcc39fee2bac124fcaa8ad79c0e92a2a327c447be2f2b8c27764471d1f25fee
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.3.0-py3-none-any.whl

Download URL porifera-0.3.0-py3-none-any.whl
Size 121.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c98f890e0351028a03619fcb05c06ff5da66faaf92c170c7f7333fb837bc65ec
BLAKE2b-256 checksum
How to use checksums
61c7c6c1acbc4975b10248687778bfa338542527a5234308e8b8d36a349be90d
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.3.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page