class phabricator::php {

  # TODO: It's not currently possible to test for warnings with `rspec-puppet`.
  # See https://github.com/rodjek/rspec-puppet/issues/108.
  if $facts['phpversion'] != undef and versioncmp($facts['phpversion'], '7.0.0') >= 0 and versioncmp($facts['phpversion'], '7.1.0') < 0 {
    warning('Phabricator does not support PHP 7.0. See https://secure.phabricator.com/T12101.')
  }
  
  class { '::php::globals': php_version => '7.2'}
  class{'::php':
    ensure       => 'latest',
    fpm          => true,
    fpm_service_ensure => 'running',
    settings => {
      'Date/date.timezone' => 'Europe/Paris',
      
# https://secure.phabricator.com/book/phabricator/article/configuring_file_storage/      
      'PHP/post_max_size'  =>     '32M',
      'PHP/memory_limit'   =>     '-1',
      'PHP/upload_max_filesize' =>  '32M',
      
      'opcache/opcache.validate_timestamps' => '0',
      'apcu/apc.shm_size' => '256M'
    }
  }
  
  php::fpm::pool { 'phabricator':
    user  => $phabricator::www_user,
    group => $phabricator::group,
    listen => $phabricator::fpm_socket,
    listen_owner => 'www-data',
    listen_group => 'www-data'
  }
  
  php::extension {
    ['curl', 'gd', 'mbstring', 'zip']: ;
    
    'apcu':
      package_prefix => 'php-';
  }
  
  ensure_packages('php-mysql')
}
