Add 'src/BeSimple/SoapBundle/' from commit 'e99f707b105c0a0472260d8d42a5a14a7fb7a211'
git-subtree-dir: src/BeSimple/SoapBundle git-subtree-mainline:9a8d23fa23
git-subtree-split:e99f707b10
This commit is contained in:
33
src/BeSimple/SoapBundle/Util/Assert.php
Normal file
33
src/BeSimple/SoapBundle/Util/Assert.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the BeSimpleSoapBundle.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapBundle\Util;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Kerl <christian-kerl@web.de>
|
||||
*/
|
||||
class Assert
|
||||
{
|
||||
const ARGUMENT_INVALID = 'Argument "%s" is invalid.';
|
||||
const ARGUMENT_NULL = 'Argument "%s" can not be null.';
|
||||
|
||||
public static function thatArgument($name, $condition, $message = self::ARGUMENT_INVALID)
|
||||
{
|
||||
if(!$condition) {
|
||||
throw new \InvalidArgumentException(sprintf($message, $name));
|
||||
}
|
||||
}
|
||||
|
||||
public static function thatArgumentNotNull($name, $value)
|
||||
{
|
||||
self::thatArgument($name, null !== $value, self::ARGUMENT_NULL);
|
||||
}
|
||||
}
|
65
src/BeSimple/SoapBundle/Util/Collection.php
Normal file
65
src/BeSimple/SoapBundle/Util/Collection.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the BeSimpleSoapBundle.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapBundle\Util;
|
||||
|
||||
class Collection implements \IteratorAggregate, \Countable
|
||||
{
|
||||
private $elements = array();
|
||||
private $getter;
|
||||
private $class;
|
||||
|
||||
public function __construct($getter, $class = null)
|
||||
{
|
||||
$this->getter = $getter;
|
||||
$this->class = $class;
|
||||
}
|
||||
|
||||
public function add($element)
|
||||
{
|
||||
if ($this->class && !$element instanceof $this->class) {
|
||||
throw new \InvalidArgumentException(sprintf('Cannot add class "%s" because it is not an instance of "%s"', get_class($element), $this->class));
|
||||
}
|
||||
|
||||
$this->elements[$element->{$this->getter}()] = $element;
|
||||
}
|
||||
|
||||
public function addAll($elements)
|
||||
{
|
||||
foreach ($elements as $element) {
|
||||
$this->add($element);
|
||||
}
|
||||
}
|
||||
|
||||
public function has($key)
|
||||
{
|
||||
return isset($this->elements[$key]);
|
||||
}
|
||||
|
||||
public function get($key)
|
||||
{
|
||||
return $this->has($key) ? $this->elements[$key] : null;
|
||||
}
|
||||
|
||||
public function clear()
|
||||
{
|
||||
$this->elements = array();
|
||||
}
|
||||
|
||||
public function count()
|
||||
{
|
||||
return count($this->elements);
|
||||
}
|
||||
|
||||
public function getIterator()
|
||||
{
|
||||
return new \ArrayIterator($this->elements);
|
||||
}
|
||||
}
|
62
src/BeSimple/SoapBundle/Util/QName.php
Normal file
62
src/BeSimple/SoapBundle/Util/QName.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the BeSimpleSoapBundle.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapBundle\Util;
|
||||
|
||||
/**
|
||||
* @author Christian Kerl <christian-kerl@web.de>
|
||||
*/
|
||||
class QName
|
||||
{
|
||||
private $namespace;
|
||||
private $name;
|
||||
|
||||
public static function isPrefixedQName($qname)
|
||||
{
|
||||
return false !== strpos($qname, ':') ? true : false;
|
||||
}
|
||||
|
||||
public static function fromPrefixedQName($qname, $resolveNamespacePrefixCallable)
|
||||
{
|
||||
Assert::thatArgument('qname', self::isPrefixedQName($qname));
|
||||
|
||||
list($prefix, $name) = explode(':', $qname);
|
||||
|
||||
return new self(call_user_func($resolveNamespacePrefixCallable, $prefix), $name);
|
||||
}
|
||||
|
||||
public static function fromPackedQName($qname)
|
||||
{
|
||||
Assert::thatArgument('qname', preg_match('/^\{(.+)\}(.+)$/', $qname, $matches));
|
||||
|
||||
return new self($matches[1], $matches[2]);
|
||||
}
|
||||
|
||||
public function __construct($namespace, $name)
|
||||
{
|
||||
$this->namespace = $namespace;
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function getNamespace()
|
||||
{
|
||||
return $this->namespace;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return sprintf('{%s}%s', $this->getNamespace(), $this->getName());
|
||||
}
|
||||
}
|
49
src/BeSimple/SoapBundle/Util/String.php
Normal file
49
src/BeSimple/SoapBundle/Util/String.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the BeSimpleSoapBundle.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapBundle\Util;
|
||||
|
||||
/**
|
||||
* String provides utility methods for strings.
|
||||
*
|
||||
* @author Christian Kerl <christian-kerl@web.de>
|
||||
*/
|
||||
class String
|
||||
{
|
||||
/**
|
||||
* Checks if a string starts with a given string.
|
||||
*
|
||||
* @param string $str A string
|
||||
* @param string $substr A string to check against
|
||||
*
|
||||
* @return bool True if str starts with substr
|
||||
*/
|
||||
public static function startsWith($str, $substr)
|
||||
{
|
||||
if(is_string($str) && is_string($substr) && strlen($str) >= strlen($substr)) {
|
||||
return $substr == substr($str, 0, strlen($substr));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a string ends with a given string.
|
||||
*
|
||||
* @param string $str A string
|
||||
* @param string $substr A string to check against
|
||||
*
|
||||
* @return bool True if str ends with substr
|
||||
*/
|
||||
public static function endsWith($str, $substr)
|
||||
{
|
||||
if(is_string($str) && is_string($substr) && strlen($str) >= strlen($substr)) {
|
||||
return $substr == substr($str, strlen($str) - strlen($substr));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user