本文整理汇总了PHP中Entity类的典型用法代码示例。如果您正苦于以下问题:PHP Entity类的具体用法?PHP Entity怎么用?PHP Entity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Entity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: post2
/**
* send a message to specified fluentd.
*
* @todo use HTTP1.1 protocol and persistent socket.
* @param string $tag
* @param array $data
*/
public function post2(Entity $entity)
{
$packed = json_encode($entity->getData());
$request = sprintf('http://%s:%d/%s?json=%s', $this->host, $this->port, $entity->getTag(), urlencode($packed));
$ret = file_get_contents($request);
return $ret !== false;
}
示例2: GetKids
function GetKids()
{
$entity = new Entity();
$query = "SELECT * FROM #__categories WHERE parent = ? ORDER BY ordering";
$objects = $entity->Collection($query, $this->id, __CLASS__);
return $objects;
}
示例3: itemsToArray
/**
* Преобразование ветки объектов в структуру из массивов для вывода в шаблоне
* @param array $items Масив объектов - пунктов меню
* @param Entity $active Активный пункт меню
* @param bool $sub_active Признак, есть или нет активные подчиненные?
* @return array
*/
protected function itemsToArray($items, $active, &$sub_active = false)
{
$list = array();
$have_active = false;
foreach ($items as $item) {
$children = $item['sub'];
$item = $item['object'];
$real = $item->linked();
$info = array('title' => $item->title->value(), 'icon' => false, 'url' => Request::url($real->uri()), 'active' => $active && $active->eq($real) ? 1 : 0);
// Иконка
// $icon = $item->icon->isExist() ? $item->icon : ($real->icon->isExist()? $real->icon : null);
// if ($icon && !$icon->isDraft() && !$icon->isHidden()){
// $info['icon'] = $icon->resize(0,30,Image::FIT_OUTSIDE_LEFT_TOP)->file();
// }
// Если заголовок не определен
if (empty($info['title'])) {
$info['title'] = $real->title->value();
if (empty($info['title'])) {
$info['title'] = $real->name();
}
}
if ($children) {
$info['children'] = $this->itemsToArray($children, $active, $sub_active);
if (!$info['active'] && $sub_active) {
$info['active'] = 2;
}
}
$have_active = $have_active || $info['active'];
$list[] = $info;
}
$sub_active = $have_active;
return $list;
}
示例4: testInit
public function testInit()
{
$entity = new Entity();
$entity->name = 'myname';
$entity->loginname = 'test';
$entity->save();
}
示例5: can_upload
function can_upload($session)
{
if ($session['authenticator']) {
$auth = $session['authenticator'];
$reason_session =& get_reason_session();
$username = $reason_session->get("username");
if (isset($_REQUEST['user_id']) && !empty($_REQUEST['user_id'])) {
$username = $reason_session->get('username');
$param_cleanup_rules = array('user_id' => array('function' => 'turn_into_int', 'extra_args' => array('zero_to_null' => 'true')));
$cleanRequest = array_merge($_REQUEST, carl_clean_vars($_REQUEST, $param_cleanup_rules));
$nametag = $cleanRequest['user_id'];
$id = get_user_id($username);
if (reason_user_has_privs($id, 'pose_as_other_user')) {
$user = new Entity($nametag);
$username = $user->get_value("name");
}
}
if ($auth['file']) {
require_once $auth['file'];
}
$args = array_merge(array($username), $auth['arguments']);
if (!call_user_func_array($auth['callback'], $args)) {
return false;
}
}
return true;
}
示例6: testInitJoinTableSelfReferencingInsertingData
public function testInitJoinTableSelfReferencingInsertingData()
{
$e = new Entity();
$e->name = "Entity test";
$this->assertTrue($e->Entity[0] instanceof Entity);
$this->assertTrue($e->Entity[1] instanceof Entity);
$this->assertEqual($e->Entity[0]->state(), Doctrine_Record::STATE_TCLEAN);
$this->assertEqual($e->Entity[1]->state(), Doctrine_Record::STATE_TCLEAN);
$e->Entity[0]->name = 'Friend 1';
$e->Entity[1]->name = 'Friend 2';
$e->Entity[0]->Entity[0]->name = 'Friend 1 1';
$e->Entity[0]->Entity[1]->name = 'Friend 1 2';
$e->Entity[1]->Entity[0]->name = 'Friend 2 1';
$e->Entity[1]->Entity[1]->name = 'Friend 2 2';
$this->assertEqual($e->Entity[0]->name, 'Friend 1');
$this->assertEqual($e->Entity[1]->name, 'Friend 2');
$this->assertEqual($e->Entity[0]->Entity[0]->name, 'Friend 1 1');
$this->assertEqual($e->Entity[0]->Entity[1]->name, 'Friend 1 2');
$this->assertEqual($e->Entity[1]->Entity[0]->name, 'Friend 2 1');
$this->assertEqual($e->Entity[1]->Entity[1]->name, 'Friend 2 2');
$this->assertEqual($e->Entity[0]->state(), Doctrine_Record::STATE_TDIRTY);
$this->assertEqual($e->Entity[1]->state(), Doctrine_Record::STATE_TDIRTY);
$count = count($this->conn);
$e->save();
$this->assertEqual($count + 13, $this->conn->count());
}
示例7: save
public function save(Entity $entity)
{
$users = $this->db->get_all('users');
foreach ($users['data'] as $key => $value) {
$this->db->insert($this->table, array('msg' => $entity->getMessage(), 'is_read' => 0, 'user_id' => $value['id'], 'sender_id' => $this->user_id, 'recepient_id' => $value['id'], 'date_added' => $entity->getDate()));
}
}
示例8: generateNoSuchModelException
private function generateNoSuchModelException(Entity $entity)
{
$className = "NoSuch{$entity->getName()}Exception";
$content = "<?php\nclass {$className} extends Exception {\n\n}\n?>";
$destination = "src/exceptions/{$className}.php";
FileUtil::storeFileContents($destination, $content);
}
示例9: onEntitySave
public function onEntitySave(Entity $entity)
{
//save to entity name only if doesn't exist
if (!$entity->rawGet('name')) {
$entity->setEntityField('name', $this->getFullName(false));
}
}
示例10: compareFkDependency
/**
* Compares two entities A and B. If A contains a foreign key referring to B, then A > B. So when sorting a list of
* entities this way, the entities will be sorted in creation order. (In this case B < A, because B must be created
* before A.)
*
* @param Entity $entityA
* @param Entity $entityB
* @return int compare
*/
public static function compareFkDependency(Entity $entityA, Entity $entityB)
{
if ($entityA == $entityB) {
return 0;
}
// Check if A has a foreign key that (directly or indirectly) refers to B.
$levelAtoB = $entityA->contaisFkReferringTo($entityB);
// Check if B has a foreign key that (directly or indirectly) refers to A.
$levelBtoA = $entityB->contaisFkReferringTo($entityA);
if ($levelAtoB < 0) {
// A does not contain a reference to B.
if ($levelBtoA < 0) {
// B does not contain a reference to A either, so A and B are not related.
return 0;
} else {
// B contains a reference to A, so B < A.
return -1;
}
} else {
// A contains a reference to B...
if ($levelBtoA < 0) {
// ...and B does not contain a reference to A, so A < B.
return 1;
} else {
// ...and B contains a reference to A too. The strongest wins!
return $levelAtoB < $levelBtoA ? 1 : -1;
}
}
}
示例11: process
public static function process(Entity $entity, $maxDepth = 10)
{
if ($maxDepth <= 0) {
$mapper = $entity->_getMapper();
$primaryKey = $mapper->getPrimaryKey($mapper->getTable(get_class($entity)));
return isset($primaryKey) && isset($entity->{$primaryKey}) ? $entity->{$primaryKey} : null;
}
$data = [];
foreach ($entity->getData() as $name => $value) {
if (is_array($value)) {
$items = [];
foreach ($value as $item) {
$items[] = self::process($item, $maxDepth - 1);
}
$value = $items;
} elseif (is_object($value) && !is_null($value)) {
if ($value instanceof \DateTime) {
$value = $value->format('Y-m-d H:i:s');
} elseif ($value instanceof Entity) {
$value = self::process($value, $maxDepth - 1);
}
}
$data[$name] = $value;
}
return $data;
}
示例12: processRow
public function processRow($row)
{
$arr = str_getcsv($row);
$ticker = $arr[0];
$name = $arr[1];
$name = str_replace(''', "'", $name);
if ($name == 'Name') {
return false;
}
$cap = $arr[3];
if ($cap < $this->min_market_cap) {
$this->too_small_ct++;
return false;
} else {
$corp = Doctrine::getTable('PublicCompany')->findOneByTicker($ticker);
if ($corp) {
$this->existing_ct++;
return false;
} else {
$corp = new Entity();
$corp->addExtension('Org');
$corp->addExtension('Business');
$corp->addExtension('PublicCompany');
$corp->ticker = $ticker;
$corp->name = $name;
$corp->save();
$this->printDebug("New company added: " . $name);
$this->added_ct++;
}
}
}
示例13: swap
/**
* Swaps field values of two objects
*
* @param Entity $object1
* @param Entity $object2
* @param string $field name of the field to be swapped
*/
public function swap(Entity $object1, Entity $object2, $field)
{
$old_field = $object1[$field];
$object1[$field] = $object2[$field];
$object2[$field] = $old_field;
$object1->store();
$object2->store();
}
示例14: update
/**
* @param \PHPSC\Conference\Infra\Persistence\Entity $obj
*/
public function update(Entity $obj)
{
if ($obj->getId() == 0) {
throw new EntityDoesNotExistsException('Não é possível atualizar uma entidade que ainda não foi adicionada');
}
$this->getEntityManager()->persist($obj);
$this->getEntityManager()->flush();
}
示例15: generateIndexes
private function generateIndexes(Entity $entity)
{
$indexes = array("\tPRIMARY KEY (`{$entity->getPrimaryKey()->getName()}`)");
foreach ($entity->getFinders() as $finder) {
$indexes[] = "\t" . $finder->getIndexDefinition();
}
return $indexes;
}