PHP code example of civicrm / cv-lib

1. Go to this page and download the library: Download civicrm/cv-lib 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/ */

    

civicrm / cv-lib example snippets


    Civi\Cv\CmsBootstrap::singleton()->bootCms()->bootCivi();
    

    $options = [...];
    Civi\Cv\CmsBootstrap::singleton()
      ->addOptions($options)
      ->bootCms()
      ->bootCivi();
    

    $options = [...];
    \Civi\Cv\Bootstrap::singleton()->boot($options);
    \CRM_Core_Config::singleton();
    \CRM_Utils_System::loadBootStrap([], FALSE);
    

// Disable all output
$options['log'] = new \Psr\Log\NullLogger();

// Enable verbose logging to STDOUT/STDERR
$options['log'] = new \Civi\Cv\Log\StderrLogger('Bootstrap', TRUE);

// Use bridge between psr/log and symfony/console
$options['log'] = new \Symfony\Component\Console\Logger\ConsoleLogger($output);

// Use the console logger from cv cli. (Requires symfony/console. Looks a bit prettier.)
public function execute(InputInterface $input, OutputInterface $output) {
  ...
  $options['output'] = $output;
  ...
}