Skip to content

Commit

Permalink
Merge pull request #10694 from dsnopek/composer-library
Browse files Browse the repository at this point in the history
CRM-17652 - Update composer and Symfony for Drupal 8
  • Loading branch information
totten authored Aug 12, 2017
2 parents e3f6a2e + 9f1588f commit a1c16b9
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 98 deletions.
27 changes: 25 additions & 2 deletions CRM/Core/ClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,28 @@ protected function __construct() {
);
}

/**
* Requires the autoload.php generated by composer
*
* @return void
*/
protected function requireComposerAutoload() {
// We are trying to locate 'vendor/autoload.php'. When installing CiviCRM
// manually from the built tarball, that will be two directories up in the
// civicrm-core directory. However, if civicrm-core was installed via
// composer as a library, that'll be 5 directories up where composer was
// run (ex. the Drupal root on a Drupal 8 site).
$civicrm_base_path = dirname(dirname(__DIR__));
$top_path = dirname(dirname(dirname(dirname(dirname(__DIR__)))));

if (file_exists($civicrm_base_path . '/vendor/autoload.php')) {
require_once $civicrm_base_path . '/vendor/autoload.php';
}
elseif (file_exists($top_path . '/vendor/autoload.php')) {
require_once $top_path . '/vendor/autoload.php';
}
}

