Problem/Motivation

Move classes from bootstap.inc and 'use' them instead.
This is motivated by my overall interest in cleaning up bootstrap.inc. Though this is a part of our overall goal making our classes PSR-0 namespaced.

Proposed resolution

Move DrupalCacheArray to new Drupal\Core\Utilities namespace.
Move SchemaCache to new Drupal\Core\Schema namespace. Drupal\Core\Utilities as well.
OOp lock system and inject into into DrupalCacheArray.
'use' new classes where needed.

Remaining tasks

There is an issue open for OOPing the locking system #1225404: Modern event based lock framework proposal - instead of tackling the injection of the locking system inthe DrupalCacheArray as part of this issue, a new refactoring issue should be opened with a dependency on #1225404.

User interface changes

None

API changes

None - just need to 'use' the classes where appropriate.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

catch’s picture

DrupalCacheArray itself I don't think belongs in the cache subsystem (at the moment it has a cross-dependency on the lock system for a start), and feels more like a standalone to me.

The Schema class should go in the Drupal\Core\Schema namespace, except we'd need to convert the schema API to classes first. There may be an issue for that already.

Crell’s picture

Agreed with catch. DrupalCacheArray should be its own thing, and we should try to remove those dependencies if possible (or inject them). For schema... Overhauling the Schema API to be more consistent and modern is on my todo list, but so are many other things. :-/

Perhaps we should have a Drupal\Core\Utility for these one-off little classes for the time being, so they don't pollute Drupal\Core if they have nowhere else to go.

andremolnar’s picture

Issue summary: View changes

Updating proposed solution based on feedback.

andremolnar’s picture

Title: Move DrupalCacheArray and SchemaCache from bootstrap.inc » Remove DrupalCacheArray and SchemaCache from bootstrap.inc

Updated issue with suggestions.

As an initial pass I'll create the new namespaces and move the classes there. As a follow up I'll look at lock.inc and see if it makes sense to OO it and inject it into the DrupalCacheArray

catch’s picture

There's an issue for lock.inc at #1225404: Modern event based lock framework proposal however it's gone quite a bit further than a straight OOP-ifying, so I'm wondering if we need a new issue for a straight-as-possible conversion to unblock the general detangling issues such as this.

andremolnar’s picture

Status: Active » Needs review
FileSize
17.5 KB

Rather than add a dependency on a yet to be created issue, would it make more sense to move the classes out as a start to 'detangle' and then open an issue to refactor DrupalCacheArray with a note to inject the reworked locking system?
DrupalCache array needs to be refactored anyway since it has comments in the code re: limitations of PHP pre-5.3 (but that's beyond the scope of what I'm trying to achieve here - i.e. bootstrap cleanup and a quick PSR-0 win.).

andremolnar’s picture

I had second thoughts (felt icky) about extending a class from one namespace in an entirely different one.
Asked Crell quickly in IRC and now moving SchemaCache into the Utilities namespace (since it extends the DrupalCacheArray).

amateescu’s picture

Title: Remove DrupalCacheArray and SchemaCache from bootstrap.inc » Convert DrupalCacheArray and SchemaCache to PSR-0
Status: Needs review » Needs work
+++ b/core/lib/Drupal/Core/Utilities/DrupalCacheArray.php
@@ -0,0 +1,202 @@
+<?php
+namespace Drupal\Core\Utilities;
+use \ArrayAccess;

Missing @file doc block: http://drupal.org/node/1354#files

Also, missing blank line between the namespace declaration and the use statement, and I think we decided against using "\" in front of class names.

For inspiration, you can take a look at a class that has already been converted, like http://drupalcode.org/project/drupal.git/blob/refs/heads/8.x:/core/lib/D...

+++ b/core/lib/Drupal/Core/Utilities/DrupalCacheArray.php
@@ -0,0 +1,202 @@
+abstract class DrupalCacheArray implements ArrayAccess {

I think we need to drop 'Drupal' and rename to CacheArray.

+++ b/core/lib/Drupal/Core/Utilities/DrupalCacheArray.php
@@ -0,0 +1,202 @@
\ No newline at end of file
+++ b/core/lib/Drupal/Core/Utilities/SchemaCache.php
@@ -0,0 +1,28 @@
\ No newline at end of file

Meh :)

andremolnar’s picture

Re-rolling with suggested fixes from #7.
I also think dropping Drupal from the class name is a good idea / sensible since Drupal classes are namespaced Drupal\ anyway.

andremolnar’s picture

Issue summary: View changes

Updated motivation for the issue.

andremolnar’s picture

Status: Needs work » Needs review
catch’s picture

This looks good to me now. I think we'll eventually want to move the schema cache stuff into the schema namespace, but that can wait on having actual code existing there.

There's not really a problem extending classes in different namespaces as far as I'm concerned - it just shows the various dependencies for what they are.

Crell’s picture

Status: Needs review » Needs work

I think we're using singular namespaces, not plural, so it should be Drupal\Core\Utility, not Drupal\Core\Utilities. Other than that, this looks done.

Partially agreed with catch. Inheriting from an out-of-namespace class isn't a bad thing. However, if you're inheriting back and forth like a madman between two namespaces, it is a code smell that maybe they should be the same namespace/package.

Either way, fix the pluralization here and I think we're good to go.

andremolnar’s picture

Status: Needs work » Needs review
FileSize
17.86 KB

Renamed Utilities to Utility. If testbot comes back green I'll take the liberty of RTBCing this.

andremolnar’s picture

Status: Needs review » Reviewed & tested by the community
Crell’s picture

And I second that.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.x, thanks!

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Updating issue based on latest information in the thread and to reflect the lastest patch.