当前位置: 首页>>代码示例>>PHP>>正文


PHP Message::create方法代码示例

本文整理汇总了PHP中JMS\TranslationBundle\Model\Message::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Message::create方法的具体用法?PHP Message::create怎么用?PHP Message::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JMS\TranslationBundle\Model\Message的用法示例。


在下文中一共展示了Message::create方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testSet

 public function testSet()
 {
     $col = new MessageCollection();
     $col->add($m = Message::create('foo'));
     $this->assertTrue($col->has('foo'));
     $this->assertSame($m, $col->get('foo'));
 }
开发者ID:clytemnestra,项目名称:JMSTranslationBundle,代码行数:7,代码来源:MessageCollectionTest.php

示例2: testCdataOutput

    public function testCdataOutput()
    {
        $dumper = $this->getDumper();
        $catalogue = new MessageCatalogue();
        $catalogue->add(Message::create('foo')->setLocaleString('<bar>')->setDesc('<baz>'));
        $expected = <<<EOF
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:jms="urn:jms:translation" version="1.2">
  <file source-language="en" target-language="" datatype="plaintext" original="not.available">
    <header>
      <tool tool-id="JMSTranslationBundle" tool-name="JMSTranslationBundle" tool-version="1.1.0-DEV"/>
      <note>The source node in most cases contains the sample message as written by the developer. If it looks like a dot-delimitted string such as "form.label.firstname", then the developer has not provided a default message.</note>
    </header>
    <body>
      <trans-unit id="0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33" resname="foo">
        <source><![CDATA[<baz>]]></source>
        <target state="new"><![CDATA[<bar>]]></target>
      </trans-unit>
    </body>
  </file>
</xliff>

EOF;
        $this->assertEquals($expected, $dumper->dump($catalogue, 'messages'));
    }
开发者ID:pixel-cookers,项目名称:JMSTranslationBundle,代码行数:25,代码来源:XliffDumperTest.php

示例3: testCreate

 public function testCreate()
 {
     $message = Message::create('id', 'foo');
     $this->assertInstanceOf('JMS\\TranslationBundle\\Model\\Message', $message);
     $this->assertEquals('id', $message->getId());
     $this->assertEquals('foo', $message->getDomain());
 }
开发者ID:AntoineLemaire,项目名称:JMSTranslationBundle,代码行数:7,代码来源:MessageTest.php

示例4: testGet

 public function testGet()
 {
     $catalogue = new MessageCatalogue();
     $catalogue->add($message = Message::create('foo'));
     $this->assertTrue($catalogue->hasDomain('messages'));
     $this->assertSame($message, $catalogue->get('foo'));
 }
开发者ID:pixel-cookers,项目名称:JMSTranslationBundle,代码行数:7,代码来源:MessageCatalogueTest.php

