Ticket #2380 (reopened defect)

Opened 5 months ago

Last modified 4 months ago

Class declarations in comments are treated as real by ManifestBuilder

Reported by: mrickerby Assigned to: sminnee
Type: defect Priority: blocker
Milestone: Component: Sapphire Framework
Version: 2.2.2-rc2 Severity: medium effort / impact
Keywords: db model framework manifest Cc: ischommer
Due date: Harvest Task: (Unknown)
Invoice sent to client: 0 Hours:

Description (last modified by mrickerby) (diff)

When class declarations that inherit from DataObject are declared in comments, ManifestBuilder::parse_file will treat it as a real class, and db/build will break when it discovers the class doesn't actually exist.

eg: the following example comment will break db/build:

/**
 *
 * <example>
 * class MyCustomClass extends DataObject {
 *    static $db = array();
 * }
 * </example>
 *
 */

Attachments

Change History

Changed 5 months ago by mrickerby

  • description changed from When class declarations that inherit from DataObject are declared in comments, {{{ManifestBuilder::parse_file}}} will treat it as a real class, and db/build will break when it discovers the class doesn't actually exist. eg: the following example comment will break db/build: {{{ /** * * <example> * class MyCustomClass extends DataObject { * static $db = array(); * } * </example> * */ }}} to When class declarations that inherit from {{{DataObject}}} are declared in comments, {{{ManifestBuilder::parse_file}}} will treat it as a real class, and db/build will break when it discovers the class doesn't actually exist. eg: the following example comment will break db/build: {{{ /** * * <example> * class MyCustomClass extends DataObject { * static $db = array(); * } * </example> * */ }}}

Changed 5 months ago by sminnee

The dark side of parsing the the PHP files without using the PHP interpreter. :-P

Perhaps we should make use of the PHP tokenizer in ManifestBuilder? instead?

Changed 5 months ago by sminnee

An alternative solution to this problem, which might be easier/quicker than invoking the PHP tokenizer, would be to strip out comments and strings from the file's content before searching for classes.

It would be good if we could profile execution speed and memory usage of the manifest builder when choosing which implementation to go with.

Changed 5 months ago by sminnee

  • status changed from new to closed
  • resolution set to fixed

This is done. I went with the latter option, in the interests of implementation speed - see r52246.

Changed 4 months ago by sminnee

  • cc set to ischommer
  • status changed from closed to reopened
  • resolution deleted

This wound up being a lot more complex than originally supposed. The current implementation in trunk uses the PHP tokeniser and a regular-expression-like parser that acts on tokens rather than characters.

It produces very valid results, but it's very slow (about 10 seconds on my macbook to parse all files). As a consequence, I've resorted to caching the parse results of each file, and only reparses files that have actually changed. This means that it's nice and fast, but I'm concerned about adding more caching, considering that SilverStripe? already caches a lot.

The changes are in r52327. Do we want to stick with this implementation, or should we go back to the drawing board?

Changed 4 months ago by sharvey

We ran into the same problem on #2398

Note: See TracTickets for help on using tickets.