Create and return a Closure available to write an object property through a property path or a private property.

@return \Closure
437757
private function createWrittingDelegate()
    {
        return $this->writeDelegate ?: $this->writeDelegate = function (PropertyPathInterface $property, $value, PropertyAccessor $propertyAccessor) {
            switch (true) {

                // Public property / accessor case
                case $propertyAccessor->isWritable($this, $property) :
                    return $propertyAccessor->setValue($this, $property, $value);

                // Private property / StdClass
                case property_exists($this, $property) || $this instanceof \StdClass :
                    return $this->$property = $value;
            }

            throw new InvalidScopeException(sprintf(
                'Unable to set "%s" property into a "%s" object, any existing property path to write it in.',
                $property,
                get_class($this)
            ));
        };
    }
467238
private function makeReflection()
    {
        if ($this->reflection === null) {
            $this->reflection = new \ReflectionProperty($this->className, $this->name);

            $this->reflection->setAccessible(true);
        }
    }
199706
private function export()
    {
        $exported = new StdClass;
        foreach ($this as $name => $field) {
            if ((new ReflectionProperty($this, $name))->isPublic()) {
                if (is_object($field)) {
                    $traits = class_uses($field);
                    if (isset($traits['Ornament\Model'])
                        || isset($traits['Ornament\JsonModel'])
                    ) {
                        $exported->$name = $field->getPrimaryKey();
                    } else {
                        $exported->$name = "$field";
                    }
                } else {
                    $exported->$name = $field;
                }
            }
        }
        return $exported;
    }
1202831
public static function prop(string $property, Closure $closure)
  {
    $trace = debug_backtrace()[1];

    if (
      $trace['class'] == 'Modulus\Framework\Upstart\Prototype' &&
      $trace['function'] == 'prop' &&
      count($trace['args']) == 3
    ) {
      if (!array_key_exists($property, Self::$properties)) {
        return Self::$properties[$property] = [$property => $closure];
      }

      throw new CannotAddPropertyException;
    }

    throw new CannotCallMethodException('Call to ' . self::class . '::prop() is not allowed');
  }
601294
public static function make($properties, Closure $callback = null)
    {
        $item = new self($properties);

        if (is_callable($callback)) {
            call_user_func($callback, $item);
        }

        return $item;
    }
423465
public function createConst() {

		$properties = get_object_vars($this);

		if(isset($properties['db'])) {
			foreach($properties['db'] as $k => $v) {
				if(is_scalar($v)) {
					$k = strtoupper($k);
					if(!defined("DB$k")) { define("DB$k", $v); }
				}
			}
		}

		if(isset($properties['site'])) {
			foreach($properties['site'] as $k => $v) {
				if(is_scalar($v)) {
					$k = strtoupper($k);
					if(!defined($k)) { define($k, $v); }
				}
			}
		}

		if(isset($properties['paths'])) {
			foreach($properties['paths'] as $k => $v) {
				$k = strtoupper($k);
				if(!defined($k)) { define($k, $v['subdir']); }
			}
		}

		$locale = localeconv();

		foreach($locale as $k => $v) {
			$k = strtoupper($k);
			if(!defined($k) && !is_array($v)) { define($k, $v); }
		}
	}
884158
public function getConcrete()
    {
        if ($this->instance) {
            return $this->instance;
        }

        if (is_object($this->concrete) || $this->concrete instanceof Closure) {
            $instance = $this->concrete;
        } else {
            $instance = $this->context->getContainer()->make($this->concrete);
        }

        if (! $this->isDynamic()) {
            $this->checkConcreteInstance($instance);
        }

        return $this->instance = $instance;
    }
1205728
protected function serializeClosure(Closure $closure)
    {
        $closure = (new Serializer())->serialize($closure);
        $serializedClosure = \http_build_query([$closure]);
        $crunzRoot = CRUNZ_BIN;

        return PHP_BINARY . " {$crunzRoot} closure:run {$serializedClosure}";
    }
1132738
protected function bindExpectedToObject()
    {
        $accessor = PropertyAccess::createPropertyAccessor();

        $values = array_merge($this->expectedValues, $this->expectedMocks, $this->expectedMocksCollections);

        foreach ($values as $property => $value) {
            if (is_array($value)) {
                $addMethod = 'add'.ucfirst($property);
                foreach ($value as $mock) {
                    $this->getObjectToTest()->$addMethod($mock);
                }
            } else {
                if ($accessor->isWritable($this->getObjectToTest(), $property)) {
                    // Use direct access to property to avoid "only variables should be passed by reference"
                    $accessor->setValue($this->objectToTest, $property, $value);
                }
            }
        }

        // Tear down
        unset($values);
        unset($accessor);

        return $this;
    }
1052442
public function serialize()
    {
        SerializableClosure::enterContext();

        $engines = $this->engines;

        foreach ($engines as &$engine) {
            if ($engine[0] instanceof \Closure) {
                $engine[0] = SerializableClosure::from($engine[0]);
            }
        }

        $object = serialize([
            'engines' => $engines,
            'renderer' => $this->renderer
        ]);

        SerializableClosure::exitContext();

        return $object;
    }
99247
public function prop(string $class, string $property, Closure $closure)
  {
    if (!class_exists($class)) throw new ClassDoesNotExistException("Class {$class} does not exist");

    if (!in_array(
      Extendable::class,
      array_keys((new ReflectionClass($class))->getTraits()))
    ) {
      throw new CannotExtendClassException("Cannot extend \"{$class}::class\"");
    }

    return $class::prop($property, $closure);
  }
103156
protected function getSlice()
	{
		return function($stack, $pipe)
		{
			return function($passable) use ($stack, $pipe)
			{
				// If the pipe is an instance of a Closure, we will just call it directly but
				// otherwise we'll resolve the pipes out of the container and call it with
				// the appropriate method and arguments, returning the results back out.
				if ($pipe instanceof Closure)
				{
					return call_user_func($pipe, $passable, $stack);
				}
				else
				{
					return $this->container->make($pipe)
							->{$this->method}($passable, $stack);
				}
			};
		};
	}
458444
public function createPath()
    {
        if ($this->isReference()) {
            throw $this->noChildrenAllowed();
        }
        $p = new Path($this->project);
        $this->elements[] = $p;
        $this->checked = false;

        return $p;
    }
47204
public function create()
    {
        $instance = self::createVariant($this);
        $this->setId($instance->getId());
        return $instance;
    }
1174156
public static function rowMapper(): Closure
    {
        return static function (stdClass $row): Media {
            return Media::getInstance($row->m_id, Tree::findById((int) $row->m_file), $row->m_gedcom);
        };
    }
111991
private static function &getStaticProperty($object, string $property)
  {
    $value = &\Closure::bind(function & () use ($property) {
      return self::$$property;
    }, $object, $object)->__invoke();

    return $value;
  }
419459
public static function rowMapper(): Closure
    {
        return static function (stdClass $row): User {
            return new static((int) $row->user_id, $row->user_name, $row->real_name, $row->email);
        };
    }