Skip to content

PHP Content Filter Modifier

The modifier allows you to selectively include or exclude PHP class elements such as methods, properties, constants, and annotations based on configurable criteria.

Please note that this modifier is specifically designed for PHP files and will not work with other file types.

Features

  • Filter methods, properties, and constants by name or pattern
  • Include or exclude elements based on visibility (public, protected, private)
  • Control whether method bodies are kept or replaced with placeholders
  • Optionally keep or remove documentation comments
  • Optionally keep or remove PHP 8 attributes
  • Filter elements using regular expression patterns

Example

yaml
documents:
  - description: API Documentation
    outputPath: docs/api.md
    sources:
      - type: file
        description: API Source Files
        sourcePaths:
          - src/Api
        filePattern: "*.php"
        modifiers:
          - name: php-content-filter
            options:
              method_visibility:
                - public
              exclude_methods:
                - __construct
              keep_method_bodies: false

Options

OptionTypeDefaultDescription
include_methodsarray[]Method names to include (empty means include all unless exclude_methods is set)
exclude_methodsarray[]Method names to exclude
include_propertiesarray[]Property names to include
exclude_propertiesarray[]Property names to exclude
include_constantsarray[]Constant names to include
exclude_constantsarray[]Constant names to exclude
method_visibilityarray["public", "protected", "private"]Method visibilities to include
property_visibilityarray["public", "protected", "private"]Property visibilities to include
constant_visibilityarray["public", "protected", "private"]Constant visibilities to include
keep_method_bodiesbooleanfalseWhether to keep method bodies or replace with placeholders
method_body_placeholderstring"/* ... */"Placeholder for method bodies when keep_method_bodies is false
keep_doc_commentsbooleantrueWhether to keep doc comments
keep_attributesbooleantrueWhether to keep PHP 8+ attributes
include_methods_patternstringnullRegular expression pattern for methods to include
exclude_methods_patternstringnullRegular expression pattern for methods to exclude
include_properties_patternstringnullRegular expression pattern for properties to include
exclude_properties_patternstringnullRegular expression pattern for properties to exclude