コード例 #1
0
ファイル: Alias.php プロジェクト: Nycto/phpVocab
 public function testParseAlias_WithAs()
 {
     $access = \vc\Tokens\Access::buildAccess($this->oneTokenReader()->thenAUse->thenSomeSpace->thenANamespacePath('sub1\\sub2')->thenSomeSpace->then(Token::T_AS, 'as')->thenSomeSpace->thenAName('renamed')->thenASemicolon->thenAClass);
     $parser = new \vc\Parser\NSpace\Alias(new \vc\Parser\Path());
     $this->assertEquals(r8(new \vc\Data\Alias('sub1\\sub2'))->setAlias('renamed'), $parser->parseAlias($access));
     $this->assertHasToken(Token::T_CLASS, $access);
 }
コード例 #2
0
ファイル: Constant.php プロジェクト: Nycto/phpVocab
 public function testParseConstant_Heredoc()
 {
     $access = \vc\Tokens\Access::buildAccess($this->oneTokenReader()->thenAConst->thenSomeSpace->thenAName('NAME')->thenSomeSpace->thenAnEquals->thenSomeSpace->thenAHereDoc('contents')->thenASemicolon->thenAClass);
     $parser = $this->getConstantParser();
     $this->assertEquals(r8(new \vc\Data\Constant('NAME'))->setValue(new \vc\Data\Value('contents', 'string')), $parser->parseConstant($access));
     $this->assertHasToken(Token::T_CLASS, $access);
 }
コード例 #3
0
ファイル: Property.php プロジェクト: Nycto/phpVocab
 public function testParseProperty_defaultValue()
 {
     $access = \vc\Tokens\Access::buildAccess($this->oneTokenReader()->thenAPublic->thenSomeSpace->thenAVariable('$var')->thenSomeSpace->thenAnEquals->thenAnInteger(789)->thenASemicolon);
     $sig = new \vc\Data\Signature(120, new \vc\Data\Comment('Note'));
     $this->assertEquals(r8(new \vc\Data\Property(120, new \vc\Data\Comment('Note')))->setName('$var')->setValue(new \vc\Data\Value(789, 'int')), $this->getPropertyParser()->parseProperty($sig, $access));
     $this->assertEndOfTokens($access);
 }
コード例 #4
0
ファイル: Context.php プロジェクト: Nycto/Round-Eights
 /**
  * Helper function that redirects the client to another url
  *
  * If redirect is called twice, the second call will override the first call
  *
  * @param String $url The URL to forward them to
  * @return \r8\Page\Context Returns a self reference
  */
 public function redirect($url)
 {
     $url = trim((string) $url);
     r8(new \r8\Validator\URL(\r8\Validator\URL::ALLOW_RELATIVE))->ensure($url);
     $this->redirect = $url;
     $this->suppress();
     return $this;
 }
コード例 #5
0
ファイル: Access.php プロジェクト: Nycto/Round-Eights
 /**
  * Normalizes a variable name and checks whether it is properly formatted
  *
  * @throws \r8\Exception\Argument Thrown if the label is invalid
  * @param String $label The variable name being filtered
  * @return String
  */
 public static function normalizeLabel($label)
 {
     $label = r8(new \r8\Filter\Variable())->filter($label);
     if (!r8(new \r8\Validator\Variable())->isValid($label)) {
         throw new \r8\Exception\Argument(0, "Label", "Must be a valid PHP variable name");
     }
     return $label;
 }
