Lifted from the gaufrette library
{@inheritDoc}
18898
public function exists($file)
    {
        $lines = ftp_rawlist($this->connection(), '-1t ' . dirname($file));
        if (false === $lines) {
            return false;
        }

        $pattern = '{(?<!->) ' . preg_quote(basename($file)) . '( -> |$)}m';
        foreach ($lines as $line) {
            if (preg_match($pattern, $line)) {
                return true;
            }
        }

        return false;
    }
830758
public static function collect(string $className, $objectAnnotation = null, string $propertyName = '', string $methodName = '', $propertyValue = null)
    {
        // collect service
        if ($objectAnnotation instanceof Service) {

            $rc = new \ReflectionClass($className);
            $interfaces = $rc->getInterfaceNames();
            $methods = $rc->getMethods(\ReflectionMethod::IS_PUBLIC);
            $version = $objectAnnotation->getVersion();

            foreach ($interfaces as $interfaceClass){
                foreach ($methods as $method){
                    $methodName = $method->getName();
                    self::$serviceMapping[$interfaceClass][$version][$methodName] = [$className, $methodName];
                }
            }

            return;
        }
    }
673133
public function repeat(int $count = -1): Observable
    {
        if ($count === 0) {
            return self::empty();
        }

        return $this->lift(function () use ($count) {
            return new RepeatOperator($count);
        });
    }
840297
protected function normalizeRelation(PropertyMetadata $propertyMetadata, $relatedObject, string $resourceClass, ?string $format, array $context)
    {
        if (null === $relatedObject) {
            if (isset($context['operation_type'], $context['subresource_resources'][$resourceClass]) && OperationType::SUBRESOURCE === $context['operation_type']) {
                $iri = $this->iriConverter->getItemIriFromResourceClass($resourceClass, $context['subresource_resources'][$resourceClass]);
            } else {
                unset($context['resource_class']);

                if ($this->serializer instanceof NormalizerInterface) {
                    return $this->serializer->normalize($relatedObject, $format, $context);
                }
                throw new LogicException(sprintf('The injected serializer must be an instance of "%s".', NormalizerInterface::class));
            }
        } else {
            $iri = $this->iriConverter->getIriFromItem($relatedObject);
            $context['iri'] = $iri;

            if (isset($context['resources'])) {
                $context['resources'][$iri] = $iri;
            }
            if (isset($context['api_included'])) {
                if (!$this->serializer instanceof NormalizerInterface) {
                    throw new LogicException(sprintf('The injected serializer must be an instance of "%s".', NormalizerInterface::class));
                }

                return $this->serializer->normalize($relatedObject, $format, $context);
            }
        }

        return [
            'data' => [
                'type' => $this->resourceMetadataFactory->create($resourceClass)->getShortName(),
                'id' => $iri,
            ],
        ];
    }
1367531
public function pull($key, $valueDefault = null)
    {
        return Arrays::pull($this->data, $key, $valueDefault);
    }
601996
public function pull($key)
    {
        if (!$this->containsKey($key)) {
            return null;
        }
        $removed = $this->items[$key];
        unset($this->items[$key]);

        return $removed;
    }
1109053
public function bulkSerialise($model)
    {
        $class = get_class($model);
        if (!$model instanceof Model) {
            throw new InvalidOperationException($class);
        }
        // dig up metadata
        if (!isset(self::$metadataCache[$class])) {
            self::$metadataCache[$class] = $model->metadata();
        }
        $meta = self::$metadataCache[$class];
        $keys = array_keys($meta);
        // dig up getter list - we only care about the mutators that end up in metadata
        if (!isset(self::$mutatorCache[$class])) {
            $getterz = [];
            $datez = $model->getDates();
            $castz = $model->retrieveCasts();
            foreach ($keys as $key) {
                if ($model->hasGetMutator($key) || in_array($key, $datez) || array_key_exists($key, $castz)) {
                    $getterz[] = $key;
                }
            }
            self::$mutatorCache[$class] = $getterz;
        }
        $getterz = self::$mutatorCache[$class];
        $modelAttrib = $model->getAttributes();
        $result = array_intersect_key($modelAttrib, $meta);
        foreach ($keys as $key) {
            if (!isset($result[$key])) {
                $result[$key] = null;
            }
        }
        foreach ($getterz as $getter) {
            $result[$getter] = $model->$getter;
        }

        return $result;
    }
358272
public function pluck($array, $property, &$return = false)
    {
        $return = [];

        if (count($array) > 0) {
            foreach ($array as $item) {
                if (is_array($item)) {
                    $this->pluck($array, $property, $return);
                }

                $return[] = $item->$property;
            }
        }

        return $return;
    }
31472
public function get(
        $where = null,
        $order = null,
        $limit = null,
        $offset = null,
        $columns = null,
        $group = null,
        $having = null
    ) {
        $result = parent::get($where, $order, $limit, $offset, $columns, $group, $having);
        return $result;
    }
