Historically, this concept was invented for KPHP, but later exposed as a separate project named nocolor.
Colored functions are of course still embedded into KPHP, but for documentation, we'll refer you here:
Visit “Introducing colored functions” page
@kphp-color
instead of @color
palette.yaml
, you declare the palette in PHP, in the KphpConfiguration
class// a separate file KphpConfiguration.php
class KphpConfiguration {
const FUNCTION_PALETTE = [
[
'highload no-highload' => "Don't call a no-highload function from a highload one",
'highload allow-no-highload no-highload' => 1,
],
[
'ssr rpc' => "Don't perform rpc queries from SSR: pass already prepared data",
'ssr ssr-allow-rpc rpc' => 1,
]
];
}
Save this folder from kphp-snippets somewhere. Execute
kphp2cpp index.php -M cli
Compilation will fail with the message:
fast slow => Potential performance leak
This color rule is broken, call chain:
ApiRequestHandler::handleRequest@fast -> Logger::debug -> DBLayer::addToLogTable@slow
If you
@kphp-color
from a demo@kphp-color slow-ignore
over Logger::debug()
then compilation will succeed.
Here's an article on Habr (in Russian) which also describes this concept: