Exemple #1
0
 public function parse($parser)
 {
     if (in_array($this->value, PPP::synonym_list())) {
         $parser->token_list[] = PPP::$synonyms[$this->value];
     } else {
         $parser->token_list[] = $this->value;
     }
 }
 public function testMultipleHasManysToTheSameModel()
 {
     $ppp1 = new PPP();
     $ppp1->name = 'ppp1';
     $ppp1->save();
     $this->assertTrue($ppp1->save());
     $ppp2 = new PPP();
     $ppp2->name = 'ppp2';
     $this->assertTrue($ppp2->save());
     $ppp3 = new PPP();
     $ppp3->name = 'ppp3';
     $this->assertTrue($ppp3->save());
     $p = new P();
     $p->name = 'name2';
     $p->ppp->add($ppp1);
     $p->ppp1->add($ppp2);
     $p->ppp2->add($ppp3);
     $this->assertTrue($p->save());
     //Retrieve row to make sure columns are correct
     $row = ZurmoRedBean::getRow('select * from p where id =' . $p->id);
     $this->assertTrue(isset($row['id']) && ($row['id'] = $p->id));
     $this->assertEquals(null, $row['pp_id']);
     $this->assertEquals(null, $row['pp1link_pp_id']);
     $this->assertEquals(null, $row['pp2link_pp_id']);
     $this->assertCount(5, $row);
     $row = ZurmoRedBean::getRow('select * from ppp where id =' . $ppp1->id);
     $this->assertTrue(isset($row['id']) && ($row['id'] = $ppp1->id));
     $this->assertTrue(isset($row['name']) && ($row['name'] = 'ppp1'));
     $this->assertTrue(isset($row['p_id']) && ($row['p_id'] = $p->id));
     $this->assertEquals(null, $row['ppp1link_p_id']);
     $this->assertEquals(null, $row['ppp2link_p_id']);
     $this->assertCount(5, $row);
     $row = ZurmoRedBean::getRow('select * from ppp where id =' . $ppp2->id);
     $this->assertTrue(isset($row['id']) && ($row['id'] = $ppp2->id));
     $this->assertTrue(isset($row['name']) && ($row['name'] = 'ppp2'));
     $this->assertEquals(null, $row['p_id']);
     $this->assertTrue(isset($row['ppp1link_p_id']) && ($row['ppp1link_p_id'] = $p->id));
     $this->assertEquals(null, $row['ppp2link_p_id']);
     $this->assertCount(5, $row);
     $row = ZurmoRedBean::getRow('select * from ppp where id =' . $ppp3->id);
     $this->assertTrue(isset($row['id']) && ($row['id'] = $ppp3->id));
     $this->assertTrue(isset($row['name']) && ($row['name'] = 'ppp3'));
     $this->assertEquals(null, $row['p_id']);
     $this->assertEquals(null, $row['ppp1link_p_id']);
     $this->assertTrue(isset($row['ppp2link_p_id']) && ($row['ppp2link_p_id'] = $p->id));
     $this->assertCount(5, $row);
     $pId = $p->id;
     $ppp1Id = $ppp1->id;
     $ppp2Id = $ppp2->id;
     $ppp3Id = $ppp3->id;
     $p->forget();
     $ppp1->forget();
     $ppp2->forget();
     $ppp3->forget();
     $p = P::getById($pId);
     $this->assertEquals(1, $p->ppp->count());
     $this->assertEquals(1, $p->ppp1->count());
     $this->assertEquals(1, $p->ppp2->count());
     $this->assertEquals($ppp1Id, $p->ppp[0]->id);
     $this->assertEquals($ppp2Id, $p->ppp1[0]->id);
     $this->assertEquals($ppp3Id, $p->ppp2[0]->id);
     //Unlink relationships to make sure they are removed properly
     $p->ppp->remove(PPP::getById($ppp1Id));
     $p->ppp1->remove(PPP::getById($ppp2Id));
     $p->ppp2->remove(PPP::getById($ppp3Id));
     $saved = $p->save();
     $this->assertTrue($saved);
     //test rows are empty..
     $row = ZurmoRedBean::getRow('select * from ppp where id =' . $ppp1->id);
     $this->assertTrue(isset($row['id']) && ($row['id'] = $ppp1->id));
     $this->assertTrue(isset($row['name']) && ($row['name'] = 'ppp1'));
     $this->assertEquals(null, $row['p_id']);
     $this->assertEquals(null, $row['ppp1link_p_id']);
     $this->assertEquals(null, $row['ppp2link_p_id']);
     $row = ZurmoRedBean::getRow('select * from ppp where id =' . $ppp2->id);
     $this->assertTrue(isset($row['id']) && ($row['id'] = $ppp2->id));
     $this->assertTrue(isset($row['name']) && ($row['name'] = 'ppp2'));
     $this->assertEquals(null, $row['p_id']);
     $this->assertEquals(null, $row['ppp1link_p_id']);
     $this->assertEquals(null, $row['ppp2link_p_id']);
     $row = ZurmoRedBean::getRow('select * from ppp where id =' . $ppp3->id);
     $this->assertTrue(isset($row['id']) && ($row['id'] = $ppp3->id));
     $this->assertTrue(isset($row['name']) && ($row['name'] = 'ppp3'));
     $this->assertEquals(null, $row['p_id']);
     $this->assertEquals(null, $row['ppp1link_p_id']);
     $this->assertEquals(null, $row['ppp2link_p_id']);
 }
