Example #1
0
 public function testDelete()
 {
     $person = new Person();
     $person->setPersonKindID(1);
     $person->setUsername("timmy");
     $person->setName("Timothy");
     $person->setPhone("000-101-1010");
     $person->save();
     $this->assertTrue(Person::personExists($person->getUsername()) != false);
     $person->delete();
     $this->assertTrue(!Person::personExists($person->getUsername()));
 }
Example #2
0
 /**
  * @param SimpleXMLElement $xml
  * @return Person
  * @throws InvalidGPXException
  */
 public static function fromXML(SimpleXMLElement $xml)
 {
     $person = new Person();
     if (!empty($xml->name)) {
         $person->setName((string) $xml->name[0]);
     }
     if (!empty($xml->email)) {
         $person->setEmail(Email::fromXML($xml->email[0]));
     }
     if (!empty($xml->link)) {
         $person->setLink(Link::fromXML($xml->link[0]));
     }
     return $person;
 }
 function testCreate_OneToOne()
 {
     $this->_createModelAndIncludeThem('social_security', 'SocialSecurity');
     $this->_createModelAndIncludeThem('person', 'Person');
     $ss = new SocialSecurity();
     $ss->setCode($ss_code = 42);
     $ss->save();
     $person = new Person();
     $person->setName($person_name = 'Vasya');
     $person->setSocialSecurity($ss);
     $person->save();
     $loaded_ss = lmbActiveRecord::findById('SocialSecurity', $ss->getId());
     $this->assertEqual($loaded_ss->getCode(), $ss_code);
     $this->assertEqual($loaded_ss->getPerson()->getId(), $person->getId());
     $loaded_person = lmbActiveRecord::findById('Person', $person->getId());
     $this->assertEqual($loaded_person->getSocialSecurity()->getId(), $ss->getId());
 }
 public function save_register()
 {
     $newPerson = new Person();
     $toRepository = new Administration();
     $newPerson->setTitle(Input::get('userTitle'));
     $newPerson->setName(Input::get('txtName'));
     $newPerson->setSurname(Input::get('txtSurName'));
     $newPerson->setPosition_ID(Input::get('userPosition'));
     $newPerson->setBirthday(Input::get('txtBirthday'));
     $newPerson->setNational_ID(Input::get('txtIdent'));
     $newPerson->setType_ID(Input::get('userType'));
     $newPerson->setDepartment_ID(Input::get('userDepart'));
     $newPerson->setDivision_ID(Input::get('userDivision'));
     $newPerson->setEmail(Input::get('txtEmail'));
     $newPerson->setTelphone(Input::get('txtTel'));
     $returnValue = $toRepository->addPerson($newPerson);
     if ($returnValue == 1) {
         return View::make('alert/person/alertRegister');
     } else {
         return View::make('alert/person/alertRegister2');
     }
 }
Example #5
0
 public function testJsonSerialize()
 {
     $commit = new Person();
     $commit->setName('Name');
     $this->assertInternalType('array', $commit->jsonSerialize());
 }
<?php

// load all classes we need
require 'NameInterface.php';
require 'AbstractAge.php';
require 'Person.php';
require 'Employee.php';
require 'Animal.php';
require 'Application.php';
// thanks to the abstract class, Person has setAge method enforced
$person = new Person();
$person->setAge(10);
$person->setName("Gary Tong");
// thanks to inheritance, Employee has the Person methods available
$employee = new Employee();
$employee->setAge(30);
$employee->setName("Gary Tong");
// thanks to an interface, Animal has the setName method enforced
$animal = new Animal();
$animal->setName("Snofu Tong");
$app = new Application($person);
echo $app::VERSION;
// get the class constant
$app->run();
Example #7
0
<?php

require_once 'Person.php';
session_start();
$p = new Person();
if ($_POST) {
    $p->setName($_POST['name']);
    $p->setAge($_POST['age']);
    $_SESSION['person'] = $p;
    header('Location:page2.php');
}
//if (isset($_POST['name'])) {
//    $_SESSION['name'] = $_POST['name'];
//    header('Location:page2.php');
//}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<form action="" method="post">
    <label for="name">Name</label>
    <input type="text" name="name" id="name">

    <label for="age">Age</label>
    <input type="text" name="age" id="age">
Example #8
0
 public static function addCommit($sCommit, $sAuthor)
 {
     // Get author info seperated first
     // Bradley T. Hughes <*****@*****.**>
     $aAuthorBits = array();
     if (!preg_match("/(.+) \\<(.+)(?:@| at )([^. ]*)[ .]?.*\\>/", $sAuthor, $aAuthorBits)) {
         die("couldn't get author info for author " . $sAuthor . "\n");
     }
     // matches are:
     // string 0
     // real name 1
     // email (from bit) 2
     // email (domain bit, first word only to avoid TLD madness) 3
     //
     // first, try find the Organisation this Person belongs to
     $oOrganisation = self::findOrganisation($aAuthorBits[3]);
     if (!$oOrganisation) {
         // create one
         $oOrganisation = new Organisation();
         $oOrganisation->setName($aAuthorBits[3]);
         // add under both name and email thingy
         self::$aOrganisations[strtolower($aAuthorBits[3])] = $oOrganisation;
     }
     // let's try find a Person
     $oPerson = self::findPerson($aAuthorBits[1]);
     if (!$oPerson) {
         // try again
         $oPerson = self::findPerson($aAuthorBits[2]);
     }
     if (!$oPerson) {
         // Person record doesn't exist, let's create one
         $oPerson = new Person();
         $oPerson->setName($aAuthorBits[1]);
         $oPerson->setEmail($sAuthor);
         // add under both name and email thingy
         self::$aPersons[strtolower($aAuthorBits[1])] = $oPerson;
         self::$aPersons[strtolower($aAuthorBits[2])] = $oPerson;
     }
     // always set their organisation, as people may move from one org to
     // another and keep contributing.
     $oPerson->setOrganisation($oOrganisation);
     // simple bookkeeping first
     $oPerson->setCommitCount($oPerson->commitCount() + 1);
     $oPerson->organisation()->setCommitCount($oPerson->organisation()->commitCount() + 1);
     $oPerson->appendToCommitQueue($sCommit);
 }
