Skip to main content

Configuration

On this page

Phel reads phel-config.php from the project root. Most projects only need the factory:

<?php
// phel-config.php
return \Phel\Config\PhelConfig::forProject(\Phel\Config\ProjectLayout::Flat, 'your-ns.main');

Sets src/, tests/, and the build entry namespace. Chain withX() methods to override.

Common tweaks#

<?php
use Phel\Config\PhelConfig;
use Phel\Config\ProjectLayout;

return PhelConfig::forProject(ProjectLayout::Flat, 'your-ns.main')
    ->withSrcDirs(['src'])                      // Phel source roots
    ->withTestDirs(['tests'])                   // test roots, picked up by `phel test`
    ->withFormatDirs(['src', 'tests'])          // dirs `phel format` rewrites
    ->withMainPhelNamespace('your-ns.index')    // entry ns for `phel build`
    ->withMainPhpPath('out/index.php')          // generated PHP entry
;

Covers running, testing, formatting, building. Defaults handle the rest.

Full reference#

All available options
<?php
// phel-config.php, every with*() option, default values shown
return (new \Phel\Config\PhelConfig())
    ->withSrcDirs(['src'])
    ->withTestDirs(['tests'])
    ->withVendorDir('vendor')
    ->withErrorLogFile('.phel/error.log')
    ->withIgnoreWhenBuilding(['ignore-when-building.phel'])
    ->withNoCacheWhenBuilding([])
    ->withFormatDirs(['src', 'tests'])
    ->withKeepGeneratedTempFiles(false)
    ->withTempDir(sys_get_temp_dir().'/phel')
    ->withCacheDir('.phel/cache')
    ->withPhelDir('.phel')
    ->withEnableNamespaceCache(true)
    ->withEnableCompiledCodeCache(true)
    ->withMainPhelNamespace('your-ns.index')
    ->withMainPhpPath('out/index.php')
    ->withBuildDestDir('out')
    ->withExportFromDirectories(['src'])
    ->withExportNamespacePrefix('PhelGenerated')
    ->withExportTargetDirectory('src/PhelGenerated')
;
MethodPurpose
withLayoutApply ProjectLayout::Flat, Nested, or Root. Sets src/test/format/export dirs.
withSrcDirsSource directories scanned by the compiler.
withTestDirsDirectories phel test walks.
withVendorDirComposer vendor directory name.
withErrorLogFilePath of the error.log file (under .phel/ by default).
withIgnoreWhenBuildingPhel files skipped by phel build.
withNoCacheWhenBuildingFiles always retranspiled, regardless of --cache / --no-cache.
withFormatDirsDirectories rewritten by phel format.
withKeepGeneratedTempFilesKeep generated temp files after phel run. Default false.
withTempDirAbsolute path for temporary files. Throws if not writable.
withCacheDirDirectory for namespace + compiled-code caches. Default .phel/cache.
withPhelDirRoot for runtime state (cache, REPL history, error log). Default .phel. Override via PHEL_DIR env.
withEnableNamespaceCachePersistent namespace cache for warm runs. Default true.
withEnableCompiledCodeCacheCompiled-code cache for tests/builds. Default true.
withEnableAssertsToggle runtime assert checks.
withWarnDeprecationsEmit warnings on deprecated APIs.
withMainPhelNamespaceEntry ns for phel build.
withMainPhpPathGenerated PHP entry path.
withBuildDestDirOutput directory for phel build.
withExportFromDirectoriesSource dirs scanned by phel export.
withExportNamespacePrefixPHP namespace prefix for exported wrappers.
withExportTargetDirectoryOutput dir for phel export. See PHP Interop.
withBuildConfig / withExportConfigReplace nested config objects wholesale (rarely needed).

Note: Old setX() setters are deprecated since 0.37 and emit notices. Use the withX() chain - the API is immutable.