It transfres a given JSON string to a collection of field

@param string|json $json
@param string $localeGroup
@param array $languages

@return CrestApps\CodeGenerator\Models\Resource
436288
public static function fromJson($json, $localeGroup, array $languages = [])
    {
        if (empty($json) || ($capsule = json_decode($json, true)) === null) {
            throw new Exception("The provided string is not a valid json.");
        }

        if (is_array($capsule) && !Helpers::isAssociative($capsule)) {
            // At this point we know the resource file is` using old convention
            // Set the fields
            $fields = FieldTransformer::fromArray($capsule, $localeGroup, $languages, true);

            return new Resource($fields);
        }

        return self::fromArray($capsule, $localeGroup, $languages);
    }
975138
public function load($locale, $group, $namespace = null)
    {
        // Load from files
        if ($group == '*' && $namespace == '*') {
            return $this->loadJsonPaths($locale);
        }
        if (is_null($namespace) || $namespace == '*') {
            $translationsFromFiles = $this->loadPath($this->path, $locale, $group);
        } else {
            $translationsFromFiles = $this->loadNamespaced($locale, $group, $namespace);
        }

        // If group is 'db', get data from DB.
        $translationsFromDB = ($group == 'db') ? $this->loadFromDB($locale, $group, $namespace) : [];

        return array_merge($translationsFromFiles, $translationsFromDB);
    }
555189
public function jsonLDSerialize(string $context = self::DEFAULT_CONTEXT, bool $types = null)
    {
        $set = array_map(function ($m) use ($types) {
            return is_object($m) ? $m->jsonLDSerialize('', $types) : $m;
        }, $this->members);

        if (!$this->closed) {
            $set[] = null;
        }
        return $set;
    }
1340547
private function languageCompareAgainstSupportedLocales(array $aggregatedValues)
    {
        foreach ($aggregatedValues as $locale => $attributes) {
            if ('*' === $locale) {
                continue;
            }

            $localeParts = explode('-', $locale);
            if (2 !== count($localeParts)) {
                continue;
            }

            $language = $localeParts[0];

            if (in_array($language, $this->supportedLocales, true)) {
                return new NegotiatedValue($language, $attributes);
            }
        }

        return null;
    }
786829
public function determineCompletedLanguages(JsonDocument $jsonDocument)
    {
        $jsonDocument = $this->polyFillMultilingualFields($jsonDocument);
        return parent::determineCompletedLanguages($jsonDocument);
    }
422169
public function load($locale, $group, $namespace = null)
	{
		if (is_null($namespace) || $namespace == '*')
		{
			return $this->loadData($locale, $group);
		}

		return $this->loadNamespaced($locale, $group, $namespace);
	}
670360
public function toJSONI18N(Entity $entity, array $locales=[], $depth=0) {
		if(!$locales)
			$locales = $entity->getLocales();
		return json_encode($entity->toArrayI18N($locales, $depth));
	}
558198
public static function fromArray(array $collection, $localeGroup, array $languages = [], $isReadOnly = false)
    {
        $transformer = new self($collection, $localeGroup, $languages, $isReadOnly);

        return $transformer->transfer()->getFields();
    }
702145
public function get($locale, $group, $namespace)
    {
        $key = $this->getKey($locale, $group, $namespace);
        return $this->store->get($key);
    }
388322
public static function fromJson($json) {
        if (!$json) {
            $json = array();
        }

        if (!is_array($json)) {
            if (is_object($json)) {
                $json = (array) $json;
            } elseif (is_string($json)) {
                $json = json_decode(trim($json) ? $json : '{}', true);
            } else {
                throw new \InvalidArgumentException("JSON must be a string, an array or an object ('" . gettype($json) . "' provided).");
            }
        }

        return new Link(
            isset($json['href'])        ? $json['href']            : null,
            isset($json['templated'])    ? $json['templated']    : null,
            isset($json['type'])        ? $json['type']            : null,
            isset($json['deprecation'])    ? $json['deprecation']    : null,
            isset($json['name'])        ? $json['name']            : null,
            isset($json['profile'])        ? $json['profile']        : null,
            isset($json['title'])        ? $json['title']        : null,
            isset($json['hreflang'])    ? $json['hreflang']        : null
        );
    }