コード例 #6
0
ファイル: Comment.php プロジェクト: Nycto/phpVocab
 public function testParse_TagsNestedAtSymbol()
 {
     $parser = new \vc\Parser\Comment();
     $this->assertEquals(\r8(new \vc\Data\Comment("This is a test comment"))->addTag(new \vc\Data\Tag("tag", "Single @Line"))->addTag(new \vc\Data\Tag("flag", NULL)), $parser->parse('/**
               * This is a test comment
               * @tag Single @Line
               * @flag
               */'));
 }
コード例 #7
0
ファイル: Backtrace.php プロジェクト: Nycto/Round-Eights
 /**
  * A helper method that dumps the current backtrace to the client
  *
  * @return NULL
  */
 public static function dump()
 {
     if (\r8\Env::request()->isCLI()) {
         $format = new \r8\Backtrace\Formatter\Text();
     } else {
         $format = new \r8\Backtrace\Formatter\HTML();
     }
     echo r8(new \r8\Backtrace\Formatter($format))->format(self::create()->popEvent());
 }
コード例 #8
0
ファイル: Body.php プロジェクト: Nycto/phpVocab
 public function testParseReference_WithArgs()
 {
     $access = \vc\Tokens\Access::buildAccess($this->oneTokenReader()->thenAFunction->thenSomeSpace->thenAName('MyFunc')->thenOpenParens->thenAVariable('$var')->thenCloseParens->thenAnOpenBlock->thenAnEcho->thenSomeSpace->thenAString('test')->thenASemicolon->thenACloseBlock);
     $routine = $this->getMockForAbstractClass('\\vc\\Data\\Routine', array(1));
     $this->getFuncParser()->parseRoutine($routine, $access);
     $this->assertEquals('MyFunc', $routine->getName());
     $this->assertEquals(array(r8(new \vc\Data\Arg())->setVariable('$var')), $routine->getArgs());
     $this->assertEndOfTokens($access);
 }
コード例 #9
0
ファイル: Scanner.php プロジェクト: Nycto/phpVocab
 public function testScan_ParseError()
 {
     $file = new \r8\FileSys\File(__FILE__);
     $parser = $this->getMock('\\vc\\iface\\Parser');
     $parser->expects($this->once())->method("parse")->with($this->equalTo($file))->will($this->throwException($this->getMock('\\vc\\Tokens\\Exception')));
     $storage = $this->getMock('\\vc\\iface\\Storage');
     $storage->expects($this->never())->method("store");
     $scanner = new \vc\App\Scanner($this->getParseLogger(), $parser, $storage);
     $scanner->scan(\r8(new \vc\App\Paths())->addInput($file));
 }
コード例 #10
0
ファイル: Formatter.php プロジェクト: Nycto/Round-Eights
 /**
  * Returns an e-mail address formatted as such: Name <*****@*****.**>
  *
  * @param String $email The e-mail address
  * @param String $name The name of the person associated with the address
  * @return String The well formatted address line
  */
 public static function formatAddress($email, $name = NULL)
 {
     $email = r8(new \r8\Filter\Email())->filter($email);
     if (!\r8\isVague($name)) {
         $name = trim(\r8\str\stripNoPrint($name));
     }
     if (\r8\isVague($name)) {
         return "<" . $email . ">";
     } else {
         return '"' . addslashes($name) . '" <' . $email . '>';
     }
 }
コード例 #11
0
ファイル: Form.php プロジェクト: Nycto/Round-Eights
 public function testProcess_WithFlags()
 {
     $input = new \r8\CLI\Input(array('test.php', '-a', 'one', 'two'));
     $arg = new \r8\CLI\Arg\Many('test');
     $form = new \r8\CLI\Form();
     $form->addOption(\r8(new \r8\CLI\Option('a', 'test'))->addArg($arg));
     $result = $form->process($input);
     $this->assertThat($result, $this->isInstanceOf('\\r8\\CLI\\Result'));
     $this->assertTrue($result->flagExists('a'));
     $this->assertSame(array('one', 'two'), $result->getArgsForFlag('a'));
     $this->assertSame(array(array('one', 'two')), $result->getAllArgsForFlag('a'));
 }
コード例 #12
0
ファイル: Invoke.php プロジェクト: Nycto/Round-Eights
 /**
  * Constructor...
  *
  * @param String $method The name of the method to invoke
  * @param mixed $args... Any rightward arguments
  */
 public function __construct($method)
 {
     $method = trim((string) $method);
     if (!r8(new \r8\Validator\Method())->isValid($method)) {
         throw new \r8\Exception\Argument(0, "Method", "Invalid method name");
     }
     $this->method = $method;
     if (func_num_args() > 1) {
         $args = func_get_args();
         array_shift($args);
         $this->setRightByArray($args);
     }
 }
コード例 #13
0
ファイル: SQL.php プロジェクト: Nycto/Round-Eights
 /**
  * Cleans up a SQL query for comparison
  *
  * @param String $sql The SQL to clean
  * @return String
  */
 public static function cleanSQL($sql)
 {
     $quoter = new \r8\Quoter();
     $quoter->setQuote('"')->setQuote("'")->setQuote("`");
     $parsed = $quoter->parse($sql);
     $parsed->setIncludeQuoted(FALSE)->setIncludeUnquoted(TRUE);
     $keywords = '/\\b(?:' . implode("|", self::$keywords) . ')\\b/i';
     $breaks = '/\\b(' . implode("|", self::$breaks) . ')\\b/i';
     $parsed->filter(new \r8\Filter\Chain(r8(new \r8\Curry\Call('str_replace'))->setLeft(array("\n", "\r"), " "), r8(new \r8\Curry\Call('\\r8\\str\\stripRepeats'))->setRight(" "), r8(new \r8\Curry\Call('preg_replace_callback'))->setLeft($keywords, function ($value) {
         return strtoupper($value[0]);
     }), r8(new \r8\Curry\Call('preg_replace'))->setLeft($breaks, "\n\\1")));
     return trim($parsed->__toString(), " ;");
 }
コード例 #14
0
ファイル: Table.php プロジェクト: Nycto/Round-Eights
 /**
  * Returns a test form
  *
  * @return \r8\Form
  */
 public function getTestForm()
 {
     $form = new \r8\Form();
     $form->setAction("http://www.example.com/submit.php");
     $form->andFormValidator(new \r8\Validator\Fail("Form Error"));
     $form->addField(r8(new \r8\Form\Checkbox("CheckboxFld", "Checkbox Label"))->andValidator(new \r8\Validator\Fail("Checkbox Error")));
     $form->addField(new \r8\Form\File("FileFld", "File Label"));
     $form->addField(r8(new \r8\Form\Hidden("HiddenFld")));
     $form->addField(r8(new \r8\Form\Password("PasswordFld", "Password Label"))->andValidator(new \r8\Validator\Fail("Password Error")));
     $form->addField(r8(new \r8\Form\Radio("RadioFld", "Radio Label"))->addOption(1234, "Radio Option")->andValidator(new \r8\Validator\Fail("Radio Error")));
     $form->addField(r8(new \r8\Form\Select("SelectFld", "Select Label"))->andValidator(new \r8\Validator\Fail("Select Error")));
     $form->addField(r8(new \r8\Form\Text("TextFld", "Text Label"))->andValidator(new \r8\Validator\Fail("Text Error")));
     $form->addField(r8(new \r8\Form\TextArea("TextAreaFld", "TextArea Label"))->andValidator(new \r8\Validator\Fail("TextArea Error")));
     return $form;
 }
コード例 #15
0
ファイル: CLI.php プロジェクト: Nycto/phpVocab
 /**
  * Builds an object for parsing the command line arguments
  *
  * @return \r8\CLI\Command
  */
 public static function getArgParser()
 {
     $cmd = new \r8\CLI\Command('vocab', 'PHP documentation generator');
     $pathFilter = new \r8\Filter\Chain(new \r8\Filter\Printable(), new \r8\Curry\Call('trim'));
     $cmd->addArg(new \r8\CLI\Arg\One('Output Directory', $pathFilter, new \r8\Validator\All(\r8(new \r8\Validator\NotEmpty())->addError('Output directory must not be empty'), new \r8\Validator\Callback(function ($dir) {
         return is_file($dir) ? 'Path must not be an existing file: ' . $dir : NULL;
     }))));
     $inputValidator = new \r8\Validator\All(\r8(new \r8\Validator\NotEmpty())->addError('Input path must not be empty'), new \r8\Validator\Callback(function ($path) {
         return file_exists($path) ? NULL : 'Path does not exist: ' . $path;
     }));
     $cmd->addArg(new \r8\CLI\Arg\One('Input Path', $pathFilter, $inputValidator));
     $cmd->addArg(new \r8\CLI\Arg\Many('Input Path', $pathFilter, $inputValidator));
     // A command form for viewing help/version info
     $info = new \r8\CLI\Form();
     $cmd->addForm($info);
     $info->addOption(\r8(new \r8\CLI\Option('v', 'Outputs version information'))->addFlag('version'));
     $info->addOption(\r8(new \r8\CLI\Option('h', 'Displays the help screen'))->addFlag('help'));
     return $cmd;
 }
コード例 #16
0
ファイル: Result.php プロジェクト: Nycto/Round-Eights
 /**
  * Returns a test result object filled with data
  *
  * @return \r8\CLI\Result
  */
 public function getTestResult()
 {
     $opt1 = \r8(new \r8\CLI\Option('a', ''))->addFlag('b')->addFlag('A');
     return r8(new \r8\CLI\Result())->addOption($opt1, array('arg1', 'arg2'))->addOption($opt1, array('two', 'three'))->addOption($opt1, array('four'))->addOption(\r8(new \r8\CLI\Option('x', ''))->addFlag('LONG'), array());
 }
コード例 #17
0
ファイル: Command.php プロジェクト: Nycto/Round-Eights
 public function testProcess_SecondFormReturns()
 {
     $command = new \r8\CLI\Command('name', 'desc');
     $command->addForm(\r8(new \r8\CLI\Form())->addArg(new \r8\CLI\Arg\One('test')));
     $result = $command->process(new \r8\CLI\Input(array('test.php', 'one')));
     $this->assertThat($result, $this->isInstanceOf('\\r8\\CLI\\Result'));
     $this->assertSame(array('one'), $result->getArgs());
 }
コード例 #18
0
ファイル: Form.php プロジェクト: Nycto/Round-Eights
 public function testToArray()
 {
     $form = new \r8\Form();
     $this->assertSame(array(), $form->toArray());
     $form->addField(\r8(new \r8\Form\Text("test1"))->setValue("abc"));
     $form->addField(\r8(new \r8\Form\Text("test2"))->setValue("blah"));
     $this->assertSame(array('test1' => 'abc', 'test2' => 'blah'), $form->toArray());
 }
コード例 #19
0
ファイル: Field.php プロジェクト: Nycto/Round-Eights
 /**
  * Sets the name of this field
  *
  * @param String $name The field name
  * @return \r8\Form\Field Returns a self reference
  */
 public function setName($name)
 {
     $name = r8(new \r8\Filter\Variable())->filter($name);
     if (!r8(new \r8\Validator\Variable())->isValid($name)) {
         throw new \r8\Exception\Argument(0, "Field Name", "Must be a valid PHP variable name");
     }
     $this->name = $name;
     return $this;
 }
コード例 #20
0
ファイル: NSpace.php プロジェクト: Nycto/phpVocab
 public function testResolve_AliasedPath_WithoutLeadingSlash()
 {
     $nspace = new \vc\Data\NSpace();
     $nspace->addAlias(\r8(new \vc\Data\Alias('one\\two'))->setAlias('english'));
     $this->assertSame('\\one\\two\\three', $nspace->resolve('english\\three'));
 }
コード例 #21
0
ファイル: Brackets.php プロジェクト: Nycto/phpVocab
 public function testParseCurliesContainingADollarCurly()
 {
     $reader = $this->oneTokenReader()->then(Token::T_ECHO, 'echo')->thenSomeSpace->thenAQuote->thenADollarCurly('var')->thenSomeSpace->thenAnOpenBlock->thenAVariable('$var')->thenACloseBlock->thenAQuote->thenASemicolon->thenACloseBlock;
     $this->assertSame('echo "${var} {$var}";', r8(new \vc\Parser\Brackets())->parseCurlies($reader));
 }
コード例 #22
0
ファイル: TestCase.php プロジェクト: Nycto/phpVocab
 /**
  * Returns an access object loaded with the given reader and comment
  *
  * @return \vc\Tokens\Access
  */
 public function getAccessParserWithComment(\vc\Data\Comment $comment, \vc\iface\Tokens\Reader $reader)
 {
     $comParse = $this->getMock('\\vc\\iface\\Tokens\\Comments');
     $comParse->expects($this->any())->method("getComment")->will($this->returnValue($comment));
     return new \vc\Tokens\Access($reader, r8(new \vc\Tokens\Search($reader))->setTokenMask(array(\vc\Tokens\Token::T_WHITESPACE)), $comParse);
 }
コード例 #23
0
ファイル: Form.php プロジェクト: Nycto/Round-Eights
 /**
  * Returns the first field with the given name
  *
  * @param String $name The name of the field to return
  * @return Boolean Returns the requested field, or NULL if it can't be found
  */
 public function find($name)
 {
     $name = r8(new \r8\Filter\Variable())->filter($name);
     if (!r8(new \r8\Validator\Variable())->isValid($name)) {
         throw new \r8\Exception\Argument(0, "Field Name", "Must be a valid PHP variable name");
     }
     foreach ($this->fields as $field) {
         if ($field->getName() == $name) {
             return $field;
         }
     }
     return null;
 }
コード例 #24
0
ファイル: Semaphore.php プロジェクト: Nycto/Round-Eights
 /**
  * Releases the lock against this semaphore
  *
  * @throws \r8\Exception\Resource Thrown if this semaphore lock can't be released
  * @return \r8\SysV\Semaphore Returns a self reference
  */
 public function unlock()
 {
     if (!$this->locked) {
         return $this;
     }
     if (!sem_release($this->resource)) {
         throw r8(new \r8\Exception\Resource("Unable to release lock"))->addData("Key", $this->key);
     }
     $this->locked = FALSE;
     return $this;
 }
コード例 #25
0
ファイル: Search.php プロジェクト: Nycto/phpVocab
 /**
  * @see \vc\iface\Tokens\Search::copy
  */
 public function copy(\vc\iface\Tokens\Reader $reader)
 {
     return r8(new self($reader))->setTokenMask($this->mask);
 }
コード例 #26
0
ファイル: Args.php プロジェクト: Nycto/phpVocab
 public function testParseArgs_Combined()
 {
     $access = \vc\Tokens\Access::buildAccess($this->oneTokenReader()->thenOpenParens->thenANamespacePath('\\path\\to\\class')->thenSomeSpace->thenAnAmpersand->thenSomeSpace->thenAVariable('$test')->thenSomeSpace->thenAnEquals->thenSomeSpace->thenAnInteger(123)->thenAComma->thenAnArray->thenSomeSpace->thenAnAmpersand->thenSomeSpace->thenAVariable('$test2')->thenSomeSpace->thenAnEquals->thenSomeSpace->thenAnArrayValue(array(1))->thenCloseParens);
     $this->assertEquals(array(\r8(new \vc\Data\Arg())->setType('\\path\\to\\class')->setReference(TRUE)->setVariable('$test')->setDefault(new \vc\Data\Value(123, 'int')), \r8(new \vc\Data\Arg())->setType('array')->setReference(TRUE)->setVariable('$test2')->setDefault(new \vc\Data\Value('array( 0 => 1,)', 'array'))), $this->getArgParser()->parseArgs($access));
     $this->assertEndOfTokens($access);
 }
コード例 #27
0
ファイル: Input.php プロジェクト: Nycto/Round-Eights
 public function testGetScript()
 {
     $this->assertNull(\r8(new \r8\CLI\Input(array()))->getScript());
     $this->assertSame('test.php', \r8(new \r8\CLI\Input(array('test.php')))->getScript());
     $this->assertSame('test.php', \r8(new \r8\CLI\Input(array('test.php', 'arg')))->getScript());
 }
コード例 #28
0
ファイル: Method.php プロジェクト: Nycto/phpVocab
 public function testParseMethod_AbstractPrivateMethod()
 {
     $access = \vc\Tokens\Access::buildAccess($this->oneTokenReader()->thenAnAbstract->thenSomeSpace->thenAPrivate->thenSomeSpace->thenAFunction->thenSomeSpace->thenAName('MyFunc')->thenOpenParens->thenCloseParens->thenAnOpenBlock->thenACloseBlock);
     $sig = new \vc\Data\Signature(123);
     $this->assertEquals(r8(new \vc\Data\Routine\Method(123))->setName('MyFunc')->setAbstract(TRUE)->setVisibility(\vc\Data\Visibility::vPrivate()), $this->getMethodParser()->parseMethod($sig, $access));
 }
コード例 #29
0
ファイル: Header.php プロジェクト: Nycto/phpVocab
 public function testParseIFace_WithExtends()
 {
     $access = $this->getAccessParserWithComment(new \vc\Data\Comment('Data'), $this->oneTokenReader()->thenAnInterface(25)->thenSomeSpace->thenAName('MyIFace')->thenSomeSpace->thenAnExtends->thenSomeSpace->thenAPathList(array('\\parent', 'relative'))->thenSomeSpace->thenAnOpenBlock->thenACloseBlock);
     $this->assertEquals(r8(new \vc\Data\Type\IFace(25, new \vc\Data\Comment('Data')))->setName('MyIFace')->setExtends(array('\\parent', 'relative')), $this->getIFaceParser()->parseIFace($access));
     $this->assertHasToken(Token::T_CURLY_CLOSE, $access);
 }
コード例 #30
0
ファイル: CSS.php プロジェクト: Nycto/Round-Eights
 /**
  * Sets the Source URL of this CSS resource
  *
  * @param String $source
  * @return \r8\HTML\CSS Returns a self reference
  */
 public function setSource($source)
 {
     r8(new \r8\Validator\URL(\r8\Validator\URL::ALLOW_RELATIVE))->ensure($source);
     $this->source = $source;
     return $this;
 }