Exemple #3
0
function wrapper()
{
    PPP::import("samples/2");
}
Exemple #4
0
 public function parse($content)
 {
     $synonyms = PPP::$synonyms;
     $synonym_list = PPP::synonym_list();
     $lines = explode("\n", $content);
     if ($this->opts['init']) {
         $this->output = array("<?php");
     } else {
         $this->output = array();
     }
     $this->in_block_quotes = false;
     $this->reset = true;
     $this->cur_token = 0;
     $this->token_count = 0;
     $this->reset_state();
     $this->reset_indentation();
     foreach ($lines as $line) {
         $trimmed = trim($line);
         if (empty($trimmed)) {
             $this->output[] = '';
             continue;
         }
         if (empty($this->array_stack) && !$this->in_block_quotes) {
             // Capture indentation
             preg_match('/^(\\s+?)[^\\s]/', $line, $leading_whitespace);
             if (!empty($leading_whitespace) && !empty($leading_whitespace[1])) {
                 $this->match_indentation(strlen($leading_whitespace[1]));
             } else {
                 $this->match_indentation(0);
             }
         }
         $this->tokens = self::tokenize($line);
         if ($this->reset) {
             $this->reset_state();
         }
         $this->token_count = count($this->tokens);
         $this->cur_token = 0;
         $this->reset = true;
         while ($this->cur_token < $this->token_count) {
             try {
                 $this->prev_token = null;
                 $this->next_token = null;
                 $end = false;
                 $this->token = $token = $this->tokens[$this->cur_token];
                 if ($this->cur_token == 0) {
                     if ($token->value == ']' || $token->value == '}') {
                         $tab_variation = -1;
                     } else {
                         $tab_variation = 0;
                     }
                     $this->tabs($tab_variation);
                 }
                 if ($this->cur_token - 1 >= 0) {
                     $this->prev_token = $this->tokens[$this->cur_token - 1];
                 }
                 $this->next_token = $next_token = $this->next_token();
                 $this->cur_token++;
                 $this->blockQuotes();
                 $token->parse($this);
                 if (is_null($this->next_token)) {
                     if ($token->value == ',' || !empty($this->array_stack)) {
                         $this->reset = false;
                         continue;
                     }
                     while (!empty($this->open_stack)) {
                         $this->token_list[] = array_pop($this->open_stack);
                     }
                     if ($this->ends_curly) {
                         $this->token_list[] = ' {';
                     } else {
                         if (!$end) {
                             $this->token_list[] = ';';
                         }
                     }
                 }
             } catch (PPP_ParserException_TokenBreak $e) {
                 break;
             } catch (PPP_ParserException_TokenContinue $e) {
                 continue;
             }
         }
         if ($this->reset) {
             $processed = implode('', $this->token_list);
             $this->output[] = $processed;
         } else {
             $this->token_list[] = "\n";
         }
     }
     while ($this->indentation['count']) {
         $this->dedent(true);
     }
     $printer = implode(PHP_EOL, $this->output);
     return $printer;
 }
Exemple #5
0
<?php

PPP::import("foo/bar");
class Foo
{
    /*
    Block motha f*****g quotes
    */
    function __construct($foo, $bar)
    {
        $this->foo = $foo;
        $this->say($foo, true);
    }
    private function say($msg, $silly)
    {
        if ($silly) {
            echo $msg;
        } else {
            echo ">>>>{$msg}<<<<";
        }
    }
}
$c = new Foo("hello", 123);