/**
* Registers this instance as an autoloader.
*
Expand All @@ -104,7 +126,7 @@ public function register($prepend = FALSE) {
}
$civicrm_base_path = dirname(dirname(__DIR__));

require_once dirname(dirname(__DIR__)) . '/vendor/autoload.php';
$this->requireComposerAutoload();

// we do this to prevent a autoloader errors with joomla / 3rd party packages
// use absolute path since we dont know the content of include_path as yet
Expand All @@ -123,7 +145,8 @@ public function register($prepend = FALSE) {
);
$include_paths = implode(PATH_SEPARATOR, $include_paths);
set_include_path($include_paths . PATH_SEPARATOR . get_include_path());
require_once "$civicrm_base_path/vendor/autoload.php";
// @todo Why do we need to load this again?
$this->requireComposerAutoload();
}

/**
Expand Down
3 changes: 3 additions & 0 deletions CRM/Utils/System/Drupal8.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,9 @@ public function loadBootStrap($params = array(), $loadUser = TRUE, $throwError =

// Create a mock $request object
$autoloader = require_once $root . '/vendor/autoload.php';
if ($autoloader === TRUE) {
$autoloader = ComposerAutoloaderInitDrupal8::getLoader();
}
// @Todo: do we need to handle case where $_SERVER has no HTTP_HOST key, ie. when run via cli?
$request = new \Symfony\Component\HttpFoundation\Request(array(), array(), array(), array(), array(), $_SERVER);

Expand Down
15 changes: 7 additions & 8 deletions Civi/Core/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public function loadContainer() {

require_once $file;
$c = new \CachedCiviContainer();
$c->set('service_container', $c);
return $c;
}

Expand Down Expand Up @@ -134,13 +133,13 @@ public function createContainer() {
'Civi\Angular\Manager',
array()
))
->setFactoryService(self::SELF)->setFactoryMethod('createAngularManager');
->setFactory(array(new Reference(self::SELF), 'createAngularManager'));

$container->setDefinition('dispatcher', new Definition(
'Civi\Core\CiviEventDispatcher',
array(new Reference('service_container'))
))
->setFactoryService(self::SELF)->setFactoryMethod('createEventDispatcher');
->setFactory(array(new Reference(self::SELF), 'createEventDispatcher'));

$container->setDefinition('magic_function_provider', new Definition(
'Civi\API\Provider\MagicFunctionProvider',
Expand All @@ -151,13 +150,13 @@ public function createContainer() {
'Civi\API\Kernel',
array(new Reference('dispatcher'), new Reference('magic_function_provider'))
))
->setFactoryService(self::SELF)->setFactoryMethod('createApiKernel');
->setFactory(array(new Reference(self::SELF), 'createApiKernel'));

$container->setDefinition('cxn_reg_client', new Definition(
'Civi\Cxn\Rpc\RegistrationClient',
array()
))
->setFactoryClass('CRM_Cxn_BAO_Cxn')->setFactoryMethod('createRegistrationClient');
->setFactory('CRM_Cxn_BAO_Cxn::createRegistrationClient');

$container->setDefinition('psr_log', new Definition('CRM_Core_Error_Log', array()));

Expand All @@ -170,7 +169,7 @@ public function createContainer() {
'type' => array('*memory*', 'SqlGroup', 'ArrayCache'),
),
)
))->setFactoryClass('CRM_Utils_Cache')->setFactoryMethod('create');
))->setFactory('CRM_Utils_Cache::create');
}

$container->setDefinition('sql_triggers', new Definition(
Expand All @@ -184,7 +183,7 @@ public function createContainer() {
));

$container->setDefinition('pear_mail', new Definition('Mail'))
->setFactoryClass('CRM_Utils_Mail')->setFactoryMethod('createMailer');
->setFactory('CRM_Utils_Mail::createMailer');

if (empty(\Civi::$statics[__CLASS__]['boot'])) {
throw new \RuntimeException("Cannot initialize container. Boot services are undefined.");
Expand All @@ -206,7 +205,7 @@ public function createContainer() {
$container->setDefinition($name, new Definition(
$class
))
->setFactoryClass($class)->setFactoryMethod('singleton');
->setFactory(array($class, 'singleton'));
}

$container->setDefinition('civi_token_compat', new Definition(
Expand Down
42 changes: 34 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
{
"name": "civicrm/civicrm-core",
"description": "Open source constituent relationship management for non-profits, NGOs and advocacy organizations.",
"type": "library",
"license": "AGPL-3.0",
"authors": [
{
"name": "Coleman Watts",
"role": "Product Manager"
},
{
"name": "Joshua Gowans",
"role": "Project Manager"
},
{
"name": "Mathieu Lutfy",
"role": "Infrastructure"
},
{
"name": "Tim Otten",
"role": "Software Architect"
},
{
"name": "CiviCRM Community",
"homepage": "https://civicrm.org"
}
],
"autoload": {
"psr-0": {
"PHPUnit_": ["packages/"],
Expand All @@ -10,20 +36,20 @@
"require": {
"dompdf/dompdf" : "0.8.*",
"electrolinux/phpquery": "^0.9.6",
"symfony/config": "~2.5.0",
"symfony/dependency-injection": "~2.5.0",
"symfony/event-dispatcher": "~2.5.0",
"symfony/filesystem": "~2.5.0",
"symfony/process": "~2.5.0",
"psr/log": "1.0.0",
"symfony/finder": "~2.5.0",
"symfony/config": "^2.6.13 || ~3.0",
"symfony/dependency-injection": "^2.6.13 || ~3.0",
"symfony/event-dispatcher": "^2.6.13 || ~3.0",
"symfony/filesystem": "^2.6.13 || ~3.0",
"symfony/process": "^2.6.13 || ~3.0",
"psr/log": "~1.0.0",
"symfony/finder": "^2.6.13 || ~3.0",
"tecnickcom/tcpdf" : "6.2.*",
"totten/ca-config": "~17.05",
"zetacomponents/base": "1.7.*",
"zetacomponents/mail": "dev-1.7-civi",
"phpoffice/phpword": "^0.13.0",
"pear/Validate_Finance_CreditCard": "dev-master",
"civicrm/civicrm-cxn-rpc": "~0.16.12.05",
"civicrm/civicrm-cxn-rpc": "~0.17.07.01",
"pear/Auth_SASL": "1.1.0",
"pear/Net_SMTP": "1.6.*",
"pear/Net_socket": "1.0.*"
Expand Down
Loading

0 comments on commit a1c16b9

Please sign in to comment.