array(), 'fail' => array() ); if (empty($dependencies)) { return array(); } $dependencies = explode(',', $this->removeSpaces($dependencies)); foreach ($dependencies as $key => $module) { if (!empty($module)) { if (preg_match(self::REGEX_MACHINE_NAME, $module)) { $dependencies_checked['success'][] = $module; } else { $dependencies_checked['fail'][] = $module; } } } return $dependencies_checked; } /** * Validate if module name exist * @param string $module Module name * @param array $modules List of modules * @return string */ public function validateModuleExist($module, $modules) { if (!in_array($module, array_values($modules))) { throw new \InvalidArgumentException(sprintf( 'Module "%s" is not in your application. Try generate:module to create it.', $module) ); } return $module; } /** * Validate if service name exist * @param string $service Service name * @param array $services Array of services * @return string */ public function validateServiceExist($service, $services) { if ($service == '') { return null; } if (!in_array($service, array_values($services))) { throw new \InvalidArgumentException(sprintf("Service \"%s\" is invalid.", $service)); } return $service; } /** * Validate if a string is a valid cache * @param string $cache The cache name * @return mixed The cache name if valid or FALSE if not valid */ public function validateCache($cache) { // Get the valid caches $caches = $this->getCaches(); $cache_keys = array_keys($caches); $cache_keys[] = 'all'; if (!in_array($cache, array_values($cache_keys))) { return false; } return $cache; } /** * Validates if class name have spaces between words * @param string $name * @return string */ public function validateSpaces($name) { $string = $this->removeSpaces($name); if ($string == $name) { return $name; } else { throw new \InvalidArgumentException(sprintf("The name \"%s\" is invalid, spaces between words are not allowed.", $name)); } } public function removeSpaces($name) { return preg_replace(self::REGEX_REMOVE_SPACES, '', $name); } public function getName() { return "validators"; } /** * Auxiliary function to get all available drupal caches * @return array The all available drupal caches */ public function getCaches() { if (empty($this->caches)) { foreach (Cache::getBins() as $name => $bin) { $this->caches[$name] = $bin; } } return $this->caches; } }