Skip to content
BETAGuardrails are in beta. The library, the configuration format and the CLI command can still change.

Guardrails / Collectors

PHP project

The Composer project in the project directory: the package it declares, the PHP version and extensions it asks for, the packages it requires and which of them are pinned, and whether the lock file is committed.

Facts keyphp
Versionv1
Scriptphp.py
Timeout30 seconds

Inputs

InputDescriptionDefaultEnvironment
projectDirDirectory holding the project, relative to the directory the CLI runs in..GUARDRAIL_INPUT_PROJECTDIR

A guardrail that declares an input of the same name passes it through, so the guardrail's configuration in buildnote.json is what decides these values.

A guardrail asks for these facts by name, and reads them back the same way:

json
{
  "collect": ["php"]
}
python
php = guardrail.facts("php")

Facts

The document php collects. A path carrying [] is an entry of the list before it, and one carrying [path] is a key of the object before it.

FactMeaning
directoryThe projectDir input, as the guardrail configured it.
existsWhether that directory is there. Nothing else is collected when it is not.
manifestPath of the primary manifest, relative to projectDir, always composer.json.
sourcesEvery manifest that was read and understood. A manifest the reader could not handle is in unparsed instead.
declaredThe PHP version the project asks for, or null when it asks for none. config.platform.php wins over require.php, because it is the version Composer resolves against.
declared.versionConstraint exactly as written, such as ^8.2 or 8.2.18.
declared.sourceFile declaring it, relative to projectDir.
declared.pinnedWhether the constraint names one exact version rather than a range. A ^, a ~, a >=, a * or a | is not pinned.
typeThe type the manifest declares, such as library or project, or null when it declares none and library is implied.
projectsThe one package the manifest declares. Composer has no workspaces, so this is always a single entry.
projects[].pathDirectory of the package, relative to projectDir, always ..
projects[].manifestThat package's composer.json, relative to projectDir.
projects[].nameName the manifest declares, such as acme/widget, or null when it declares none.
dependenciesWhat the manifest requires, split by whether the project asks for it itself.
dependencies.directEvery package require and require-dev name, the php constraint and the ext- and lib- platform requirements left out because they are not packages.
dependencies.direct[].namePackage name, such as symfony/console.
dependencies.direct[].versionConstraint exactly as written, such as ^7.0.
dependencies.direct[].scopesWhich of require and require-dev declare it.
dependencies.direct[].sourceManifest declaring it, relative to projectDir.
dependencies.direct[].pinnedWhether the constraint names one exact version. A ^, a ~, a range, a *, a dev- branch or a @ stability flag is not pinned.
dependencies.transitiveAlways empty. What composer.lock resolves is not read: lockfiles says whether one is committed.
platformEvery ext- and lib- requirement the manifest names, which is what the runtime has to carry rather than what Composer installs.
platform[].nameRequirement name, such as ext-json.
platform[].versionConstraint exactly as written, such as *.
scriptsNames of the scripts the manifest declares. Names only, because a script body can carry a token.
lockfilescomposer.lock when it is committed, relative to projectDir. An application without one resolves differently on every install.
unparsedEvery manifest the reader could not handle, so a guardrail can tell a project that declares nothing from one nobody could read.
unparsed[].pathPath of that manifest, relative to projectDir.
unparsed[].reasonWhat stopped the reader.

A collector that cannot finish prints what it had along with an incomplete key saying why, so the facts below the point it stopped are absent. A check that cares reads incomplete before the rest.

Example facts

The example facts collected by php collector:

json
{
  "directory": ".",
  "exists": true,
  "manifest": "composer.json",
  "sources": [
    "composer.json"
  ],
  "declared": {
    "version": "^8.2",
    "source": "composer.json",
    "pinned": false
  },
  "type": "project",
  "projects": [
    {
      "path": ".",
      "manifest": "composer.json",
      "name": "acme/widget"
    }
  ],
  "dependencies": {
    "direct": [
      {
        "name": "symfony/console",
        "version": "^7.0",
        "scopes": [
          "require"
        ],
        "source": "composer.json",
        "pinned": false
      },
      {
        "name": "monolog/monolog",
        "version": "3.6.0",
        "scopes": [
          "require"
        ],
        "source": "composer.json",
        "pinned": true
      },
      {
        "name": "phpunit/phpunit",
        "version": "^11.1",
        "scopes": [
          "require-dev"
        ],
        "source": "composer.json",
        "pinned": false
      }
    ],
    "transitive": []
  },
  "platform": [
    {
      "name": "ext-json",
      "version": "*"
    }
  ],
  "scripts": [
    "lint",
    "test"
  ],
  "lockfiles": [
    "composer.lock"
  ],
  "unparsed": []
}

Collected for

GuardrailCategoryInputs
php/dependencies-constrainedphpprojectDir
php/lockfile-committedphpprojectDir
php/version-declaredphpprojectDir

All collectors

Buildnote Limited
Registered in England and Wales, Reg: 16140412