1. Go to this page and download the library: Download zeecoder/good-to-know library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zeecoder / good-to-know example snippets
use ZeeCoder\GoodToKnow\GoodToKnow;
use ZeeCoder\GoodToKnow\Repository\YamlFileRepository;
// The `GoodToKnow` object acts as a wrapper around the given repository.
// Every call made to this object is forwarded to the repository.
// The listeners are fired after getting the result collection from the
// repository.
$gtk = new GoodToKnow(
new YamlFileRepository(__DIR__ . '/good-to-know.yml')
// A dispatcher could be passed as the second argument.
// If no dispatcher is given, one gets created
);
// `findAllByGroups` is a method in the `YamlFileRepository` repository.
// It returns a collection of `ZeeCoder\GoodToKnow\Fact` objects.
// (In this case, an `\SplObjectStorage`.)
$collection = $gtk->findAllByGroups([
'feature1'
]);
// The collection would have the "Something important." and
// "Something important about both features." texts as Fact objects.
// ...
// Assuming the example above
use ZeeCoder\GoodToKnow\ParameterInjector;
use ZeeCoder\GoodToKnow\Events;
use ZeeCoder\GoodToKnow\Listener\ParameterListener;
// Getting the dispatcher, since we didn't provide one explicitly.
$dispatcher = $gtk->getDispatcher();
// Creating the ParameterInjector
$parameterInjector = (new ParameterInjector())
// Registering parameters
->addParameter('%lorem%', 'ipsum')
->addParameter('%upload_max_filesize%', function() {
return ini_get('upload_max_filesize');
})
;
// Adding the listener.
// The TRANSFORM event is fired for every result returned by the repository.
$dispatcher->addListener(
Events::TRANSFORM,
new ParameterListener($parameterInjector)
);
$collection = $gtk->findAllByGroups([
'feature1'
]);
// Now the collection would have the "Something important. ipsum!" and
// "Something important about both features: The upload max filesize is: 2M."
// texts as Fact objects.
use ZeeCoder\GoodToKnow\Events;
use ZeeCoder\GoodToKnow\Listener\TranslationListener;
// Getting the dispatcher, since we didn't provide one explicitly.
$dispatcher = $gtk->getDispatcher();
$dispatcher->addListener(
Events::TRANSFORM,
new TranslationListener(
// Assuming we have a Symfony `$translator` object.
$translator
// The second parameter, is the translation domain. Default: "good-to-know"
)
);
// Now all Fact texts will be translated.
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.