1152560
private function getFilteredFormatter(Throwable $e, ServerRequestInterface $request): FormatterInterface
    {
        $filtered = $this->formatters;

        foreach ($filtered as $index => $formatter) {
            // *** isVerbose Filter ***
            if (! $this->shouldBeVerbose) {
                if ($formatter->isVerbose()) {
                    unset($filtered[$index]);

                    continue;
                }
            }
            // *** CanFormat Filter ***
            if (! $formatter->canFormat($e)) {
                unset($filtered[$index]);

                continue;
            }
            // *** Content-Type Filter ***
            if (! $this->isAcceptableContentType($request, $formatter->contentType())) {
                unset($filtered[$index]);

                continue;
            }
        }

        // use a default formatter if there is none present after applying the filters. Else use the first one present in the array.
        // TODO : attention on devrait lever une exception si il n'y a pas de default formatter de défini par l'utilisateur, ou alors à minima on fait un rethrow de l'exception.
        return reset($filtered) ?: $this->defaultFormatter;
    }
1256129
@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		final String methodName = method.getName();
		// != for perf (strings interned: != is ok)
		if ("include" != methodName && "forward" != methodName) { // NOPMD
			return method.invoke(requestDispatcher, args);
		}
		boolean systemError = false;
		try {
			final String pathWithoutParameters;
			final int indexOf = path.indexOf('?');
			if (indexOf != -1) {
				pathWithoutParameters = path.substring(0, indexOf);
			} else {
				pathWithoutParameters = path;
			}
			JSP_COUNTER.bindContextIncludingCpu(pathWithoutParameters);
			return method.invoke(requestDispatcher, args);
		} catch (final InvocationTargetException e) {
			if (e.getCause() instanceof Error) {
				// on catche Error pour avoir les erreurs systèmes
				// mais pas Exception qui sont fonctionnelles en général
				systemError = true;
			}
			throw e;
		} finally {
			// on enregistre la requête dans les statistiques
			JSP_COUNTER.addRequestForCurrentContext(systemError);
		}
	}
972022
public function read(&$result)
    {
        $relations = [];
        $conditions = [];

        foreach ($result as $i => $entity) {
            foreach ($this->definition->localKeys() as $local => $refer) {
                $conditions[$refer][] = $this->accessor->getPropertyValue($entity, $local);
            }

            $relations[$this->buildLocalKey($entity, $this->definition->localKeys())][] = &$result[$i];
        }

        $collection = $this->fetch($this->definition->mediator(), $conditions, false);

// --- MEDIATOR START

        $mediator = [];
        $conditions = [];
        foreach ($collection as $entity) {
            foreach ($this->definition->foreignKeys() as $local => $refer) {
                $conditions[$refer][] = $this->accessor->getPropertyValue($entity, $local);
            }

            $in = $this->buildForeignKey($entity, $this->definition->localKeys());
            $out = $this->buildLocalKey($entity, $this->definition->foreignKeys());
            $mediator[$out][] = $in;
        }

        $collection = $this->fetch($this->definition->entity(), $conditions, true);

// --- MEDIATOR END

        foreach ($collection as $relEntity) {
            $key = $this->buildForeignKey($relEntity, $this->definition->foreignKeys());

            if (!isset($mediator[$key])) {
                continue;
            }
            foreach ($mediator[$key] as $mkey) {
                if (!isset($relations[$mkey])) {
                    continue;
                }

                foreach ($relations[$mkey] as &$entity) {
                    $this->accessor->addPropertyValue($entity, $this->definition->container(), $relEntity);
                    unset($entity);
                }
            }
        }

        return $result;
    }
34595
public function get($key = null, $default = null, $throw = true)
    {
        $this->setScope($key);
        $result = parent::get($key, $default, $throw);
        /** @noinspection PhpInternalEntityUsedInspection */
        $this->key = null;

        return $result;
    }
1060316
@CheckReturnValue
    public final <F extends E> FluentIterableWrapper<F> filter(Class<F> clazz) {
        return from(Iterables.filter(iterable, clazz));
    }
703725
public function unserialize(string $context): GraphQLContext
    {
        [
            'request' => $rawRequest,
            'user' => $rawUser
        ] = unserialize($context);

        $request = new Request(
            $rawRequest['query'],
            $rawRequest['request'],
            $rawRequest['attributes'],
            $rawRequest['cookies'],
            $rawRequest['files'],
            $rawRequest['server'],
            $rawRequest['content']
        );

        $request->setUserResolver(
            function () use ($rawUser) {
                return unserialize($rawUser);
            }
        );

        return $this->createsContext->generate($request);
    }
442272
@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		if (DISABLED || !SERVICES_COUNTER.isDisplayed()) {
			return method.invoke(facade, args);
		}
		// nom identifiant la requête
		final String requestName = getRequestName(method);

		return invokeTarget(facade, method, args, requestName);
	}
1112209
public function load($properties)
    {
        $keys = $this->_entity->getIdentifyingData();

        $this->_entity->getRepository()->getCommandChain()->disable();

        $query = $this->_entity->getRepository()->getQuery()
                    ->columns($properties)
                    ->where($keys);

        $data = $this->_entity->getRepository()->fetch($query, AnDomain::FETCH_ROW);

        if (!empty($data)) {
            $this->_row = array_merge($this->_row, (array) $data);

            foreach ($properties as $property) {
                unset($this->_materialized[$property]);
            }
        }

        $this->_entity->getRepository()->getCommandChain()->enable();

        return !empty($data);
    }