Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
14098 anikendra 1
<?php
2
/**
3
 * Schemaless behavior.
4
 *
5
 * Adds functionality specific to MongoDB/schemaless dbs
6
 * Allow /not/ specifying the model's schema, and derive it (for cake-compatibility) from the data
7
 * being saved. Note that used carelessly this is a pretty dangerous thing to allow - means a user
8
 * can modify input forms adding whatever fields they like (unless you'er using the security
9
 * component) and fill your db with their junk.
10
 *
11
 * PHP version 5
12
 *
13
 * Copyright (c) 2010, Andy Dawson
14
 *
15
 * Licensed under The MIT License
16
 * Redistributions of files must retain the above copyright notice.
17
 *
18
 * @filesource
19
 * @copyright     Copyright (c) 2010, Andy Dawson
20
 * @link          www.ad7six.com
21
 * @package       mongodb
22
 * @subpackage    mongodb.models.behaviors
23
 * @since         v 1.0 (24-May-2010)
24
 * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
25
 */
26
 
27
/**
28
 * SchemalessBehavior class
29
 *
30
 * @uses          ModelBehavior
31
 * @package       mongodb
32
 * @subpackage    mongodb.models.behaviors
33
 */
34
class SchemalessBehavior extends ModelBehavior {
35
 
36
/**
37
 * name property
38
 *
39
 * @var string 'Schemaless'
40
 * @access public
41
 */
42
	public $name = 'Schemaless';
43
 
44
/**
45
 * settings property
46
 *
47
 * @var array
48
 * @access public
49
 */
50
	public $settings = array();
51
 
52
/**
53
 * defaultSettings property
54
 *
55
 * @var array
56
 * @access protected
57
 */
58
	protected $_defaultSettings = array(
59
	);
60
 
61
/**
62
 * setup method
63
 *
64
 * Don't currently have any settings at all - disabled
65
 *
66
 * @param mixed $Model
67
 * @param array $config array()
68
 * @return void
69
 * @access public
70
 */
71
	public function setup(Model $Model, $config = array()) {
72
		//$this->settings[$Model->alias] = array_merge($this->_defaultSettings, $config);
73
	}
74
 
75
/**
76
 * beforeSave method
77
 *
78
 * Set the schema to allow saving whatever has been passed
79
 *
80
 * @param mixed $Model
81
 * @return void
82
 * @access public
83
 */
84
	public function beforeSave(Model $Model, $config = array()) {
85
		$Model->cacheSources = false;
86
		$Model->schema(true);
87
		return true;
88
	}
89
}