本文整理汇总了PHP中Symfony\Component\Translation\Loader\ArrayLoader::load方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayLoader::load方法的具体用法?PHP ArrayLoader::load怎么用?PHP ArrayLoader::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Translation\Loader\ArrayLoader
的用法示例。
在下文中一共展示了ArrayLoader::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
/**
* {@inheritdoc}
*/
public function load($resource, $locale, $domain = 'messages')
{
if (!stream_is_local($resource)) {
throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
}
if (!file_exists($resource)) {
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
}
$messages = array();
try {
$file = new \SplFileObject($resource, 'rb');
} catch (\RuntimeException $e) {
throw new NotFoundResourceException(sprintf('Error opening file "%s".', $resource), 0, $e);
}
$file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY);
$file->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
foreach ($file as $data) {
if ('#' !== substr($data[0], 0, 1) && isset($data[1]) && 2 === count($data)) {
$messages[$data[0]] = $data[1];
}
}
$catalogue = parent::load($messages, $locale, $domain);
if (class_exists('Symfony\\Component\\Config\\Resource\\FileResource')) {
$catalogue->addResource(new FileResource($resource));
}
return $catalogue;
}
示例2: load
/**
* {@inheritdoc}
*
* @api
*/
public function load($resource, $locale, $domain = 'messages')
{
$messages = (require $resource);
$catalogue = parent::load($messages, $locale, $domain);
$catalogue->addResource(new FileResource($resource));
return $catalogue;
}
示例3: load
/**
* {@inheritdoc}
*/
public function load($resource, $locale, $domain = 'messages')
{
if (!stream_is_local($resource)) {
throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
}
if (!file_exists($resource)) {
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
}
if (!class_exists('Symfony\\Component\\Yaml\\Parser')) {
throw new \LogicException('Loading translations from the YAML format requires the Symfony Yaml component.');
}
if (null === $this->yamlParser) {
$this->yamlParser = new YamlParser();
}
try {
$messages = $this->yamlParser->parse(file_get_contents($resource));
} catch (ParseException $e) {
throw new InvalidResourceException(sprintf('Error parsing YAML, invalid file "%s"', $resource), 0, $e);
}
// empty file
if (null === $messages) {
$messages = array();
}
// not an array
if (!is_array($messages)) {
throw new InvalidResourceException(sprintf('The file "%s" must contain a YAML array.', $resource));
}
$catalogue = parent::load($messages, $locale, $domain);
if (class_exists('Symfony\\Component\\Config\\Resource\\FileResource')) {
$catalogue->addResource(new FileResource($resource));
}
return $catalogue;
}
示例4: load
/**
* {@inheritdoc}
*
* @api
*/
public function load($resource, $locale, $domain = 'messages')
{
$messages = array();
try {
$file = new \SplFileObject($resource, 'rb');
} catch (\RuntimeException $e) {
throw new \InvalidArgumentException(sprintf('Error opening file "%s".', $resource));
}
$file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY);
$file->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
foreach ($file as $data) {
if (substr($data[0], 0, 1) === '#') {
continue;
}
if (!isset($data[1])) {
continue;
}
if (count($data) == 2) {
$messages[$data[0]] = $data[1];
} else {
continue;
}
}
$catalogue = parent::load($messages, $locale, $domain);
$catalogue->addResource(new FileResource($resource));
return $catalogue;
}
示例5: load
/**
* {@inheritdoc}
*/
public function load($resource, $locale, $domain = 'messages')
{
if (!stream_is_local($resource)) {
throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
}
if (!file_exists($resource)) {
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
}
try {
$messages = Neon\Neon::decode(file_get_contents($resource));
} catch (Nette\Utils\NeonException $e) {
throw new InvalidResourceException(sprintf("Error parsing Neon: %s", $e->getMessage()), 0, $e);
} catch (Nette\Neon\Exception $e) {
throw new InvalidResourceException(sprintf("Error parsing Neon: %s", $e->getMessage()), 0, $e);
}
if (empty($messages)) {
$messages = array();
}
if (!is_array($messages)) {
throw new InvalidResourceException(sprintf('The file "%s" must contain a Neon array.', $resource));
}
$catalogue = parent::load($messages, $locale, $domain);
$catalogue->addResource(new FileResource($resource));
return $catalogue;
}
示例6: load
/**
* {@inheritdoc}
*
* @api
*/
public function load($resource, $locale, $domain = 'messages')
{
if (!stream_is_local($resource)) {
throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
}
if (!file_exists($resource)) {
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
}
if (null === $this->yamlParser) {
$this->yamlParser = new YamlParser();
}
try {
$messages = $this->yamlParser->parse(file_get_contents($resource));
} catch (ParseException $e) {
throw new InvalidResourceException(sprintf('Error parsing YAML, invalid file "%s"', $resource), 0, $e);
}
// empty file
if (null === $messages) {
$messages = array();
}
// not an array
if (!is_array($messages)) {
throw new InvalidResourceException(sprintf('The file "%s" must contain a YAML array.', $resource));
}
$catalogue = parent::load($messages, $locale, $domain);
$catalogue->addResource(new FileResource($resource));
return $catalogue;
}
示例7: load
/**
* {@inheritdoc}
*/
public function load($resource, $locale, $domain = 'messages')
{
$messages = array();
$file = @fopen($resource, 'rb');
if (!$file) {
throw new \InvalidArgumentException(sprintf('Error opening file "%s".', $resource));
}
while (($data = fgetcsv($file, 0, ';')) !== false) {
if (substr($data[0], 0, 1) === '#') {
continue;
}
if (!isset($data[1])) {
continue;
}
if (count($data) == 2) {
$messages[$data[0]] = $data[1];
} else {
continue;
}
}
$catalogue = parent::load($messages, $locale, $domain);
$catalogue->addResource(new FileResource($resource));
return $catalogue;
}
示例8: load
/**
* {@inheritdoc}
*/
public function load($resource, $locale, $domain = 'messages')
{
$dataCatalogue = new DataCatalogue();
$dataCatalogue->load($resource, 'json', $locale);
$messages = $dataCatalogue->getMessages();
$catalogue = parent::load($messages, $locale, $domain);
$catalogue->addResource(new FileResource($resource));
return $catalogue;
}
示例9: load
/**
* {@inheritdoc}
*
* @api
*/
public function load($resource, $locale, $domain = 'messages')
{
if (!stream_is_local($resource)) {
throw new \InvalidArgumentException(sprintf('This is not a local file "%s".', $resource));
}
$messages = (require $resource);
$catalogue = parent::load($messages, $locale, $domain);
$catalogue->addResource(new FileResource($resource));
return $catalogue;
}
示例10: load
/**
*
* {@inheritDoc} @see ArrayLoader::load()
*/
public function load($resource, $locale, $domain = 'messages')
{
$messages = array();
$catalogue = new MessageCatalogue($locale);
$catalogue->add($resource, $domain);
$messages = $this->parse($resource);
$catalogue = parent::load($messages, $locale, $domain);
$catalogue->addResource(new FileResource($resource));
return $catalogue;
}
示例11: load
/**
* {@inheritdoc}
*/
public function load($resource, $locale, $domain = 'messages')
{
if (!stream_is_local($resource)) {
throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
}
if (!file_exists($resource)) {
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
}
return parent::load(require $resource, $locale, $domain);
}
示例12: load
/**
* {@inheritdoc}
*/
public function load($resource, $locale, $domain = 'messages')
{
if (!is_file($resource)) {
throw new \InvalidArgumentException(sprintf('Error opening file "%s".', $resource));
}
$messages = parse_ini_file($resource, true);
$catalogue = parent::load($messages, $locale, $domain);
$catalogue->addResource(new FileResource($resource));
return $catalogue;
}
示例13: load
/**
* {@inheritdoc}
*/
public function load($resource, $locale, $domain = 'messages')
{
if (!stream_is_local($resource)) {
throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
}
if (!file_exists($resource)) {
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
}
$messages = parse_ini_file($resource, true);
$catalogue = parent::load($messages, $locale, $domain);
$catalogue->addResource(new FileResource($resource));
return $catalogue;
}
示例14: load
/**
* {@inheritdoc}
*
* @api
*/
public function load($resource, $locale, $domain = 'messages')
{
if (!stream_is_local($resource)) {
throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
}
if (!file_exists($resource)) {
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
}
$messages = (require $resource);
$catalogue = parent::load($messages, $locale, $domain);
if (class_exists('Symfony\\Component\\Config\\Resource\\FileResource')) {
$catalogue->addResource(new FileResource($resource));
}
return $catalogue;
}
示例15: load
public function load($resource, $locale, $domain = 'messages')
{
$messages = $this->parse($resource);
// empty file
if (null === $messages) {
$messages = array();
}
// not an array
if (!is_array($messages)) {
throw new \InvalidArgumentException(sprintf('The file "%s" must contain a valid mo file.', $resource));
}
$catalogue = parent::load($messages, $locale, $domain);
$catalogue->addResource(new FileResource($resource));
return $catalogue;
}