1309845
protected function _expandLanguageMap($language_map) {
    $rval = array();
    $keys = array_keys((array)$language_map);
    sort($keys);
    foreach($keys as $key) {
      $values = $language_map->{$key};
      $values = self::arrayify($values);
      foreach($values as $item) {
        if($item === null) {
          continue;
        }
        if(!is_string($item)) {
          throw new JsonLdException(
            'Invalid JSON-LD syntax; language map values must be strings.',
            'jsonld.SyntaxError', 'invalid language map value',
            array('languageMap', $language_map));
        }
        $rval[] = (object)array(
          '@value' => $item,
          '@language' => strtolower($key));
      }
    }
    return $rval;
  }
649095
public function getTranslationsByLocalesAndDomains($locales, $domains)
    {
        $em = $this->getEntityManager();
        $qb = $em->createQueryBuilder();
        $qb
            ->select('t')
            ->from('KunstmaanTranslatorBundle:Translation', 't')
            ->andWhere('t.status != :statusstring')
            ->setParameter('statusstring', Translation::STATUS_DISABLED)
            ->orderBy('t.domain', 'ASC')
            ->addOrderBy('t.keyword', 'ASC');

        if (count($locales) > 0) {
            $qb->andWhere($qb->expr()->in('t.locale', $locales));
        }

        if (count($domains) > 0) {
            $qb->andWhere($qb->expr()->in('t.domain', $domains));
        }

        $result = $qb
            ->getQuery()
            ->getResult();

        return $result;
    }
830984
public function getLanguageNames(array $languageCodes, $locale)
    {
        $apiCall = new ApiCall\GetLanguageNames($languageCodes, $locale);

        return $this->call($apiCall);
    }
998659
public static function fromString(string $input, string $locale): Resource
    {
        $data = json_decode($input, true);
        if (json_last_error() !== \JSON_ERROR_NONE) {
            if (function_exists('json_last_error_msg')) {
                throw new \InvalidArgumentException(json_last_error_msg(), json_last_error());
            }
            throw new \InvalidArgumentException("Error parsing JSON.", json_last_error());
        }

        return static::fromArray($data, $locale);
    }
999130
public static function jsonDeserialize(array $json): DocumentSerializationInterface
    {
        $managerClass = $json['document_serialization']['manager_class'];
        $data = (array) $json['document_serialization']['data'];

        return new self($managerClass, $data);
    }
533224
public static function fromString($str, $localeGroup = 'generic', array $languages = [], $isReadOnly = false)
    {
        // The following are the expected two formats
        // a,b,c
        // OR
        // name:a;html-type:select;options:first|second|third|fourth
        $fields = [];
        $fieldNames = array_unique(Helpers::convertStringToArray($str, ','));

        foreach ($fieldNames as $fieldName) {
            $field = [];

            if (!str_contains($fieldName, ':')) {
			
				$field['name'] = $fieldName;
				
				continue;
			}
			
			// Handle the following format
			// name:a;html-type:select;options:first|second|third|fourth
			if (!str_is('*name*:*', $fieldName)) {
				throw new Exception('The "name" property was not provided and is required!');
			}

			$parts = Helpers::convertStringToArray($fieldName, ';');

			foreach ($parts as $part) {
				
				if (!str_is('*:*', $part) || count($properties = Helpers::convertStringToArray($part, ':', 2)) != 2) {
					throw new Exception('Each provided property should use the following format "key:value"');
				}
				list($key, $value) = $properties;
				
				// The renations uses # as a delimiter
				$selfParts = Helpers::convertStringToArray($value, '#');
				
				if(LaravelStr::startsWith($key, 'is-')){
					$field[$key] = Helpers::stringToBool($value);					
				} else {
					$field[$key] = count($selfParts) > 1 ? $selfParts : $value;
				}
				
				
				if ($key == 'options') {
					$options = Helpers::convertStringToArray($value, '|');

					if (count($options) == 0) {
						throw new Exception('You must provide at least one option where each option is seperated by "|".');
					}

					$field['options'] = [];
					foreach ($options as $option) {
						$field['options'][$option] = $option;
					}
				}
			}

            $fields[] = $field;
        }
		
        return self::fromArray($fields, $localeGroup, $languages, $isReadOnly);
    }
270909
private function getValue(array $values, $languages, $group, $parent = NULL)
    {
    	foreach($values as $key => $value){

			foreach($languages as $language){
				$entry = Translation::firstOrCreate([
					'key' => $key,
					'language' => $language,
					'translation_group' => $group->id,
					'parent' => $parent
				]);
				if(is_array($value)){
					$this->getValue($value, $languages, $group, $entry->id);
				} else {
					if($entry->value === NULL){
						$entry->value = $value;
						$entry->save();
					}
				}
			}
	    }
    }