示例5: load

 /**
  * Converts Symfony's message catalogue to the catalogue of this
  * bundle.
  *
  * @param mixed $resource
  * @param string $locale
  * @param string $domain
  * @return MessageCatalogue
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     $catalogue = new MessageCatalogue();
     $catalogue->setLocale($locale);
     foreach ($this->loader->load($resource, $locale, $domain)->all($domain) as $id => $message) {
         $catalogue->add(Message::create($id, $domain)->setLocaleString($message)->setNew(false));
     }
     return $catalogue;
 }
开发者ID:pixel-cookers,项目名称:JMSTranslationBundle,代码行数:18,代码来源:SymfonyLoaderAdapter.php

示例6: testLoadWithSymfonyFormat

 public function testLoadWithSymfonyFormat()
 {
     $loader = new XliffLoader();
     $expected = new MessageCatalogue();
     $expected->setLocale('en');
     $expected->add(Message::create('foo1')->setDesc('foo1')->setLocaleString('bar')->setNew(false));
     $expected->add(Message::create('foo2')->setDesc('foo2')->setLocaleString('bar')->setNew(false));
     $expected->add(Message::create('foo3')->setDesc('foo3')->setLocaleString('bar')->setNew(false));
     $expected->add(Message::create('foo4')->setDesc('foo4')->setLocaleString('bar')->setNew(false));
     $this->assertEquals($expected, $loader->load(__DIR__ . '/Symfony/xliff/old_format.xml', 'en'));
 }
开发者ID:AntoineLemaire,项目名称:JMSTranslationBundle,代码行数:11,代码来源:XliffLoaderTest.php

示例7: testCompareWithMultipleDomains

 public function testCompareWithMultipleDomains()
 {
     $current = new MessageCatalogue();
     $current->add(Message::create('foo')->setLocaleString('bar'));
     $current->add(Message::create('bar', 'routes')->setLocaleString('baz'));
     $new = new MessageCatalogue();
     $new->add(new Message('foo'));
     $new->add(new Message('bar'));
     $expected = new ChangeSet(array(new Message('bar')), array(Message::create('bar', 'routes')->setLocaleString('baz')));
     $comparator = new CatalogueComparator();
     $this->assertEquals($expected, $comparator->compare($current, $new));
 }
开发者ID:clytemnestra,项目名称:JMSTranslationBundle,代码行数:12,代码来源:CatalogueComparatorTest.php

示例8: load

 public function load($resource, $locale, $domain = 'messages')
 {
     $previous = libxml_use_internal_errors(true);
     if (false === ($doc = simplexml_load_file($resource))) {
         libxml_use_internal_errors($previous);
         $libxmlError = libxml_get_last_error();
         throw new RuntimeException(sprintf('Could not load XML-file "%s": %s', $resource, $libxmlError->message));
     }
     libxml_use_internal_errors($previous);
     $doc->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2');
     //        $doc->registerXPathNamespace('jms', 'urn:jms:translation');
     //        $hasReferenceFiles = in_array('urn:jms:translation', $doc->getNamespaces(true));
     $catalogue = new MessageCatalogue();
     $catalogue->setLocale($locale);
     foreach ($doc->xpath('//xliff:trans-unit') as $trans) {
         $id = ($resName = (string) $trans->attributes()->resname) ? $resName : (string) $trans->source;
         $m = Message::create($id, $domain)->setDesc((string) $trans->source)->setLocaleString((string) $trans->target);
         $catalogue->add($m);
         //            if ($hasReferenceFiles) {
         //                foreach ($trans->xpath('./jms:reference-file') as $file) {
         //                    $line = (string) $file->attributes()->line;
         //                    $column = (string) $file->attributes()->column;
         //                    $m->addSource(new FileSource(
         //                        (string) $file,
         //                        $line ? (integer) $line : null,
         //                        $column ? (integer) $column : null
         //                    ));
         //                }
         //            }
         if ($meaning = (string) $trans->attributes()->extradata) {
             if (0 === strpos($meaning, 'Meaning: ')) {
                 $meaning = substr($meaning, 9);
             }
             $m->setMeaning($meaning);
         }
         if (!($state = (string) $trans->target->attributes()->state) || 'new' !== $state) {
             $m->setNew(false);
         }
     }
     return $catalogue;
 }
开发者ID:Craimasjien,项目名称:JMSTranslationBundle,代码行数:41,代码来源:XliffLoader.php

示例9: enterNode

 public function enterNode(\PHPParser_Node $node)
 {
     if ($node instanceof \PHPParser_Node_Stmt_Namespace) {
         $this->namespace = implode('\\', $node->name->parts);
         return;
     }
     if ($node instanceof \PHPParser_Node_Stmt_Class) {
         $name = '' === $this->namespace ? $node->name : $this->namespace . '\\' . $node->name;
         if (!class_exists($name)) {
             return;
         }
         $ref = new \ReflectionClass($name);
         if (!$ref->isSubclassOf('Symfony\\Component\\Security\\Core\\Exception\\AuthenticationException') && $ref->name !== 'Symfony\\Component\\Security\\Core\\Exception\\AuthenticationException') {
             return;
         }
         if (!$ref->hasMethod('getMessageKey')) {
             return;
         }
         $this->inAuthException = true;
         return;
     }
     if (!$this->inAuthException) {
         return;
     }
     if ($node instanceof \PHPParser_Node_Stmt_ClassMethod) {
         if ('getmessagekey' === strtolower($node->name)) {
             $this->inGetMessageKey = true;
         }
         return;
     }
     if (!$this->inGetMessageKey) {
         return;
     }
     if (!$node instanceof \PHPParser_Node_Stmt_Return) {
         return;
     }
     $ignore = false;
     $desc = $meaning = null;
     if ($docComment = $node->getDocComment()) {
         foreach ($this->docParser->parse($docComment->getText(), 'file ' . $this->file . ' near line ' . $node->getLine()) as $annot) {
             if ($annot instanceof Ignore) {
                 $ignore = true;
             } else {
                 if ($annot instanceof Desc) {
                     $desc = $annot->text;
                 } else {
                     if ($annot instanceof Meaning) {
                         $meaning = $annot->text;
                     }
                 }
             }
         }
     }
     if (!$node->expr instanceof \PHPParser_Node_Scalar_String) {
         if ($ignore) {
             return;
         }
         $message = sprintf('Could not extract id from return value, expected scalar string but got %s (in %s on line %d).', get_class($node->expr), $this->file, $node->expr->getLine());
         if ($this->logger) {
             $this->logger->err($message);
             return;
         }
         throw new RuntimeException($message);
     }
     $message = Message::create($node->expr->value, $this->domain)->setDesc($desc)->setMeaning($meaning)->addSource(new FileSource((string) $this->file, $node->expr->getLine()));
     $this->catalogue->add($message);
 }
开发者ID:binaryminds,项目名称:JMSTranslationBundle,代码行数:67,代码来源:AuthenticationMessagesExtractor.php


注:本文中的JMS\TranslationBundle\Model\Message::create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。