/[drupal]/contributions/sandbox/crell/fileoop.php
ViewVC logotype

Contents of /contributions/sandbox/crell/fileoop.php

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Fri Nov 30 07:37:25 2007 UTC (23 months, 4 weeks ago) by crell
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +21 -1 lines
File MIME type: text/x-php
- Added $options array to queries (partial, untested).
- Tweakery in fileoop.php brainstorm.
1 <?php
2
3 function debug($msg) {
4 if (is_bool($msg)) $msg = $msg ? 'TRUE' : 'FALSE';
5 $backtrace = debug_backtrace();
6 // print "DEBUG: {$backtrace[1]['class']}::{$backtrace[1]['function']}::{$backtrace[0]['line']}: <pre>" . print_r($msg, 1) . "</pre><br />\n";
7 print "DEBUG: {$backtrace[0]['line']}: <pre>" . print_r($msg, 1) . "</pre><br />\n";
8 }
9
10 interface Loadable {
11
12 public static function load($id);
13
14 function insert();
15
16 function update();
17
18 function save();
19
20 function delete();
21
22 }
23
24 abstract class Asset implements Loadable {
25
26 protected $variants = array();
27
28 protected abstract function getDefaultKeys();
29
30 public abstract function getVariant(array $keys);
31
32 public function fields() {
33 $this->getDefaultVariant()->fields();
34 }
35
36 public function getDefaultVariant() {
37 return $this->getVariant($this->getDefaultKeys());
38 }
39
40 public static function load($id) {}
41 public function insert() {}
42 public function update() {}
43 public function save() {}
44 public function delete() {}
45
46 }
47
48 abstract class AssetVariant {
49
50 protected $fields = array();
51
52 public abstract function fields();
53 }
54
55 class File extends Asset {
56
57 public function getVariant(array $keys) {
58 $keys += $this->getDefaultKeys();
59
60 }
61
62 public function fields() {
63
64 }
65
66 protected function getDefaultKeys() {
67 return module_invoke_all('file');
68 }
69
70 }
71
72 class FileVariant extends AssetVariant {
73
74 public function fields() {
75
76 }
77 }
78
79 function example_file() {
80 return array('mime_type' => 'image/png');
81 }
82
83 function module_list() {
84 $modules = array('example');
85 return $modules;
86 }
87
88 function module_implements($hook) {
89 $modules = array();
90 foreach (module_list() as $module) {
91 if (function_exists("{$module}_{$hook}")) {
92 $modules[] = $module;
93 }
94 }
95 return $modules;
96 }
97
98 function module_invoke_all($hook) {
99 $return = array();
100 foreach (module_implements($hook) as $module) {
101 $return = array_merge($return, call_user_func("{$module}_{$hook}"));
102 }
103 return $return;
104 }
105
106 //$variants = module_invoke_all('file');
107 //debug($variants);
108

  ViewVC Help
Powered by ViewVC 1.1.2