本文整理汇总了PHP中Doctrine\Common\Inflector\Inflector::classify方法的典型用法代码示例。如果您正苦于以下问题:PHP Inflector::classify方法的具体用法?PHP Inflector::classify怎么用?PHP Inflector::classify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Inflector\Inflector
的用法示例。
在下文中一共展示了Inflector::classify方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postBuild
/**
* Execute after types are built.
*/
public function postBuild()
{
$types_build_path = $this->getBuildPath() ? "{$this->getBuildPath()}/types.php" : null;
if ($types_build_path) {
$result = [];
$result[] = '<?php';
$result[] = '';
if ($this->getStructure()->getConfig('header_comment')) {
$result = array_merge($result, explode("\n", $this->getStructure()->getConfig('header_comment')));
$result[] = '';
}
$namespace = $this->getStructure()->getNamespace();
if ($namespace) {
$namespace = ltrim($namespace, '\\');
}
if ($this->getStructure()->getNamespace()) {
$result[] = '/**';
$result[] = ' * @package ' . $this->getStructure()->getNamespace();
$result[] = ' */';
}
$result[] = 'return [';
foreach ($this->getStructure()->getTypes() as $current_type) {
$result[] = ' ' . var_export($namespace . '\\' . Inflector::classify(Inflector::singularize($current_type->getName())), true) . ',';
}
$result[] = '];';
$result[] = '';
$result = implode("\n", $result);
if (is_file($types_build_path) && file_get_contents($types_build_path) === $result) {
return;
} else {
file_put_contents($types_build_path, $result);
$this->triggerEvent('on_types_built', [$types_build_path]);
}
}
}
示例2: camelize
/**
* {@inheritdoc}
*/
public function camelize($str)
{
if (isset($this->rules['camelize'][$str])) {
return $this->rules['camelize'][$str];
}
return DoctrineInflector::classify($str);
}
示例3: validate
public function validate(Request $request, array $rules)
{
$valid = true;
foreach ($rules as $field => $rule) {
if (is_null($rule) || !is_string($rule) || strlen($rule) == 0) {
throw new ValidationException("Rule must be a string");
}
// get field value
$value = $request->input($field);
// split validation rule into required / sometimes (no validation if not set or empty)
// contract and contract parameters
$parts = explode("|", $rule);
if (is_null($parts) || !is_array($parts) || count($parts) < 3) {
throw new ValidationException("Invalid rule");
}
$required = strtolower($parts[0]) == "required" ? true : false;
if ($required && is_null($value)) {
$valid = false;
continue;
}
$args = explode(":", $parts[1]);
$clazz = Inflector::classify($args[0]) . "Contract";
if (!class_exists($clazz)) {
throw new ValidationException("Invalid rule: invalid validation class '{$clazz}'");
}
$instance = new $clazz($value, isset($args[1]) ? $args[1] : array());
if (!$instance instanceof Contract) {
throw new ValidationException("Invalid rule: invalid validation class '{$clazz}'. Class must extend Simplified\\Validator\\Contract");
}
if (!$instance->isValid()) {
$valid = false;
}
}
return $valid;
}
示例4: process
/**
* {@inheritDoc}
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition(self::SERVICE_KEY)) {
return;
}
// find providers
$providers = [];
$taggedServices = $container->findTaggedServiceIds(self::TAG);
foreach ($taggedServices as $id => $attributes) {
if (empty($attributes[0]['scope'])) {
throw new InvalidConfigurationException(sprintf('Tag attribute "scope" is required for "%s" service', $id));
}
$priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
$scope = $attributes[0]['scope'];
$providers[$scope][$priority][] = new Reference($id);
}
if (empty($providers)) {
return;
}
// add to chain
$serviceDef = $container->getDefinition(self::SERVICE_KEY);
foreach ($providers as $scope => $items) {
// sort by priority and flatten
krsort($items);
$items = call_user_func_array('array_merge', $items);
// register
foreach ($items as $provider) {
$serviceDef->addMethodCall(sprintf('add%sVariablesProvider', Inflector::classify($scope)), [$provider]);
}
}
}
示例5: getParametersFromObject
/**
* @param $keys
* @param $object
* @return array
*/
protected function getParametersFromObject($keys, $object)
{
$parameters = [];
foreach ($keys as $key) {
$relation = $object;
$method = 'get' . Inflector::classify($key);
if (method_exists($relation, $method)) {
$relation = $relation->{$method}();
} else {
$segments = explode('_', $key);
if (count($segments) > 1) {
foreach ($segments as $segment) {
$method = 'get' . Inflector::classify($segment);
if (method_exists($relation, $method)) {
$relation = $relation->{$method}();
} else {
$relation = $object;
break;
}
}
}
}
if ($object !== $relation) {
$parameters[$key] = $relation;
}
}
return $parameters;
}
示例6: buildType
/**
* @param TypeInterface $type
*/
public function buildType(TypeInterface $type)
{
$class_name = Inflector::classify(Inflector::singularize($type->getName()));
$base_class_name = 'Base\\' . $class_name;
$class_build_path = $this->getBuildPath() ? "{$this->getBuildPath()}/{$class_name}.php" : null;
if ($class_build_path && is_file($class_build_path)) {
$this->triggerEvent('on_class_build_skipped', [$class_name, $class_build_path]);
return;
}
$result = [];
$result[] = '<?php';
$result[] = '';
if ($this->getStructure()->getConfig('header_comment')) {
$result = array_merge($result, explode("\n", $this->getStructure()->getConfig('header_comment')));
$result[] = '';
}
if ($this->getStructure()->getNamespace()) {
$result[] = 'namespace ' . $this->getStructure()->getNamespace() . ';';
$result[] = '';
$result[] = '/**';
$result[] = ' * @package ' . $this->getStructure()->getNamespace();
$result[] = ' */';
}
$result[] = 'class ' . $class_name . ' extends ' . $base_class_name;
$result[] = '{';
$result[] = '}';
$result[] = '';
$result = implode("\n", $result);
if ($this->getBuildPath()) {
file_put_contents($class_build_path, $result);
} else {
eval(ltrim($result, '<?php'));
}
$this->triggerEvent('on_class_built', [$class_name, $class_build_path]);
}
示例7: __call
/**
* Catch all getter and setter
*
* @param string $name
* @param array $arguments
*
* @return mixed
*/
public function __call($name, $arguments)
{
// Match the getters
if (substr($name, 0, 3) == 'get') {
$parameter = Inflector::tableize(substr($name, 3));
if (property_exists($this, $parameter)) {
return $this->{$parameter};
} else {
throw new \Exception(sprintf('The property "%s" does not exist.', $parameter));
}
}
// Match the setters
if (substr($name, 0, 3) == 'set') {
$parameter = Inflector::tableize(substr($name, 3));
$method = 'set' . Inflector::classify($parameter);
if (method_exists($this, $method)) {
return $this->{$method}($arguments[0]);
} else {
if (property_exists($this, $parameter) && isset($arguments[0])) {
$this->{$parameter} = $arguments[0];
return $this;
} else {
throw new \Exception(sprintf('The property "%s" does not exist.', $parameter));
}
}
}
}
示例8: getDirection
/**
* {@inheritdoc}
*/
public function getDirection($activity, $target)
{
//check if target is entity created from admin part
if (!$target instanceof EmailHolderInterface) {
$metadata = $this->doctrineHelper->getEntityMetadata($target);
$columns = $metadata->getColumnNames();
$className = get_class($target);
foreach ($columns as $column) {
//check only columns with 'contact_information'
if ($this->isEmailType($className, $column)) {
$getMethodName = "get" . Inflector::classify($column);
/** @var $activity Email */
if ($activity->getFromEmailAddress()->getEmail() === $target->{$getMethodName}()) {
return DirectionProviderInterface::DIRECTION_OUTGOING;
} else {
foreach ($activity->getTo() as $recipient) {
if ($recipient->getEmailAddress()->getEmail() === $target->{$getMethodName}()) {
return DirectionProviderInterface::DIRECTION_INCOMING;
}
}
}
}
}
return DirectionProviderInterface::DIRECTION_UNKNOWN;
}
/** @var $activity Email */
/** @var $target EmailHolderInterface */
if ($activity->getFromEmailAddress()->getEmail() === $target->getEmail()) {
return DirectionProviderInterface::DIRECTION_OUTGOING;
}
return DirectionProviderInterface::DIRECTION_INCOMING;
}
示例9: reverseTransform
/**
* @param Request $request
* @param string $id
* @param string $type
* @param string $event
* @param string $eventClass
*
* @return Response
*/
protected function reverseTransform(Request $request, $id, $type, $event, $eventClass)
{
$facadeName = Inflector::classify($type) . 'Facade';
$typeName = Inflector::tableize($type);
$format = $request->get('_format', 'json');
$facade = $this->get('jms_serializer')->deserialize($request->getContent(), 'OpenOrchestra\\ApiBundle\\Facade\\' . $facadeName, $format);
$mixed = $this->get('open_orchestra_model.repository.' . $typeName)->find($id);
$oldStatus = null;
if ($mixed instanceof StatusableInterface) {
$oldStatus = $mixed->getStatus();
}
$mixed = $this->get('open_orchestra_api.transformer_manager')->get($typeName)->reverseTransform($facade, $mixed);
if ($this->isValid($mixed)) {
$em = $this->get('object_manager');
$em->persist($mixed);
$em->flush();
if (in_array('OpenOrchestra\\ModelInterface\\Event\\EventTrait\\EventStatusableInterface', class_implements($eventClass))) {
$this->dispatchEvent($event, new $eventClass($mixed, $oldStatus));
return array();
}
$this->dispatchEvent($event, new $eventClass($mixed));
return array();
}
return $this->getViolations();
}
示例10: addTest
public function addTest($testName)
{
$methodName = 'test' . Inflector::classify($testName);
$testMethod = new ClassMethod($methodName, array(), array());
$testMethod->setScope('public');
$this->methods[] = $testMethod;
return $testMethod;
}
示例11: create
/**
* Create platform function node.
*
* @param string $platformName
* @param string $functionName
* @param array $parameters
* @throws \Doctrine\ORM\Query\QueryException
* @return PlatformFunctionNode
*/
public static function create($platformName, $functionName, array $parameters)
{
$className = __NAMESPACE__ . '\\Platform\\Functions\\' . Inflector::classify(strtolower($platformName)) . '\\' . Inflector::classify(strtolower($functionName));
if (!class_exists($className)) {
throw QueryException::syntaxError(sprintf('Function "%s" does not supported for platform "%s"', $functionName, $platformName));
}
return new $className($parameters);
}
示例12: parseResult
/**
* Parse a response body into a collection
*
* @param string $data
*
* @return ResultCollection
*/
public static function parseResult($data)
{
$responseBody = json_decode($data, true);
$rootKey = self::getRootKey($responseBody);
$data = self::getResultForRootKey($responseBody, $rootKey);
$className = Inflector::classify($rootKey);
$result = new Result();
return $result->fromArrayWithObject($data, $className);
}
示例13: instantiate
public function instantiate(string $class, array $data)
{
$object = new $class();
foreach ($data as $key => $value) {
$method = 'set' . Inflector::classify($key);
$object->{$method}($value);
}
return $object;
}
示例14: getHandler
public function getHandler($alias)
{
$className = Inflector::classify($alias);
$handlerClass = sprintf('\\%s\\%sHandler', $this->handlerNamespace, $className);
if (!class_exists($handlerClass)) {
throw new \RuntimeException('The specified handler class does not exist: ' . $handlerClass);
}
return new $handlerClass($this->typeHandler);
}
示例15: getActionClassFromControllerName
/**
* @param string $controller
* @return string
*/
public static function getActionClassFromControllerName($controller)
{
$actionNameStart = strpos($controller, ':') + 1;
$actionNameLength = strrpos($controller, 'Action') - $actionNameStart;
$actionName = substr($controller, $actionNameStart, $actionNameLength);
$actionName = Inflector::classify($actionName);
$refl = new \ReflectionClass(Action::class);
return $refl->getNamespaceName() . '\\' . $actionName;
}