$s->load(true);
$courses = $s->getCourses();
foreach ($courses as $c) {
    echo $c->getDescription() . "\n";
}
$c = new Course();
$c->setId(1);
$c->load();
echo $c->getDescription() . "\n";
$students = $c->getStudents();
foreach ($students as $s) {
    echo $s->getName() . "\n";
}
//SEARCH
$p = new Person();
$p->setName('Mat');
$search = $p->search();
$search->orderBy('name');
$list = $search->execute();
foreach ($list as $p) {
    echo $p->getName() . "\n";
}
//Recursive Search
$c = new City();
$c->setName('San');
$p = new Person();
$p->setCity($c);
$b = new Book();
$b->setAuthor($p);
$list = $b->search()->execute();
foreach ($list as $b) {
Example #10
0
 public function assignPageContent(\phpQueryObject $_)
 {
     $this->setSynopsis(trim($_['p[itemprop=description]']->text()));
     if ($duration = $_['[itemprop=duration]']->attr('datetime')) {
         $this->setLength(new \DateInterval($duration));
     }
     $this->setRating((double) $_['[itemprop=ratingValue]']->text());
     $this->setTitle(trim($_['h1 [itemprop=name]']->text()));
     $this->setVotes((int) preg_replace('/[^\\d]+/', '', $_['[itemprop=ratingCount]']->text()));
     $this->setPosterUri($_['img[itemprop=image]']->attr('src'));
     $this->setDatePublished(\DateTime::createFromFormat('Y-m-d', $_['.infobar [itemprop="datePublished"]']->attr('content')));
     $g = [];
     foreach ($_['.infobar [itemprop=genre]'] as $genre) {
         $g[] = pq($genre)->text();
     }
     $this->setGenres($g);
     foreach ($_['#title-overview-widget [itemtype="http://schema.org/Person"][itemprop!=actors]'] as $x) {
         $x = pq($x);
         foreach ($x['a[itemprop=url]'] as $p) {
             $p = pq($p);
             $person = new Person();
             $person->setId(preg_replace('@^.*(nm\\d+).*@', '$1', $p->attr('href')));
             $person->setName($p->text());
             if (!isset($this->_people[$x->attr('itemprop')])) {
                 $this->_people[$x->attr('itemprop')] = [];
             }
             $this->_people[$x->attr('itemprop')][$person->getId()] = $person;
         }
     }
     // Casting
     if (!isset($this->_people['actors'])) {
         $this->_people['actors'] = [];
     }
     foreach ($_['table.cast_list tr:has([itemprop=name])'] as $p) {
         $p = pq($p);
         $actor = new Actor();
         $actor->setId(preg_replace('@^.*(nm\\d+).*@', '$1', $p['[itemprop=url]']->attr('href')));
         $actor->setName($p['[itemprop=name]']->text());
         $actor->setCharacter($p['a[href^=/character]']->text());
         $this->_people['actors'][$actor->getId()] = $actor;
     }
 }
Example #11
0
 echo "## Loading\n";
 $p = new Person();
 $p->setId($id);
 $db->load($p);
 $p->prettyPrint();
 echo "## Updating\n";
 $p->setColor('red');
 $db->update($p);
 $p->prettyPrint();
 echo "## Loading Multiple\n";
 $p2 = new Person();
 $p2->setName('Bob');
 $p2->setColor('red');
 $db->insert($p2);
 $p3 = new Person();
 $p3->setName('John');
 $p3->setColor('purple');
 $db->insert($p3);
 $people = $db->loadMulti(new Person(), " color='red' ");
 foreach ($people as $person) {
     $person->prettyPrint();
 }
 echo "## Updating Multiple\n";
 $p = new Person();
 $p->setColor('blue');
 $db->updateMulti($p, " color='red' ");
 $people = $db->loadMulti(new Person());
 foreach ($people as $person) {
     $person->prettyPrint();
 }
 echo "### Deleting purple\n";
 private function setUpPerson()
 {
     $person = new Person();
     $person->setPersonKindID(getPersonKindID($this->request['personKind']));
     $person->setUsername($this->request['username']);
     $person->setName($this->request['name']);
     $person->setPhone($this->request['phone']);
     $person->save();
     return $person->getID();
 }
Example #13
0
<?php

include __DIR__ . '/../autoload.php';
class Person
{
    protected $name;
    public function getName()
    {
        return $this->name;
    }
    public function setName($name)
    {
        $this->name = $name;
    }
}
$person = new Person();
$person->setName('Jack');
$form = new Gregwar\Formidable\Form('<form method="post">
    <input type="text" name="name" mapping="name" />
    </form>');
$form->setData($person);
echo $form;
/*
Will output something like:

<form method="post">
    <input required="required" type="text" name="name" value="Jack" />
    <input type="hidden" name="csrf_token" value="aa27f437cc6127c244db14361fd614af51c79aac" />
</form>
*/
Example #14
0
/**
 * Loads the people that are currently in the people table in our database.
 *
 * @return {HashMap.<String, Person>} The hash table with the people, where
 *     the key is the name of each person (lower case, no diacritics, all
 *     names sorted alphabetically).
 */
function loadPeopleFromDb()
{
    $results = array();
    $s = mysql_query("SELECT * FROM people");
    while ($r = mysql_fetch_array($s)) {
        $person = new Person();
        $person->setName($r['name']);
        $person->setDisplayName($r['display_name']);
        $person->setId($r['id']);
        $results[$person->name] = $person;
    }
    return $results;
}
Example #15
0
 /**
  * Utility function for adding a person to this show. A new person
  * record is created if they don't already exist.
  *
  * @param Show $show This show.
  * @param string $role_type The type of role ('cast', 'band', 'prod')
  * @param string $role_name Director, Producer, Macbeth..
  * @param string $person_name The person's name
  */
 private function addRoleToShow(Show $show, $role_type, $role_name, $person_name)
 {
     $role = new Role();
     $role->setType($role_type);
     $role->setRole($role_name);
     $em = $this->getDoctrine()->getManager();
     $person_repo = $em->getRepository('ActsCamdramBundle:Person');
     /* Try and find the person. Add a new person if they don't exist. */
     $person = $person_repo->findCanonicalPerson($person_name);
     if ($person == null) {
         $person = new Person();
         $person->setName($person_name);
         $slug = Sluggable\Urlizer::urlize($person_name, '-');
         $person->setSlug($slug);
         $em->persist($person);
     }
     $role->setPerson($person);
     /* Append this role to the list of roles of this type. */
     $order = $this->getDoctrine()->getRepository('ActsCamdramBundle:Role')->getMaxOrderByShowType($show, $role->getType());
     $role->setOrder(++$order);
     $role->setShow($show);
     $em->persist($role);
     $person->addRole($role);
     $show->addRole($role);
     $em->flush();
 }
Example #16
0
 /**
  * Tests Person->setName()
  */
 public function testSetName()
 {
     $this->Person->setName('name');
     $this->assertEquals('name', $this->Person->name);
 }
Example #17
0
File: 1.php Project: ruyicoder/php
    {
        echo "领带 ";
        parent::show();
    }
}
class leatherShoe extends Finery
{
    public function show()
    {
        echo "皮鞋 ";
        parent::show();
    }
}
//客户端代码
$xc = new Person();
$xc->setName('小菜');
var_dump('第一种装装扮');
$dtx = new Tshirt();
//大T恤
$kk = new BigTrouser();
//跨裤
$pqx = new Sneaker();
//破球鞋
$dtx->decorator($xc);
$kk->decorator($dtx);
$pqx->decorator($kk);
$pqx->show();
var_dump("第二中装饰");
$ld = new tie();
//领带
$xz = new Suit();
 public function testFindFriendsOf()
 {
     $john = new Person();
     $john->setName('john');
     $john->save();
     $jean = new Person();
     $jean->setName('jean');
     $jean->save();
     $phil = new Person();
     $phil->setName('phil');
     $phil->save();
     $this->assertEquals(0, PersonQuery::create()->findFriendsOf($phil)->count());
     $this->assertEquals(0, PersonQuery::create()->findFriendsOf($jean)->count());
     $this->assertEquals(0, PersonQuery::create()->findFriendsOf($john)->count());
     $jean->addFriend($phil);
     $this->assertEquals(0, PersonQuery::create()->findFriendsOf($phil)->count());
     $this->assertEquals(0, PersonQuery::create()->findFriendsOf($jean)->count());
     $jean->save();
     $this->assertEquals(1, PersonQuery::create()->findFriendsOf($phil)->count());
     $this->assertEquals(1, PersonQuery::create()->findFriendsOf($jean)->count());
     $coll = PersonQuery::create()->findFriendsOf($phil);
     $this->assertInstanceOf('PropelObjectCollection', $coll);
     $this->assertInstanceOf('Person', $coll[0]);
     $this->assertEquals('jean', $coll[0]->getName());
     $coll = PersonQuery::create()->findFriendsOf($jean);
     $this->assertInstanceOf('PropelObjectCollection', $coll);
     $this->assertInstanceOf('Person', $coll[0]);
     $this->assertEquals('phil', $coll[0]->getName());
     $jean->removeFriends();
     $jean->save();
     $this->assertEquals(0, FriendQuery::create()->count());
     $this->assertEquals(0, PersonQuery::create()->findFriendsOf($phil)->count());
     $this->assertEquals(0, PersonQuery::create()->findFriendsOf($jean)->count());
 }
Example #19
0
     die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
 } else {
     SmartTest::instance()->progress();
 }
 if (!RedBean_OODB::registerSearch("cheese") && count(RedBean_DBAdapter::getLogs()) < 1) {
     die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
 } else {
     SmartTest::instance()->progress();
 }
 //test convenient tree functions
 SmartTest::instance()->canwe = "convient tree functions";
 if (!class_exists("Person")) {
     RedBean_OODB::gen("person");
 }
 $donald = new Person();
 $donald->setName("Donald");
 $donald->save();
 $kwik = new Person();
 $kwik->setName("Kwik");
 $kwik->save();
 $kwek = new Person();
 $kwek->setName("Kwek");
 $kwek->save();
 $kwak = new Person();
 $kwak->setName("Kwak");
 $kwak->save();
 $donald->attach($kwik);
 $donald->attach($kwek);
 $donald->attach($kwak);
 if (count($donald->children()) != 3) {
     die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
Example #20
0
 public static function getPersons()
 {
     $dados = Database::ReadAll("person", "*");
     if (!$dados) {
         return '';
     }
     foreach ($dados as $dado) {
         $person = new Person();
         $person->setId($dado['ID_PERSON']);
         $person->setName($dado['NAME_PERSON']);
         $person->setEmail($dado['EMAIL']);
         $person->setAge($dado['AGE']);
         $person->setSex($dado['SEX']);
         $person->setPhone($dado['PHONE']);
         $person->setOperator($dado['OPERATOR']);
         $person->setMaritalStatus($dado['MARITAL_STATUS']);
         $person->setChildren($dado['CHILDREN']);
         $religion = Religion::getReligion("WHERE id_religion = " . $dado['ID_RELIGION']);
         $person->setReligion($religion);
         $address = Address::getAddress("AND id_address = " . $dado['ID_ADDRESS']);
         $person->setAddress($address);
         $login = Login::getLogin($dado['ID_PERSON']);
         $person->setLogin($login);
         $persons[] = $person;
     }
     return $persons;
 }
  leftJoin('Article')->with('Article');
$comments = $finder->find();
$latestQuery = $finder->getLatestQuery();
$t->is($comments[0]->getAuthor(), null, 'First object has no author');
$t->is(Propel::getConnection()->getLastExecutedQuery(), $latestQuery, 'Related hydration occurred correctly');
$t->isnt($comments[0]->getArticle(), null, 'First object has an article');
$t->is(Propel::getConnection()->getLastExecutedQuery(), $latestQuery, 'Related hydration occurred correctly');
$t->isnt($comments[1]->getAuthor(), null, 'Second object has an author');
$t->is(Propel::getConnection()->getLastExecutedQuery(), $latestQuery, 'Related hydration occurred correctly');
$t->isnt($comments[1]->getArticle(), null, 'Second object has an article');
$t->is(Propel::getConnection()->getLastExecutedQuery(), $latestQuery, 'Related hydration occurred correctly');

$t->diag('sfPropelFinder::with() and exotic phpNames');

CivilityPeer::doDeleteAll();
HumanPeer::doDeleteAll();
$civility1 = new Civility();
$civility1->setIsMan(true);
$civility1->save();
$person1 = new Person();
$person1->setName('John');
$person1->setCivility($civility1);
$person1->save();

$finder = sfPropelFinder::from('Person')->
  with('Civility');
$person = $finder->findOne();
$latestQuery = $finder->getLatestQuery();
$t->is($person->getCivility()->getIsMan(), true, 'Related Objects with a non-natural phpName get hydrated correctly');
$t->is(Propel::getConnection()->getLastExecutedQuery(), $latestQuery, 'Related hydration occurred correctly');
<?php

class Person
{
    protected $name;
    protected $age;
    public function setName($name)
    {
        $this->name = $name;
        return $this;
    }
    public function setAge($age)
    {
        $this->age = $age;
        return $this;
    }
    public function __toString()
    {
        return "Hello, my name is " . $this->name . " and I am " . $this->age . " years old.";
    }
}
$person = new Person();
// Doesn't matter if I'm using new Person; or new Person();
//
echo $person->setName("Peter")->setAge(21);
// echo on object automatically calls magic method __toString()
echo PHP_EOL;
echo $person;
// printing the Object, it will call the macic method too!
echo PHP_EOL;
Example #23
0
function testsperengine()
{
    global $tests;
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "perform generic bean manipulation";
    $ok = 1;
    $bean = RedBean_OODB::dispense("note");
    $bean->message = "hai";
    $bean->color = 3;
    $bean->date = time();
    $bean->special = 'n';
    $bean->state = 90;
    RedBean_OODB::set($bean);
    $bean2 = RedBean_OODB::getById("note", 1);
    if ($bean2->state != 90 || $bean2->special != 'n' || $bean2->message != 'hai') {
        $ok = 0;
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    $bean->message = "lorem ipsum";
    RedBean_OODB::set($bean);
    $bean->message = 1;
    $bean->color = "green";
    $bean->date = str_repeat("BLABLA", 100);
    RedBean_OODB::set($bean);
    $note = $bean;
    SmartTest::instance()->progress();
    $person = RedBean_OODB::dispense("person");
    $person->age = 50;
    $person->name = "Bob";
    $person->gender = "m";
    RedBean_OODB::set($person);
    RedBean_OODB::associate($person, $note);
    $memo = RedBean_OODB::getById("note", 1);
    $authors = RedBean_OODB::getAssoc($memo, "person");
    if (count($authors) !== 1) {
        SmartTest::failedTest();
    }
    RedBean_OODB::trash($authors[1]);
    $authors = RedBean_OODB::getAssoc($memo, "person");
    if (count($authors) > 0) {
        $ok = 0;
    }
    if (!$ok) {
        SmartTest::failedTest();
    }
    //unit tests
    //drop the note table
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "dispense an RedBean_OODB Bean";
    $oBean = RedBean_OODB::dispense();
    if (!$oBean instanceof OODBBean) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "put a bean in the database";
    $person = RedBean_OODB::dispense("person");
    $person->name = "John";
    $person->age = 35;
    $person->gender = "m";
    $person->hasJob = true;
    $id = RedBean_OODB::set($person);
    $johnid = $id;
    $person2 = RedBean_OODB::getById("person", $id);
    if ($person2->age != $person->age) {
        SmartTest::failedTest();
    }
    $person2->anotherprop = 2;
    RedBean_OODB::set($person2);
    $person = RedBean_OODB::dispense("person");
    $person->name = "Bob";
    $person->age = 50;
    $person->gender = "m";
    $person->hasJob = false;
    $bobid = RedBean_OODB::set($person);
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "find records on basis of similarity";
    $ids = RedBean_OODB::getBySQL("`gender`={gender} order by `name` asc", array("gender" => "m"), "person");
    if (count($ids) != 2) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    $ids = RedBean_OODB::getBySQL("`gender`={gender} OR `color`={clr} ", array("gender" => "m", "clr" => "red"), "person");
    if (count($ids) != 0) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    $ids = RedBean_OODB::getBySQL("`gender`={gender} AND `color`={clr} ", array("gender" => "m", "clr" => "red"), "person");
    if (count($ids) != 0) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    R::gen("Person");
    $dummy = new Person();
    $dummy->age = 40;
    SmartTest::instance()->test(count(Person::find($dummy, array("age" => ">"))), 1);
    $dummy->age = 20;
    SmartTest::instance()->test(count(Person::find($dummy, array("age" => ">"))), 2);
    $dummy->age = 100;
    SmartTest::instance()->test(count(Person::find($dummy, array("age" => ">"))), 0);
    $dummy->age = 100;
    SmartTest::instance()->test(count(Person::find($dummy, array("age" => "<="))), 2);
    $dummy->name = "ob";
    SmartTest::instance()->test(count(Person::find($dummy, array("name" => "LIKE"))), 1);
    $dummy->name = "o";
    SmartTest::instance()->test(count(Person::find($dummy, array("name" => "LIKE"))), 2);
    $dummy->gender = "m";
    SmartTest::instance()->test(count(Person::find($dummy, array("gender" => "="))), 2);
    $dummy->gender = "f";
    SmartTest::instance()->test(count(Person::find($dummy, array("gender" => "="))), 0);
    SmartTest::instance()->test(count(Person::listAll()), 2);
    SmartTest::instance()->test(count(Person::listAll(0, 1)), 1);
    SmartTest::instance()->test(count(Person::listAll(1)), 1);
    $can = Person::where("`gender`={gender} order by `name`  asc", array("gender" => "m"), "person");
    //test array access
    foreach ($can as $item) {
        if ($item->getName() == "Bob" || $item->getName() == "John") {
            SmartTest::instance()->progress();
        } else {
            SmartTest::failedTest();
        }
    }
    //test array access
    $bean = $can[0];
    if ($bean->name == "Bob") {
        SmartTest::instance()->progress();
    } else {
        SmartTest::failedTest();
    }
    if ($can->count() != 2) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    $can->rewind();
    SmartTest::instance()->test($can->key(), 0);
    SmartTest::instance()->test($can->valid(), true);
    SmartTest::instance()->test($can->current()->getName(), "Bob");
    $can->next();
    SmartTest::instance()->test($can->key(), 1);
    SmartTest::instance()->test($can->valid(), false);
    SmartTest::instance()->test($can->current()->getName(), "John");
    $can->seek(0);
    SmartTest::instance()->test($can->key(), 0);
    $beans = $can->getBeans();
    if (count($beans) != 2) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    //test slicing
    $can->slice(0, 1);
    $can->rewind();
    SmartTest::instance()->test($can->current()->getName(), "Bob");
    SmartTest::instance()->test($can->count(), 1);
    $b1 = array_shift($beans);
    if ($b1->name != "Bob") {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    //basic functionality where()
    $beans = Person::where("`gender`={gender} order by `name` asc", array("gender" => "m"), "person")->getBeans();
    if (count($beans) != 2) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    //without backticks should still work
    $beans = Person::where("gender={person} order by `name` asc", array("person" => "m"), "person")->getBeans();
    if (count($beans) != 2) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    //like comparing should still work
    $beans = Person::where("gender={gender} and `name` LIKE {name} order by `name` asc", array("gender" => "m", "name" => "B%"), "person")->getBeans();
    if (count($beans) != 1) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    $searchBean = RedBean_OODB::dispense("person");
    $searchBean->gender = "m";
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "associate beans with eachother?";
    $app = RedBean_OODB::dispense("appointment");
    $app->kind = "dentist";
    RedBean_OODB::set($app);
    RedBean_OODB::associate($person2, $app);
    $appforbob = array_shift(RedBean_OODB::getAssoc($person2, "appointment"));
    if (!$appforbob || $appforbob->kind != "dentist") {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "delete a bean?";
    $person = RedBean_OODB::getById("person", $bobid);
    RedBean_OODB::trash($person);
    try {
        $person = RedBean_OODB::getById("person", $bobid);
        $ok = 0;
    } catch (ExceptionFailedAccessBean $e) {
        $ok = true;
    }
    if (!$ok) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "unassociate two beans?";
    $john = RedBean_OODB::getById("person", $johnid);
    //hmmmmmm gaat mis bij innodb
    $app = RedBean_OODB::getById("appointment", 1);
    RedBean_OODB::unassociate($john, $app);
    $john2 = RedBean_OODB::getById("person", $johnid);
    $appsforjohn = RedBean_OODB::getAssoc($john2, "appointment");
    if (count($appsforjohn) > 0) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "unassociate by deleting a bean?";
    $anotherdrink = RedBean_OODB::dispense("whisky");
    $anotherdrink->name = "bowmore";
    $anotherdrink->age = 18;
    $anotherdrink->singlemalt = 'y';
    RedBean_OODB::set($anotherdrink);
    RedBean_OODB::associate($anotherdrink, $john);
    $hisdrinks = RedBean_OODB::getAssoc($john, "whisky");
    if (count($hisdrinks) !== 1) {
        SmartTest::failedTest();
    }
    RedBean_OODB::trash($anotherdrink);
    $hisdrinks = RedBean_OODB::getAssoc($john, "whisky");
    if (count($hisdrinks) !== 0) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "create parent child relationships?";
    $pete = RedBean_OODB::dispense("person");
    $pete->age = 48;
    $pete->gender = "m";
    $pete->name = "Pete";
    $peteid = RedBean_OODB::set($pete);
    $rob = RedBean_OODB::dispense("person");
    $rob->age = 19;
    $rob->name = "Rob";
    $rob->gender = "m";
    $saskia = RedBean_OODB::dispense("person");
    $saskia->age = 20;
    $saskia->name = "Saskia";
    $saskia->gender = "f";
    RedBean_OODB::set($saskia);
    RedBean_OODB::set($rob);
    RedBean_OODB::addChild($pete, $rob);
    RedBean_OODB::addChild($pete, $saskia);
    $children = RedBean_OODB::getChildren($pete);
    $names = 0;
    if (is_array($children) && count($children) === 2) {
        foreach ($children as $child) {
            if ($child->name === "Rob") {
                $names++;
            }
            if ($child->name === "Saskia") {
                $names++;
            }
        }
    }
    if (!$names) {
        SmartTest::failedTest();
    }
    $daddies = RedBean_OODB::getParent($saskia);
    $daddy = array_pop($daddies);
    if ($daddy->name === "Pete") {
        $ok = 1;
    } else {
        $ok = 0;
    }
    if (!$ok) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "remove a child from a parent-child tree?";
    RedBean_OODB::removeChild($daddy, $saskia);
    $children = RedBean_OODB::getChildren($pete);
    $ok = 0;
    if (count($children) === 1) {
        $only = array_pop($children);
        if ($only->name === "Rob") {
            $ok = 1;
        }
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "save on the fly while associating?";
    $food = RedBean_OODB::dispense("dish");
    $food->name = "pizza";
    RedBean_OODB::associate($food, $pete);
    $petesfood = RedBean_OODB::getAssoc($pete, "food");
    if (is_array($petesfood) && count($petesfood) === 1) {
        $ok = 1;
    }
    if (!$ok) {
        SmartTest::failedTest();
    }
    //some extra tests... quick without further notice.
    $food = RedBean_OODB::dispense("dish");
    $food->name = "spaghetti";
    RedBean_OODB::trash($food);
    //test aggregation functions
    //insert stat table
    $s = RedBean_OODB::dispense("stattest");
    $s->amount = 1;
    RedBean_OODB::set($s);
    $s = RedBean_OODB::dispense("stattest");
    $s->amount = 2;
    RedBean_OODB::set($s);
    $s = RedBean_OODB::dispense("stattest");
    $s->amount = 3;
    RedBean_OODB::set($s);
    SmartTest::instance()->testPack = "can we use aggr functions using Redbean?";
    if (RedBean_OODB::numberof("stattest") != 3) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if (RedBean_OODB::maxof("stattest", "amount") != 3) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if (RedBean_OODB::minof("stattest", "amount") != 1) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if (RedBean_OODB::avgof("stattest", "amount") != 2) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if (RedBean_OODB::sumof("stattest", "amount") != 6) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if (count(RedBean_OODB::distinct("stattest", "amount")) != 3) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    RedBean_OODB::setLocking(true);
    $i = 3;
    SmartTest::instance()->testPack = "generate only valid classes?";
    try {
        $i += RedBean_OODB::gen("");
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        SmartTest::failedTest();
    }
    //nothing
    try {
        $i += RedBean_OODB::gen(".");
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        SmartTest::failedTest();
    }
    //illegal chars
    try {
        $i += RedBean_OODB::gen(",");
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        SmartTest::failedTest();
    }
    //illegal chars
    try {
        $i += RedBean_OODB::gen("null");
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        SmartTest::failedTest();
    }
    //keywords
    try {
        $i += RedBean_OODB::gen("Exception");
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        SmartTest::failedTest();
    }
    //reserved
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "generate classes using Redbean?";
    if (!class_exists("Bug")) {
        $i += RedBean_OODB::gen("Bug");
        if ($i !== 4) {
            SmartTest::failedTest();
        }
    } else {
        if ($i !== 3) {
            SmartTest::failedTest();
        }
    }
    if (!class_exists("Bug")) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "use getters and setters";
    $bug = new Bug();
    $bug->setSomething(sha1("abc"));
    if ($bug->getSomething() != sha1("abc")) {
        SmartTest::failedTest();
    }
    //can we use non existing props? --triggers fatal..
    $bug->getHappy();
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "Use boolean values and retrieve them with is()?";
    if ($bug->isHappy()) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    $bug->setHappy(true);
    $bug->save();
    $bug = new Bug(1);
    if (!$bug->isHappy()) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    $bug->setHappy(false);
    if ($bug->isHappy()) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "avoid race-conditions by locking?";
    RedBean_OODB::gen("Cheese,Wine");
    $cheese = new Cheese();
    $cheese->setName('Brie');
    $cheese->save();
    $cheese = new Cheese(1);
    //try to mess with the locking system...
    $oldkey = RedBean_OODB::$pkey;
    RedBean_OODB::$pkey = 1234;
    $cheese = new Cheese(1);
    $cheese->setName("Camembert");
    $ok = 0;
    try {
        $cheese->save();
    } catch (ExceptionFailedAccessBean $e) {
        $ok = 1;
    }
    if (!$ok) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    $bordeaux = new Wine();
    $bordeaux->setRegion("Bordeaux");
    try {
        $bordeaux->add($cheese);
    } catch (ExceptionFailedAccessBean $e) {
        $ok = 1;
    }
    if (!$ok) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    try {
        $bordeaux->attach($cheese);
    } catch (ExceptionFailedAccessBean $e) {
        $ok = 1;
    }
    if (!$ok) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    try {
        $bordeaux->add(new Wine());
        $ok = 1;
    } catch (ExceptionFailedAccessBean $e) {
        $ok = 0;
    }
    if (!$ok) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    RedBean_OODB::$pkey = $oldkey;
    $cheese = new Cheese(1);
    $cheese->setName("Camembert");
    $ok = 0;
    try {
        $cheese->save();
        $ok = 1;
    } catch (ExceptionFailedAccessBean $e) {
        $ok = 0;
    }
    if (!$ok) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    try {
        RedBean_OODB::$pkey = 999;
        RedBean_OODB::setLockingTime(0);
        $cheese = new Cheese(1);
        $cheese->setName("Cheddar");
        $cheese->save();
        RedBean_OODB::setLockingTime(10);
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        SmartTest::failedTest();
    }
    try {
        RedBean_OODB::$pkey = 123;
        RedBean_OODB::setLockingTime(100);
        $cheese = new Cheese(1);
        $cheese->setName("Cheddar2");
        $cheese->save();
        RedBean_OODB::setLockingTime(10);
        SmartTest::failedTest();
    } catch (Exception $e) {
        SmartTest::instance()->progress();
    }
    try {
        RedBean_OODB::$pkey = 42;
        RedBean_OODB::setLockingTime(0);
        $cheese = new Cheese(1);
        $cheese->setName("Cheddar3");
        $cheese->save();
        RedBean_OODB::setLockingTime(10);
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        SmartTest::failedTest();
    }
    //test value ranges
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "protect inner state of RedBean";
    try {
        RedBean_OODB::setLockingTime(-1);
        SmartTest::failedTest();
    } catch (ExceptionInvalidArgument $e) {
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "protect inner state of RedBean";
    try {
        RedBean_OODB::setLockingTime(1.5);
        SmartTest::failedTest();
    } catch (ExceptionInvalidArgument $e) {
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "protect inner state of RedBean";
    try {
        RedBean_OODB::setLockingTime("aaa");
        SmartTest::failedTest();
    } catch (ExceptionInvalidArgument $e) {
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "protect inner state of RedBean";
    try {
        RedBean_OODB::setLockingTime(null);
        SmartTest::failedTest();
    } catch (ExceptionInvalidArgument $e) {
    }
    SmartTest::instance()->progress();
    //test convenient tree functions
    SmartTest::instance()->testPack = "convient tree functions";
    if (!class_exists("Person")) {
        RedBean_OODB::gen("person");
    }
    $donald = new Person();
    $donald->setName("Donald");
    $donald->save();
    $kwik = new Person();
    $kwik->setName("Kwik");
    $kwik->save();
    $kwek = new Person();
    $kwek->setName("Kwek");
    $kwek->save();
    $kwak = new Person();
    $kwak->setName("Kwak");
    $kwak->save();
    $donald->attach($kwik);
    $donald->attach($kwek);
    $donald->attach($kwak);
    if (count($donald->children()) != 3) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if (count($kwik->siblings()) != 2) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    //todo
    if ($kwik->hasParent($donald) != true) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if ($donald->hasParent($kwak) != false) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if ($donald->hasChild($kwak) != true) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if ($donald->hasChild($donald) != false) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if ($kwak->hasChild($kwik) != false) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if ($kwak->hasSibling($kwek) != true) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if ($kwak->hasSibling($kwak) != false) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if ($kwak->hasSibling($donald) != false) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    //copy
    SmartTest::instance()->testPack = "copy functions";
    $kwak2 = $kwak->copy();
    $id = $kwak2->save();
    $kwak2 = new Person($id);
    if ($kwak->getName() != $kwak2->getName()) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    SmartTest::instance()->testPack = "countRelated";
    R::gen("Blog,Comment");
    $blog = new Blog();
    $blog2 = new Blog();
    $blog->setTitle("blog1");
    $blog2->setTitle("blog2");
    for ($i = 0; $i < 5; $i++) {
        $comment = new Comment();
        $comment->setText("comment no.  {$i} ");
        $blog->add($comment);
    }
    for ($i = 0; $i < 3; $i++) {
        $comment = new Comment();
        $comment->setText("comment no.  {$i} ");
        $blog2->add($comment);
    }
    if ($blog->numofComment() !== 5) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if ($blog2->numofComment() !== 3) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    SmartTest::instance()->testPack = "associate tables of the same name";
    $blog = new Blog();
    $blogb = new Blog();
    $blog->title = 'blog a';
    $blogb->title = 'blog b';
    $blog->add($blogb);
    $b = $blog->getRelatedBlog();
    if (count($b) !== 1) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    $b = array_pop($b);
    if ($b->title != 'blog b') {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    SmartTest::instance()->testPack = "inferTypeII patch";
    $blog->rating = 4294967295.0;
    $blog->save();
    $id = $blog->getID();
    $blog2->rating = -1;
    $blog2->save();
    $blog = new Blog($id);
    if ($blog->getRating() != 4294967295.0) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    SmartTest::instance()->testPack = "Longtext column type";
    $blog->message = str_repeat("x", 65535);
    $blog->save();
    $blog = new Blog($id);
    if (strlen($blog->message) != 65535) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    $rows = RedBean_OODB::$db->get("describe blog");
    if ($rows[3]["Type"] != "text") {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    $blog->message = str_repeat("x", 65536);
    $blog->save();
    $blog = new Blog($id);
    if (strlen($blog->message) != 65536) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    $rows = RedBean_OODB::$db->get("describe blog");
    if ($rows[3]["Type"] != "longtext") {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    Redbean_OODB::clean();
    SmartTest::instance()->testPack = "Export";
    RedBean_OODB::gen("justabean");
    $oBean = new JustABean();
    $oBean->setA("a");
    $oOtherBean = new OODBBean();
    $oOtherBean->a = "b";
    $oBean2 = new OODBBean();
    $oBean->exportTo($oBean2);
    if ($oBean2->a !== "a") {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    $oBean2 = $oBean->exportTo($oBean2);
    if ($oBean2->a !== "a") {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    $oBean->exportTo($oBean2, $oOtherBean);
    if ($oBean2->a !== "b") {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    $arr = array();
    $oBean->exportTo($arr);
    if ($arr["a"] !== "a") {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    $arr = array();
    $arr = $oBean->exportTo($arr);
    if ($arr["a"] !== "a") {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    $arr = $oBean->exportTo($arr, $oOtherBean);
    if ($arr["a"] !== "b") {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    SmartTest::instance()->testPack = "Export Array";
    $oBean->a = "a";
    $oInnerBean = new JustABean();
    $oInnerBean->setID(123);
    $oBean->innerbean = $oInnerBean;
    $arr = $oBean->exportAsArr();
    if (!is_array($arr)) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if ($arr["innerbean"] !== 123) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if ($arr["a"] !== "a") {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    //test 1-to-n
    SmartTest::instance()->testPack = "1-to-n relations";
    R::gen("Track,Disc");
    $cd1 = new Disc();
    $cd1->name = 'first';
    $cd1->save();
    $cd2 = new Disc();
    $cd2->name = 'second';
    $cd2->save();
    $track = new Track();
    $track->title = "song 1";
    $track->belongsTo($cd1);
    $discs = $track->getRelatedDisc();
    SmartTest::instance()->test(count($discs), 1);
    $track->belongsTo($cd2);
    $discs = $track->getRelatedDisc();
    SmartTest::instance()->test(count($discs), 1);
    $track2 = new Track();
    $track2->title = "song 2";
    $cd1->exclusiveAdd($track2);
    SmartTest::instance()->test(count($track->getRelatedDisc()), 1);
    $cd2->exclusiveAdd($track2);
    SmartTest::instance()->test(count($track->getRelatedDisc()), 1);
}
Example #24
0
// Load wp-config so that we can use the fact that the user is logged in.
require_once '../wp-config.php';
include_once '../hp-includes/people_lib.php';
include_once '../hp-includes/user_utils.php';
// current_user is a variable set by Wordpress.
$uid = is_user_logged_in() ? $current_user->ID : 0;
if ($uid == 0) {
    die("You're not logged in");
}
if (getUserLevel($uid) == 0) {
    die("Not enough privileges");
}
// Sanitize the inputs a little bit.
$name = mysql_real_escape_string($_GET['name_all']);
$displayName = mysql_real_escape_string($_GET['display_name']);
$photoUrl = mysql_real_escape_string($_GET['photo_url']);
$person = new Person();
$person->setName($name);
$person->addExtraNames($displayName);
$person->setDisplayName($displayName);
$person->addToDatabaseIfNobody();
// Now also set the image URL.
if ($photoUrl != '') {
    downloadPersonPhoto($person->id, $photoUrl);
}
// Also record this in the moderation queue so we can see who added what.
$ip = $_SERVER['REMOTE_ADDR'];
$userLogin = getUserLogin($uid);
mysql_query("INSERT INTO moderation_queue(type, idperson, value, ip, time)\n   VALUES('add_person', {$person->id}, 'by {$userLogin}', '{$ip}', " . time() . ")");
echo "Persoana X a fost adăugată. " . "Vizitează-le pagina <a href=/?cid=9&id={$person->id} " . "taget=_blank>aici</a>.";
require_once '../_bottom.php';
<?php

$rasmus = new Person();
$rasmus->setName('Rasmus Lerdorf');
$rasmus->setCity('Sunnyvale');
print $rasmus->getName() . ' lives in ' . $rasmus->getCity() . '.';
Example #26
0
/**
 * createAdminPerson() Create a person-object based on the certificate
 * credentials passed via the client certificate.
 *
 * Ideally, this should be done via Confusa_Auth, however, since we do not have
 * a live Feide-session, but are basing the authetnication on an X.509
 * certificate, the case is a corner, thus we do it here.
 *
 * @return Person|NULL the decorated person or NULL if the creation failed.
 */
function createAdminPerson()
{
    global $log_error_code;
    /*
     * Try to find the certificate in the robot_certs-table. If we have a
     * match, we have a legit user and create a proxy-admin.
     *
     * If the query fails for some reason, we jumb out, returning null
     */
    $fingerprint = openssl_x509_fingerprint($_SERVER['SSL_CLIENT_CERT'], true);
    if (is_null($fingerprint)) {
        return null;
    }
    try {
        $cert_res = MDB2Wrapper::execute("SELECT * FROM robot_certs WHERE fingerprint = ?", array('text'), array(trim($fingerprint)));
    } catch (DBStatementException $dbse) {
        Logger::log_event(LOG_NOTICE, "[RI] ({$log_error_code}) (line: " . __LINE__ . ")Error with syntax for robot_certs-query.(" . $dbse->getMessage() . ")");
        return null;
    } catch (DBQueryException $dbqe) {
        Logger::log_event(LOG_NOTICE, "[RI] ({$log_error_code}) Error with params (line (" . __LINE__ . ") in robot_certs-query.(" . $dbqe->getMessage() . ")");
        return null;
    }
    switch (count($cert_res)) {
        case 0:
            Logger::log_event(LOG_NOTICE, "[RI] ({$log_error_code}): Unauthenticated client connected. Refusing to establish connection. " . $_SERVER['SSL_CLIENT_I_DN']);
            echo "[{$log_error_code}] You are not authorized to use this API. This incident has been logged.\n";
            return null;
        case 1:
            /*
             * We have to do the compare in a rather awkward way to ensure
             * that differences in spaces, newlines, tabs and whatnot are
             * removed.
             */
            openssl_x509_export(openssl_x509_read($_SERVER['SSL_CLIENT_CERT']), $stored_admin_dump);
            openssl_x509_export(openssl_x509_read($cert_res[0]['cert']), $stored_client_dump);
            if ($stored_admin_dump != $stored_client_dump) {
                Logger::log_event(LOG_NOTICE, "[RI] ({$log_error_code}) Got matching fingerprint ({$fingerprint}) " . "but actual certificates differ! Aborting");
                echo "[{$code}] There were issues with your certificate. Cannot continue using this cert.\n";
                echo "Please use another certificate for the time being.\n";
                echo "This event has been logged.\n";
                return null;
            }
            break;
        default:
            Logger::log_event(LOG_ALERT, "[RI] ({$log_error_code}) Several certs (" . count($cert_res) . ") in DB matching fingerprint ({$fingerprint}), cannot auth client.");
            return null;
    }
    /*
     * Get the details for the owner of the certificate, use this as a
     * basis for authenticating the person.
     *
     * It does not really matter which IdP-map we use, as long as we get one
     * that points to the correct NREN. This is probably not the 'correct'
     * way of using the idp_map, but atm, this is the only 'correct' way of
     * decorating the NREN-object.
     */
    try {
        /* get admin */
        $ares = MDB2Wrapper::execute("SELECT * FROM admins WHERE admin_id=?", array('text'), array($cert_res[0]['uploaded_by']));
        if (count($ares) != 1) {
            /* no admin found. This should not be possible, but be
             * safe and test nevertheless */
            return null;
        }
        /* get Subscriber */
        $sres = MDB2Wrapper::execute("SELECT * FROM subscribers WHERE subscriber_id=?", array('text'), array($cert_res[0]['subscriber_id']));
        if (count($sres) != 1) {
            /* No subscriber found */
            return null;
        }
        /* get NREN */
        $nres = MDB2Wrapper::execute("SELECT n.*,im.idp_url FROM nrens n LEFT JOIN idp_map im ON im.nren_id = n.nren_id WHERE n.nren_id=?", array('text'), array($sres[0]['nren_id']));
        if (count($nres) < 1) {
            /* No nrens found at all, which means that the
             * subscriber is bogus. Since this is a foreign-key
             * constraint, we've run into a corrupt db. Let's hope
             * this'll never happen :-) */
            Logger::log_event(LOG_EMERG, "Found subscriber (" . $sres[0]['subscriber_id'] . ":" . $sres[0]['name'] . ") without a corresponding NREN (" . $sres[0]['nren_id'] . "), you have a corrupt database");
        }
    } catch (DBStatementException $dbse) {
        $msg = "[{$log_error_code}] Problem executing query. Is the database-schema outdated?. ";
        Logger::log_event(LOG_INFO, $msg . " Server said: " . $dbse->getMessage());
        echo $msg . "<br />\nServer said: " . htmlentities($dbse->getMessage()) . "<br />\n";
        return null;
    } catch (DBQueryException $dbqe) {
        /* FIXME */
        $msg = "Could not find owner-details for certificate, probably issues with supplied data. ";
        $msg .= "Admin_id: " . htmlentities($cert_res[0]['uploaded_by']);
        Logger::log_event(LOG_INFO, $msg . " Server said: " . $dbqe->getMessage());
        echo $msg . "<br />\nServer said: " . htmlentities($dbqe->getMessage()) . "<br />\n";
        return null;
    }
    /*
     * Decorate person.
     */
    $person = new Person();
    if (isset($ares[0]['admin_name']) && $ares[0]['admin_name'] != "") {
        $person->setName($ares[0]['admin_name']);
    } else {
        $person->setName($ares[0]['admin']);
    }
    try {
        $person->setEPPN($ares[0]['admin']);
    } catch (CGE_CriticalAttributeException $cae) {
        echo "[{$log_error_code}] Problems with setting the unique identifier for robot-admin.<br />\n";
        echo "Check the data in admins (admin_id: " . htmlentities($cert_res[0]['uploaded_by']) . ")<br />\n";
        Logger::log_event(LOG_NOTICE, "[RI] ({$log_error_code}) Internal error? Suddenly provided admin-uid is not available.");
        return null;
    }
    $person->setAuth(true);
    $person->setNREN(new NREN($nres[0]['idp_url']));
    $person->setSubscriber(new Subscriber($sres[0]['name'], $person->getNREN()));
    $person->setName($ares[0]['admin_name']);
    $person->setEmail($ares[0]['admin_email']);
    /* Robot authenticated, we can return the person and live happily ever
     * after */
    Logger::log_event(LOG_NOTICE, "[RI]: Authenticated robot-client via cert {$fingerprint} belonging to " . $person->getEPPN());
    return $person;
}
    const TEST = 10;
}
class Person implements IPerson
{
    public function introduce()
    {
        echo "Hello, I'm a person!" . PHP_EOL;
    }
    public function setName($name)
    {
        echo "Hello, my name is {$name}" . PHP_EOL;
    }
}
$foo = new Person();
$foo->introduce();
$foo->setName("foo");
echo Person::TEST . PHP_EOL;
// extendable interfaces
interface IA
{
    public function method();
}
interface IB extends IA
{
    public function method2();
}
class A implements IB
{
    public function method()
    {
        echo "method" . PHP_EOL;