本文整理汇总了PHP中DataMapper类的典型用法代码示例。如果您正苦于以下问题:PHP DataMapper类的具体用法?PHP DataMapper怎么用?PHP DataMapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DataMapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
protected function setUp()
{
$this->dataMapper = $this->getMock('FSi\\Component\\DataGrid\\DataMapper\\DataMapperInterface');
$this->dataMapper->expects($this->any())->method('getData')->will($this->returnCallback(function ($field, $object) {
switch ($field) {
case 'name':
return $object->getName();
break;
}
}));
$this->dataMapper->expects($this->any())->method('setData')->will($this->returnCallback(function ($field, $object, $value) {
switch ($field) {
case 'name':
return $object->setName($value);
break;
}
}));
$this->indexingStrategy = $this->getMock('FSi\\Component\\DataGrid\\Data\\IndexingStrategyInterface');
$this->indexingStrategy->expects($this->any())->method('getIndex')->will($this->returnCallback(function ($object, $dataMapper) {
if (is_object($object)) {
return $object->getName();
}
return null;
}));
$this->factory = $this->getMock('FSi\\Component\\DataGrid\\DataGridFactoryInterface');
$this->factory->expects($this->any())->method('getExtensions')->will($this->returnValue(array(new FooExtension())));
$this->factory->expects($this->any())->method('getColumnType')->with($this->equalTo('foo'))->will($this->returnValue(new FooType()));
$this->factory->expects($this->any())->method('hasColumnType')->with($this->equalTo('foo'))->will($this->returnValue(true));
$this->datagrid = new DataGrid('grid', $this->factory, $this->dataMapper, $this->indexingStrategy);
}
示例2: testGlobalMapping
/**
* @dataProvider globalMappedData
*/
public function testGlobalMapping($path, $data, $expected)
{
$mapper = new DataMapper();
foreach ($data as $globalData) {
$mapper->mapAll($globalData);
}
$this->assertEquals($expected, $mapper->data($path));
}
示例3: testShouldListPossibleParents
function testShouldListPossibleParents()
{
$mapper = new DataMapper($this->db);
$parent1_id = $mapper->save(array('name' => 'Parent 1'));
$mapper = new DataMapper($this->db);
$parent2_id = $mapper->save(array('name' => 'Parent 1a', 'paths' => array($parent1_id)));
$form = new Form($mapper);
$expected = array($parent1_id => 'Parent 1', $parent1_id . '/' . $parent2_id => 'Parent 1a');
$this->assertEquals($expected, $form->getElement('paths')->getMultiOptions());
}
示例4: testShouldUpdateAddress
function testShouldUpdateAddress()
{
$address = array('first_name' => 'Joshua', 'last_name' => 'Ribakoff', 'email' => 'josh.ribakoff@gmail.com', 'address' => '123 Test St', 'address2' => 'Suite 5', 'city' => 'Port St Lucie', 'state' => 'FL', 'postal' => '00123', 'country' => 'USA', 'phone' => '0101010101', 'fax' => '0202020202');
$addressMapper = new DataMapper($this->db);
$id = $addressMapper->save($address);
$updatedAddress = array('id' => $id, 'first_name' => 'Joshua-updated', 'last_name' => 'Ribakoff-updated', 'email' => 'josh.ribakoff-updated@gmail.com', 'address' => '123 Test St-updated', 'address2' => 'Suite 5-updated', 'city' => 'Port St Lucie-updated', 'state' => 'FL-updated', 'postal' => '12345', 'country' => 'USA-updated', 'phone' => '111111111', 'fax' => '2222222222');
$addressMapper = new DataMapper($this->db);
$id = $addressMapper->save($updatedAddress);
$loadedAddress = $addressMapper->load($id);
$this->assertSame($updatedAddress, $loadedAddress, 'should save new address');
}
示例5: testShouldSaveCartAndItems
function testShouldSaveCartAndItems()
{
$cart = new \Metator\Cart\Cart();
$cart->add(1, 9.99);
$cart->add(2, 4.99);
$cart->setQuantity(2, 2);
$order = array('items' => $cart, 'created' => '0000-00-00 00:00:00');
$orderMapper = new DataMapper($this->db);
$id = $orderMapper->save($order, null);
$reloaded_order = $orderMapper->load($id);
$this->assertEquals(array(1, 2), $reloaded_order['items']->items(), 'should save items');
}
示例6: __construct
public function __construct()
{
Cowl::timer('cowl init');
@session_start();
// I know that the @-notation is frowned upon, but adding it to session_start saves us unnecessary warnings
Cache::setDir(COWL_CACHE_DIR);
Current::initialize(COWL_DIR);
if (COWL_CLI) {
$this->parseCLIPath();
} else {
$this->parseRequestPath();
}
Cowl::timer('cowl set defaults');
// Get and set all directories for various things.
list($commands_dir, $model_dir, $validators_dir, $library_dir, $view_dir, $helpers_dir, $helpers_app_dir, $drivers_dir, $app_dir, $view_layout_dir, $validator_error_messages, $lang) = Current::$config->gets('paths.commands', 'paths.model', 'paths.validators', 'paths.library', 'paths.view', 'paths.helpers', 'paths.helpers_app', 'paths.drivers', 'paths.app', 'paths.layouts', 'paths.validator_messages', 'lang');
Controller::setDir($commands_dir);
DataMapper::setMappersDir($model_dir);
DataMapper::setObjectsDir($model_dir);
Validator::setPath($validators_dir);
Validator::loadStrings($validator_error_messages, $lang);
Templater::setBaseDir($view_dir);
Templater::setLayoutDir($view_layout_dir);
Library::setPath($library_dir);
Helpers::setPath($helpers_dir);
Helpers::setAppPath($helpers_app_dir);
Database::setPath($drivers_dir);
StaticServer::setDir($app_dir);
Cowl::timerEnd('cowl set defaults');
Cowl::timer('cowl plugins load');
Current::$plugins = new Plugins();
Cowl::timerEnd('cowl plugins load');
// Load default helper
Helpers::load('standard', 'form');
Cowl::timerEnd('cowl init');
}
示例7: __construct
public function __construct()
{
foreach ($this->objects as $map) {
$this->{strtolower($map . 'mapper')} = DataMapper::get($map);
}
$this->template = new Templater();
}
示例8: __construct
public function __construct($id = null)
{
if (!is_null($id)) {
$this->setID($id);
}
$this->validator = new Validator();
$this->validator->setStoreErrors(true);
$this->mapper = DataMapper::get(get_class($this));
}
示例9: delete
/**
* Delete this student or related object.
* If no parameters are set, this method deletes current student and all participant record related with this student.
* @param DataMapper|string $object related object to delete from relation.
* @param string $related_field relation internal name.
*/
public function delete($object = '', $related_field = '')
{
if (empty($object) && !is_array($object) && !empty($this->id)) {
$participant = new Participant();
$participant->where_related($this);
$participant->get();
$participant->delete_all();
}
parent::delete($object, $related_field);
}
示例10: delete
/**
* Delete this test or related object.
* If no parameters are set, this method deletes current test and all files associated with this test.
* @param DataMapper|string $object related object to delete from relation.
* @param string $related_field relation internal name.
*/
public function delete($object = '', $related_field = '')
{
if (empty($object) && !is_array($object) && !empty($this->id)) {
$path_to_test_files = 'private/uploads/unit_tests/test_' . $this->id;
if (file_exists($path_to_test_files)) {
unlink_recursive($path_to_test_files, TRUE);
}
}
parent::delete($object, $related_field);
}
示例11: delete
/**
* Deletes relations (if parameters are set) or this object from database.
* All comments which replies to this one will be deleted as well.
* @param DataMapper|string $object related object to delete from relation.
* @param string $related_field relation internal name.
*/
public function delete($object = '', $related_field = '')
{
$this_id = $this->id;
if (empty($object) && !is_array($object) && !empty($this_id)) {
$comments = $this->comment->get_iterated();
foreach ($comments as $comment) {
$comment->delete();
}
}
parent::delete($object, $related_field);
}
示例12: __construct
/**
* {@inheritdoc}
*/
public function __construct($id = null)
{
$trace = debug_backtrace();
if ((empty($trace[2]['object']) || !$trace[2]['object'] instanceof DataMapper) && self::$isInstantiated) {
throw new RuntimeException('System_setting can be instantiated only once!');
}
if ($this->hasTable($this->prefix . $this->table)) {
parent::__construct($id);
}
self::$isInstantiated = true;
}
示例13: delete
function delete($object = '')
{
if (empty($object)) {
$this->deattach();
}
return parent::delete($object);
}
示例14: __get
public function __get($name)
{
// // the conditions below should be replace by using the _get_relationship_type method
// belongs to relationship
if (in_array($name, $this->belongs_to)) {
return $this->_belongs_to($name);
} elseif (array_key_exists($name, $this->belongs_to) && is_array($this->belongs_to[$name])) {
return $this->_belongs_to($name, $this->belongs_to[$name]);
} elseif (in_array($name, $this->has_many)) {
return $this->_has_many($name);
} elseif (array_key_exists($name, $this->has_many) && is_array($this->has_many[$name])) {
return $this->_has_many($name, $this->has_many[$name]);
// for has_many :through
} elseif (array_key_exists($name, $this->has_many_through)) {
return $this->_has_many_through($name);
} elseif (in_array($name, $this->has_one)) {
return $this->_has_one($name);
} elseif (array_key_exists($name, $this->has_one) && is_array($this->has_one[$name])) {
return $this->_has_one($name, $this->has_one[$name]);
} elseif (method_exists($this, $name)) {
#echo $this;
return $this->{$name}();
} else {
return parent::__get($name);
}
}
示例15: __construct
public function __construct(Database $db, $user)
{
parent::__construct($db);
$this->table('logins');
$this->columns(array('id', 'users_id', 'unixtime'));
$this->has_one = array($user);
}