本文整理汇总了PHP中Matrix::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP Matrix::instance方法的具体用法?PHP Matrix::instance怎么用?PHP Matrix::instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix
的用法示例。
在下文中一共展示了Matrix::instance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: header
$result[] = $mapper->cast();
}
header("Content-type: application/json");
echo json_encode($result);
});
$f3->route('GET /plaintext', function ($f3) {
header("Content-type: text/plain");
echo "Hello, World!";
});
$f3->route('GET /fortune', function ($f3) {
/** @var Base $f3 */
$dbc = $f3->get('DBS');
$db = new \DB\SQL($dbc[0], $dbc[1], $dbc[2], array(\PDO::ATTR_PERSISTENT => TRUE));
$result = $db->exec('SELECT id, message FROM Fortune');
$result[] = array('id' => 0, 'message' => 'Additional fortune added at request time.');
$mtx = \Matrix::instance();
$mtx->sort($result, 'message');
$f3->set('result', $result);
echo \Template::instance()->render('fortune.html');
});
$f3->route(array('GET /update-raw', 'GET /update-raw/@queries'), function ($f3, $params) {
/** @var Base $f3 */
$queries = 1;
if (isset($params['queries'])) {
$queries = (int) $params['queries'];
$queries = $queries < 1 ? 1 : ($queries > 500 ? 500 : $queries);
}
$dbc = $f3->get('DBS');
$db = new \DB\SQL($dbc[0], $dbc[1], $dbc[2], array(\PDO::ATTR_PERSISTENT => TRUE));
$result = array();
for ($i = 0; $i < $queries; $i++) {
示例2: run
function run($db, $type)
{
$test = new \Test();
// setup
///////////////////////////////////
$author = new \AuthorModel();
$news = new \NewsModel();
$profile = new \ProfileModel();
$tag = new \TagModel();
$ac = $author::resolveConfiguration();
$author_pk = is_int(strpos($type, 'sql')) ? $ac['primary'] : '_id';
$nc = $news::resolveConfiguration();
$news_pk = is_int(strpos($type, 'sql')) ? $nc['primary'] : '_id';
$tc = $tag::resolveConfiguration();
$tag_pk = is_int(strpos($type, 'sql')) ? $tc['primary'] : '_id';
$authorIDs = $author->find()->getAll('_id');
$all = $news->find();
$newsIDs = $all->getAll('_id');
$profileIDs = $profile->find()->getAll('_id');
$tagIDs = $tag->find()->getAll('_id');
// add another relation
$news->load(array('title = ?', 'CSS3 Showcase'));
$news->author = $author->load(array($author_pk . ' = ?', $authorIDs[0]));
$news->save();
$news->reset();
$author->reset();
// has-filter on belongs-to relation
///////////////////////////////////
$result = $author->has('news', array('title like ?', '%Image%'))->afind();
$test->expect(count($result) == 1 && $result[0]['name'] == 'Johnny English', $type . ': has filter on many-to-one field');
\Matrix::instance()->sort($result[0]['news'], 'title');
$test->expect(count($result[0]['news']) == 2 && $result[0]['news'][0]['title'] == 'CSS3 Showcase' && $result[0]['news'][1]['title'] == 'Responsive Images', $type . ': has filter does not prune relation set');
$result = $news->has('author', array('name = ?', 'Johnny English'))->afind(null, array('order' => 'title DESC'));
$test->expect(count($result) == 2 && $result[0]['title'] == 'Responsive Images' && $result[1]['title'] == 'CSS3 Showcase', $type . ': has filter on one-to-many field');
// add another profile
$profile->message = 'Beam me up, Scotty!';
$profile->author = $authorIDs[2];
$profile->save();
$profile->reset();
$result = $author->has('profile', array('message LIKE ?', '%Scotty%'))->afind();
$test->expect(count($result) == 1 && $result[0]['name'] == 'James T. Kirk' && $result[0]['profile']['message'] == 'Beam me up, Scotty!', $type . ': has filter on one-to-one field');
$result = $profile->has('author', array('name LIKE ?', '%Kirk%'))->afind();
$test->expect(count($result) == 1 && $result[0]['message'] == 'Beam me up, Scotty!' && $result[0]['author']['name'] == 'James T. Kirk', $type . ': has filter on one-to-one field, inverse');
// add mm tags
$news->load(array('title = ?', 'Responsive Images'));
$news->tags2 = array($tagIDs[0], $tagIDs[1]);
$news->save();
$news->load(array('title = ?', 'CSS3 Showcase'));
$news->tags2 = array($tagIDs[1], $tagIDs[2]);
$news->save();
$news->reset();
$result = $news->has('tags2', array('title like ?', '%Design%'))->find();
$test->expect(count($result) == 1 && $result[0]['title'] == 'Responsive Images', $type . ': has filter on many-to-many field');
$result = $news->has('tags2', array('title = ?', 'Responsive'))->find();
$test->expect(count($result) == 2 && $result[0]['title'] == 'Responsive Images' && $result[1]['title'] == 'CSS3 Showcase', $type . ': has filter on many-to-many field, additional test');
$result = $tag->has('news', array('title = ?', 'Responsive Images'))->find();
$test->expect(count($result) == 2 && $result[0]['title'] == 'Web Design' && $result[1]['title'] == 'Responsive', $type . ': has filter on many-to-many field, inverse');
// add another tag
$news->load(array('title = ?', 'Touchable Interfaces'));
$news->tags2 = array($tagIDs[1]);
$news->save();
$news->reset();
$tag->has('news', array('text LIKE ? and title LIKE ?', '%Lorem%', '%Interface%'));
$result = $tag->find();
$test->expect(count($result) == 1 && $result[0]['title'] == 'Responsive', $type . ': has filter with multiple conditions');
$news->has('tags2', array('title = ? OR title = ?', 'Usability', 'Web Design'));
$result = $news->afind(array('text = ?', 'Lorem Ipsun'));
$test->expect(count($result) == 1 && $result[0]['title'] == 'Responsive Images', $type . ': find with condition and has filter');
$news->load(array('title = ?', 'Responsive Images'));
$news->author = $authorIDs[1];
$news->save();
$news->reset();
$news->has('tags2', array('title = ? OR title = ?', 'Usability', 'Web Design'));
$news->has('author', array('name = ?', 'Ridley Scott'));
$result = $news->afind();
$test->expect(count($result) == 1 && $result[0]['title'] == 'Responsive Images', $type . ': find with multiple has filters on different relations');
// add another news to author 2
$news->load(array($news_pk . ' = ?', $newsIDs[2]));
$news->author = $authorIDs[1];
$news->save();
$news->reset();
$news->has('author', array('name = ?', 'Ridley Scott'));
$news->load(null, array('order' => 'title'));
$res = array();
while (!$news->dry()) {
$res[] = $news->title;
$news->next();
}
$test->expect(count($res) == 2 && $res[0] == 'Responsive Images' && $res[1] == 'Touchable Interfaces', $type . ': has filter in load context');
$news->reset();
$news->fields(array('title'));
$news->load();
$test->expect(!empty($news->title) && empty($news->author) && empty($news->text) && empty($news->tags) && empty($news->tags2), $type . ': use a whitelist to restrict fields');
unset($news);
$news = new \NewsModel();
$news->fields(array('title', 'tags', 'tags2', 'author'), true);
$news->load();
$test->expect(empty($news->title) && empty($news->author) && !empty($news->text) && empty($news->tags) && empty($news->tags2), $type . ': use a blacklist to restrict fields');
unset($news);
$news = new \NewsModel();
//.........这里部分代码省略.........