Browse files

PHP Parser works by serializing / unserializing the arrays

  • Loading branch information...
1 parent 3f74c7c commit 5af323d4e50a52aa44fa1bc04ccf8a79a9bfc4a6 @shakty committed Apr 22, 2012
Showing with 20 additions and 26 deletions.
  1. +3 −1 includes/forms/editor.inc
  2. +15 −22 patterns_phpparser/patterns_phpparser.module
  3. +2 −3 tests/README.md
View
4 includes/forms/editor.inc
@@ -259,7 +259,9 @@ function patterns_load_co2($format = PATTERNS_FORMAT_YAML) {
drupal_add_css($co2_css_theme);
drupal_add_js($co2_js);
- if ($format !== PATTERNS_FORMAT_UNKNOWN) {
+ // TODO: enable PHP mode for codemirror as well.
+ // At the moment it does not work
+ if ($format !== PATTERNS_FORMAT_UNKNOWN && $format !== 'php') {
$co2_mode = $co2_path . '/mode/' . $format . '/' . $format . '.js';
drupal_add_js($co2_mode);
}
View
37 patterns_phpparser/patterns_phpparser.module
@@ -33,35 +33,25 @@ function patterns_phpparser_load_new($path, $local = TRUE) {
}
/**
- * @depracated
+ * Loads a serialized PHP pattern array from file.
*
+ * @param mixed $path The path of the pattern file.
+ * @param bool $local
+ * (optional) TRUE if the pattern file is local. Defaults to TRUE.
+ *
+ * @return array|bool
+ * The pattern structure, or FALSE.
*/
function patterns_phpparser_load($path, $local = TRUE) {
if ($local && !file_exists($path)) {
return FALSE;
}
- // TODO: not working
- return FALSE;
-
- // $pattern = array();
- // include $path
- // return $pattern;
-
-
-
if (!$php = file_get_contents($path)) {
return FALSE;
}
-
- // That should have declared a 'pattern' into current scope.
- //if (!patterns_validate_pattern($pattern)) {
- // // TODO: why not drupal_set_message?
- // trigger_error(t("Failed to evaluate a useful pattern from the input file %path. Pattern did not validate. May have been invalid syntax.", array('%path' => $path)), E_USER_WARNING);
- // return FALSE;
- //}
- return $php;
+ return patterns_phpparser_parse($php);
}
@@ -77,9 +67,10 @@ function patterns_phpparser_parse($pattern = NULL) {
if (is_array($pattern)) return $pattern;
if (!is_string($pattern)) return FALSE;
- // TODO: at the moment string parsing does not work
+ return unserialize($pattern);
- return FALSE;
+ // TODO: at the moment string parsing does not work
+ //return FALSE;
//$outout = array();
//parse_str($pattern, $output);
@@ -95,9 +86,11 @@ function patterns_phpparser_parse($pattern = NULL) {
function patterns_phpparser_dump($pattern = NULL) {
if (is_null($pattern) || !is_array($pattern)) return FALSE;
- $string = '';
+ $string = serialize($pattern);
+
+ //$string = '';
//foreach ($subs as $key => $value) {
- $string = "\$pattern = " . var_export($pattern, TRUE) . ";\n";
+ // $string = "\$pattern = " . var_export($pattern, TRUE) . ";\n";
//}
return $string;
}
View
5 tests/README.md
@@ -21,12 +21,11 @@
The following parts of the Patterns module still need a test. Feel free to contribute!
- - Lab page
+ - Check if all the pages are loaded without errors
+ - Add specific tests for Lab page, Export page, Public Page
- YAML parser
- XML parser
- PHP parser
- First Install screen
- - Export page
- - Public page
- Patterns D2D
- How tagmodules and modulestag indexes are built

0 comments on commit 5af323d

Please sign in to comment.