作者:instant
项目:util
/**
* Simple gate for Nette object events.
* @param string method name
* @param array arguments
* @return mixed
* @throws MemberAccessException
*/
public function __call($name, $args)
{
if ($name >= 'onA' && $name < 'on_') {
return ObjectMixin::call($this, $name, $args);
} else {
throw new MemberAccessException($name);
}
}
作者:nextra
项目:form
public static function registerControls()
{
ObjectMixin::setExtensionMethod(Container::class, 'addDatePicker', function (Container $container, $name, $label = null) {
return $container[$name] = new Controls\DatePicker($label);
});
ObjectMixin::setExtensionMethod(Container::class, 'addDateTimePicker', function (Container $container, $name, $label = null) {
return $container[$name] = new Controls\DateTimePicker($label);
});
ObjectMixin::setExtensionMethod(Container::class, 'addTypeahead', function (Container $container, $name, $label = null, $callback = null) {
return $container[$name] = new Controls\Typeahead($label, $callback);
});
}
作者:Northy
项目:d
/**
* Checks whether $config contains only $expected items and returns combined array.
* @return array
* @throws Nette\InvalidStateException
*/
public function validateConfig(array $expected, array $config = NULL, $name = NULL)
{
if (func_num_args() === 1) {
return $this->config = $this->validateConfig($expected, $this->config);
}
if ($extra = array_diff_key((array) $config, $expected)) {
$name = $name ?: $this->name;
$hint = Nette\Utils\ObjectMixin::getSuggestion(array_keys($expected), key($extra));
$extra = $hint ? key($extra) : implode(", {$name}.", array_keys($extra));
throw new Nette\InvalidStateException("Unknown configuration option {$name}.{$extra}" . ($hint ? ", did you mean {$name}.{$hint}?" : '.'));
}
return Config\Helpers::merge($config, $expected);
}
作者:Zarganwa
项目:or
public function fireEvent($method, $args = [])
{
if (!method_exists($this, $method)) {
throw new InvalidArgumentException("Event '{$method}' does not exist.");
}
$this->eventCheck = FALSE;
call_user_func_array([$this, $method], $args);
if (!$this->eventCheck) {
throw new InvalidStateException("Event '{$method}' was not correctly propagate to overwritten methods.");
}
if (property_exists($this, $method)) {
ObjectMixin::call($this, $method, $args);
}
}
作者:phpsta
项目:phpstan-nett
public function hasProperty(ClassReflection $classReflection, string $propertyName) : bool
{
$traitNames = $this->getTraitNames($classReflection->getNativeReflection());
if (!in_array(\Nette\SmartObject::class, $traitNames, true)) {
return false;
}
$property = \Nette\Utils\ObjectMixin::getMagicProperty($classReflection->getName(), $propertyName);
if ($property === null) {
return false;
}
$getterMethod = $this->getMethodByProperty($classReflection, $propertyName);
if ($getterMethod === null) {
return false;
}
return $getterMethod->isPublic();
}
作者:KinaMari
项目:securit
/**
* Removes property.
* @param string property name
* @return void
* @throws Nette\MemberAccessException
*/
public function __unset($name)
{
Nette\Utils\ObjectMixin::remove($this, $name);
}
作者:hrac
项目:nette-applicatio
public function __call($name, $args)
{
if (method_exists(ClassType::class, $name)) {
trigger_error("getReflection()->{$name}() is deprecated, use Nette\\Reflection\\ClassType::from(\$presenter)->{$name}()", E_USER_DEPRECATED);
return call_user_func_array([new ClassType($this->getName()), $name], $args);
}
Nette\Utils\ObjectMixin::strictCall(get_class($this), $name);
}
作者:WebChemistr
项目:filte
public function __get($name)
{
return ObjectMixin::get($this, $name);
}
作者:LidskaSil
项目:Doctrin
/**
* Access to undeclared property.
*
* @param string $name
*
* @throws \Nette\MemberAccessException
* @return void
*/
public function __unset($name)
{
if ($name === '_conn') {
$this->{$name} = NULL;
return;
}
ObjectMixin::remove($this, $name);
}
作者:nextra
项目:form
/**
* Returns component specified by name or path.
* @param string
* @param bool throw exception if component doesn't exist?
* @return IComponent|NULL
*/
public function getComponent($name, $need = TRUE)
{
if (isset($this->components[$name])) {
return $this->components[$name];
}
if (is_int($name)) {
$name = (string) $name;
} elseif (!is_string($name)) {
throw new Nette\InvalidArgumentException(sprintf('Component name must be integer or string, %s given.', gettype($name)));
} else {
$a = strpos($name, self::NAME_SEPARATOR);
if ($a !== FALSE) {
$ext = (string) substr($name, $a + 1);
$name = substr($name, 0, $a);
}
if ($name === '') {
if ($need) {
throw new Nette\InvalidArgumentException('Component or subcomponent name must not be empty string.');
}
return;
}
}
if (!isset($this->components[$name])) {
$component = $this->createComponent($name);
if ($component) {
if (!$component instanceof IComponent) {
throw new Nette\UnexpectedValueException('Method createComponent() did not return Nette\\ComponentModel\\IComponent.');
} elseif (!isset($this->components[$name])) {
$this->addComponent($component, $name);
}
}
}
if (isset($this->components[$name])) {
if (!isset($ext)) {
return $this->components[$name];
} elseif ($this->components[$name] instanceof IContainer) {
return $this->components[$name]->getComponent($ext, $need);
} elseif ($need) {
throw new Nette\InvalidArgumentException("Component with name '{$name}' is not container and cannot have '{$ext}' component.");
}
} elseif ($need) {
$hint = Nette\Utils\ObjectMixin::getSuggestion(array_merge(array_keys($this->components), array_map('lcfirst', preg_filter('#^createComponent([A-Z0-9].*)#', '$1', get_class_methods($this)))), $name);
throw new Nette\InvalidArgumentException("Component with name '{$name}' does not exist" . ($hint ? ", did you mean '{$hint}'?" : '.'));
}
}
作者:Vyk
项目:or
protected function fireEvent(IEntity $entity, $event)
{
if (!property_exists($this, $event)) {
throw new InvalidArgumentException("Event '{$event}' is not defined.");
}
$entity->fireEvent($event);
ObjectMixin::call($this, $event, [$entity]);
}
作者:Richmond7
项目:learning-nett
/**
* Access to undeclared property.
*
* @param string $name
*
* @throws \Nette\MemberAccessException
* @return void
*/
public function __unset($name)
{
ObjectMixin::remove($this, $name);
}
作者:ricco2
项目:databas
/**
* @param string
* @return ActiveRow|mixed
* @throws Nette\MemberAccessException
*/
public function &__get($key)
{
$this->accessColumn($key);
if (array_key_exists($key, $this->data)) {
return $this->data[$key];
}
$referenced = $this->table->getReferencedTable($this, $key);
if ($referenced !== FALSE) {
$this->accessColumn($key, FALSE);
return $referenced;
}
$this->removeAccessColumn($key);
$hint = Nette\Utils\ObjectMixin::getSuggestion(array_keys($this->data), $key);
throw new Nette\MemberAccessException("Cannot read an undeclared column '{$key}'" . ($hint ? ", did you mean '{$hint}'?" : '.'));
}
作者:filsedl
项目:hyperro
/**
* @param $key
* @return bool
*/
public function __isset($key)
{
return ObjectMixin::has($this, $key) || $this->activeRow->__isset($key);
}
作者:librett
项目:doctrine-form
private function registerReplicator()
{
if (!ObjectMixin::getExtensionMethod(SubmitButton::class, 'addCreateOnClick')) {
Replicator::register();
}
}
作者:noiki
项目:Cur
/**
* @param string $name
* @param array $args
*
* @return mixed
*/
public function __call($name, $args)
{
if (method_exists('Nette\\Utils\\ObjectMixin', 'callProperty')) {
return ObjectMixin::callProperty($this, $name, $args);
} else {
return ObjectMixin::call($this, $name, $args);
}
}
作者:JZech
项目:ZBo
/**
* Převede databázový název sloupce s lomítkama na camelFont.
* @example group_id => groupId
* @param string $name
* @return string
*/
private function normalizePropertyName($name)
{
$propertyName = $name;
if (!\Nette\Utils\ObjectMixin::has($this, $name)) {
$propertyName = '';
$nameParts = explode('_', $name);
foreach ($nameParts as $key => $partName) {
$propertyName .= $key == 0 ? $partName : ucfirst($partName);
}
}
return $propertyName;
}
作者:Northy
项目:d
/** @internal */
public function processExtensions()
{
$last = $this->getExtensions(Extensions\InjectExtension::class);
$this->extensions = array_merge(array_diff_key($this->extensions, $last), $last);
$this->config = Helpers::expand(array_diff_key($this->config, self::$reserved), $this->builder->parameters) + array_intersect_key($this->config, self::$reserved);
foreach ($first = $this->getExtensions(Extensions\ExtensionsExtension::class) as $name => $extension) {
$extension->setConfig(isset($this->config[$name]) ? $this->config[$name] : []);
$extension->loadConfiguration();
}
$extensions = array_diff_key($this->extensions, $first);
foreach (array_intersect_key($extensions, $this->config) as $name => $extension) {
$extension->setConfig($this->config[$name] ?: []);
}
foreach ($extensions as $extension) {
$extension->loadConfiguration();
}
if ($extra = array_diff_key($this->extensions, $extensions, $first)) {
$extra = implode("', '", array_keys($extra));
throw new Nette\DeprecatedException("Extensions '{$extra}' were added while container was being compiled.");
} elseif ($extra = key(array_diff_key($this->config, self::$reserved, $this->extensions))) {
$hint = Nette\Utils\ObjectMixin::getSuggestion(array_keys(self::$reserved + $this->extensions), $extra);
throw new Nette\InvalidStateException("Found section '{$extra}' in configuration, but corresponding extension is missing" . ($hint ? ", did you mean '{$hint}'?" : '.'));
}
}
作者:4iz27
项目:cvicen
private function resolveImplement(ServiceDefinition $def, $name)
{
$interface = $def->getImplement();
if (!interface_exists($interface)) {
throw new ServiceCreationException("Interface {$interface} used in service '{$name}' not found.");
}
self::checkCase($interface);
$rc = new ReflectionClass($interface);
$method = $rc->hasMethod('create') ? $rc->getMethod('create') : ($rc->hasMethod('get') ? $rc->getMethod('get') : NULL);
if (count($rc->getMethods()) !== 1 || !$method || $method->isStatic()) {
throw new ServiceCreationException("Interface {$interface} used in service '{$name}' must have just one non-static method create() or get().");
}
$def->setImplementType($methodName = $rc->hasMethod('create') ? 'create' : 'get');
if (!$def->getClass() && !$def->getEntity()) {
$returnType = PhpReflection::getReturnType($method);
if (!$returnType) {
throw new ServiceCreationException("Method {$interface}::{$methodName}() used in service '{$name}' has no @return annotation.");
} elseif (!class_exists($returnType)) {
throw new ServiceCreationException("Check a @return annotation of the {$interface}::{$methodName}() method used in service '{$name}', class '{$returnType}' cannot be found.");
}
$def->setClass($returnType);
}
if ($methodName === 'get') {
if ($method->getParameters()) {
throw new ServiceCreationException("Method {$interface}::get() used in service '{$name}' must have no arguments.");
}
if (!$def->getEntity()) {
$def->setFactory('@\\' . ltrim($def->getClass(), '\\'));
} elseif (!$this->getServiceName($def->getFactory()->getEntity())) {
throw new ServiceCreationException("Invalid factory in service '{$name}' definition.");
}
}
if (!$def->parameters) {
$ctorParams = array();
if (!$def->getEntity()) {
$def->setFactory($def->getClass(), $def->getFactory() ? $def->getFactory()->arguments : array());
}
if (($class = $this->resolveEntityClass($def->getFactory(), array($name => 1))) && ($rc = new ReflectionClass($class)) && ($ctor = $rc->getConstructor())) {
foreach ($ctor->getParameters() as $param) {
$ctorParams[$param->getName()] = $param;
}
}
foreach ($method->getParameters() as $param) {
$hint = PhpReflection::getParameterType($param);
if (isset($ctorParams[$param->getName()])) {
$arg = $ctorParams[$param->getName()];
if ($hint !== PhpReflection::getParameterType($arg)) {
throw new ServiceCreationException("Type hint for \${$param->getName()} in {$interface}::{$methodName}() doesn't match type hint in {$class} constructor.");
}
$def->getFactory()->arguments[$arg->getPosition()] = self::literal('$' . $arg->getName());
} elseif (!$def->getSetup()) {
$hint = Nette\Utils\ObjectMixin::getSuggestion(array_keys($ctorParams), $param->getName());
throw new ServiceCreationException("Unused parameter \${$param->getName()} when implementing method {$interface}::{$methodName}()" . ($hint ? ", did you mean \${$hint}?" : '.'));
}
$paramDef = $hint . ' ' . $param->getName();
if ($param->isOptional()) {
$def->parameters[$paramDef] = $param->getDefaultValue();
} else {
$def->parameters[] = $paramDef;
}
}
}
}
作者:nett
项目:finde
public static function extensionMethod($name, $callback)
{
Nette\Utils\ObjectMixin::setExtensionMethod(__CLASS__, $name, $callback);
}