Esempio n. 1
0
 public function completeItem($id) : JsonResponse
 {
     $status = Nullable::fromValue($id)->reject('')->map('intval')->filter(P::lt(0))->flatMap(Item::class . '::findNullable')->map(function ($item) {
         return $item->setStateId(State::of('completed')->id)->save();
     })->getOrThrow(new \RuntimeException("Item by ID {$id} not found!"));
     return response()->json(['status' => $status, 'id' => $id]);
 }
 public function testCreateContentList()
 {
     $rpbContent1 = $this->getMock('Riak\\Client\\ProtoBuf\\RpbContent', [], [], '', false);
     $rpbContent2 = $this->getMock('Riak\\Client\\ProtoBuf\\RpbContent', [], [], '', false);
     $rpbContent1->expects($this->once())->method('getContentType')->willReturn(Option::fromValue('application/json'));
     $rpbContent2->expects($this->once())->method('getContentType')->willReturn(Option::fromValue('application/json'));
     $rpbContent1->expects($this->once())->method('getLastMod')->willReturn(Option::fromValue(1420229384));
     $rpbContent2->expects($this->once())->method('getLastMod')->willReturn(Option::fromValue(1420229377));
     $rpbContent1->expects($this->once())->method('getVtag')->willReturn(Option::fromValue('vtag-hash'));
     $rpbContent2->expects($this->once())->method('getVtag')->willReturn(Option::fromValue('vtag-hash'));
     $rpbContent1->expects($this->once())->method('getValue')->willReturn('[1,1,1]');
     $rpbContent2->expects($this->once())->method('getValue')->willReturn('[2,2,2]');
     $rpbContent1->expects($this->once())->method('getIndexesList')->willReturn([]);
     $rpbContent2->expects($this->once())->method('getIndexesList')->willReturn([]);
     $rpbContent1->expects($this->once())->method('getUsermetaList')->willReturn([]);
     $rpbContent2->expects($this->once())->method('getUsermetaList')->willReturn([]);
     $rpbContent1->expects($this->once())->method('getLinksList')->willReturn([]);
     $rpbContent2->expects($this->once())->method('getLinksList')->willReturn([]);
     $contentList = $this->invokeMethod($this->instance, 'createContentList', [[$rpbContent1, $rpbContent2]]);
     $this->assertCount(2, $contentList);
     $this->assertEquals('[1,1,1]', $contentList[0]->value);
     $this->assertEquals('[2,2,2]', $contentList[1]->value);
     $this->assertEquals(1420229384, $contentList[0]->lastModified);
     $this->assertEquals(1420229377, $contentList[1]->lastModified);
     $this->assertEquals('application/json', $contentList[0]->contentType);
     $this->assertEquals('application/json', $contentList[1]->contentType);
 }
Esempio n. 3
0
 /**
  * @expectedException \Bart\GitHook\GitHookException
  * @expectedExceptionMessage All repositories are frozen
  */
 public function testWhenAllFrozenRepoAndNoEnvVarConfigured()
 {
     $this->shmockAndDieselify('\\Bart\\GitHook\\GitHookSystemConfig', function ($config) {
         $config->envVarNameForPushUser()->once()->return_value(Option::fromValue(null));
         // This should not be called because env var name is None
         $config->superUserNames()->never();
         $config->frozenRepoNames()->once()->return_value(['all']);
     }, true);
     $freeze = new CodeFreeze();
     $freeze->run($this->head);
 }
Esempio n. 4
0
 /**
  * Flexible getter
  *
  * ```php
  * // Get value or throw
  * $data->attribute('key.sub')->get();
  * // Get value or throw custom exception
  * $data->attribute('m.s.k')->getOrThrow(new \LogicException('does not exists'));
  * // Or call some closure
  * $data->attribute('my.sub.key')->getOrCall(function() { return 'fallBackValue';});
  * // Or use default value
  * $data->attribute('my.sub.key')->getOrElse(2);
  * // Check if it exists
  * $data->attribute('m.s.k')->isDefined();
  * // Value is an array convert to observable
  * $data->attribute('my.array')
  *  ->map([Observable, 'fromArray')
  *  ->get()
  *  ->subscribeCallback(...);
  * ```
  *
  * @see https://github.com/schmittjoh/php-option
  * @param string $key
  * @return None|Option
  */
 public function attribute($key)
 {
     $object = $this->payload;
     foreach (explode('.', $key) as $segment) {
         if (!is_object($object) || !isset($object->{$segment})) {
             return None::create();
         }
         $object = $object->{$segment};
     }
     return Option::fromValue($object);
 }
Esempio n. 5
0
 /**
  * Executes a console command.
  *
  * @param ContainerInterface $container
  * @param Command            $command
  * @param string             $alias
  * @param array              $args
  */
 protected static function runCommand(ContainerInterface $container, Command $command, $alias, array $args = null)
 {
     $application = new Application(static::$kernel);
     $application->setAutoExit(false);
     $application->add($command);
     $command = $application->find($alias);
     if ($command instanceof ContainerAwareCommand) {
         $command->setContainer($container);
     }
     $commandTester = new CommandTester($command);
     $call = array_merge(Option::fromValue($args)->getOrElse(array()), array('command' => $command->getName()));
     $commandTester->execute($call);
 }
Esempio n. 6
0
 /**
  * @param string $operator
  * @return Option Option of a callable.
  */
 public static function forOperator($operator)
 {
     $fun = null;
     switch ($operator) {
         case "+":
             $fun = [OperatorCallbacks::class, 'add'];
             break;
         case "-":
             $fun = [OperatorCallbacks::class, 'sub'];
             break;
     }
     return Option::fromValue($fun);
 }
Esempio n. 7
0
 public function handle(Request $request, Closure $next, string $inputParam = 'input')
 {
     $value = $request->input($inputParam);
     if (!is_array($value)) {
         $request->merge([$inputParam => Nullable::fromValue($value)]);
     } else {
         $nullables = array_map(function ($id) {
             return Nullable::fromValue($id);
         }, $value);
         $request->merge([$inputParam => $nullables]);
     }
     return $next($request);
 }
Esempio n. 8
0
 public function testFromReturn()
 {
     $null = function () {
         return null;
     };
     $false = function () {
         return false;
     };
     $some = function () {
         return 'foo';
     };
     $this->assertTrue(\PhpOption\Option::fromReturn($null)->isEmpty());
     $this->assertFalse(\PhpOption\Option::fromReturn($false)->isEmpty());
     $this->assertTrue(\PhpOption\Option::fromReturn($false, array(), false)->isEmpty());
     $this->assertTrue(\PhpOption\Option::fromReturn($some)->isDefined());
     $this->assertFalse(\PhpOption\Option::fromReturn($some, array(), 'foo')->isDefined());
 }
 /**
  * Get "n_val" value
  * @return \PhpOption\Option of type (int)
  *
  *
  */
 public function getNVal()
 {
     return \PhpOption\Option::fromValue($this->n_val);
 }
Esempio n. 10
0
 /**
  * @param Option $option
  * @param string $className
  * @return Option
  */
 public static function filterConditionByClass(Option $option, $className)
 {
     return $option->filter(function (ConditionInterface $condition) use($className) {
         return $condition instanceof $className;
     });
 }
 /**
  * Get "value" value
  * @return \PhpOption\Option of type (int)
  *
  *
  */
 public function getValue()
 {
     return \PhpOption\Option::fromValue($this->value);
 }
Esempio n. 12
0
 /**
  *
  * @param type $value
  * @param type $noneValue
  * @return type
  */
 public function fromValue($value, $noneValue = null)
 {
     return \PhpOption\Option::fromValue($value, $noneValue);
 }
Esempio n. 13
0
File: System.php Progetto: phpj/phpj
 /**
  * @return Properties
  */
 public static function getProperties()
 {
     return Option::fromValue(self::$props)->getOrCall(function () {
         return self::$props = new Properties();
     });
 }
 /**
  * Get "server_version" value
  * @return \PhpOption\Option of type (string)
  *
  *
  */
 public function getServerVersion()
 {
     return \PhpOption\Option::fromValue($this->server_version);
 }
Esempio n. 15
0
 /**
  * Get "counter_value" value
  * @return \PhpOption\Option of type (int)
  *
  *
  */
 public function getCounterValue()
 {
     return \PhpOption\Option::fromValue($this->counter_value);
 }
Esempio n. 16
0
 /**
  * Get "map_op" value
  * @return \PhpOption\Option of type (MapOp)
  *
  *
  */
 public function getMapOp()
 {
     return \PhpOption\Option::fromValue($this->map_op);
 }
Esempio n. 17
0
File: String.php Progetto: phpj/phpj
 /**
  * Converts this string to a new character array.
  *
  * @return  CharArray a newly allocated character array whose length is the length
  *          of this string and whose contents are initialized to contain
  *          the character sequence represented by this string.
  */
 public function toCharArray()
 {
     return Option::fromValue($this->charArray)->getOrCall(function () {
         return $this->charArray = CharArray::fromString($this->value);
     });
 }
Esempio n. 18
0
 /**
  * Get "tag" value
  * @return \PhpOption\Option of type (string)
  *
  *
  */
 public function getTag()
 {
     return \PhpOption\Option::fromValue($this->tag);
 }
Esempio n. 19
0
 /**
  * Get "consistent" value
  * @return \PhpOption\Option of type (boolean)
  *
  *
  */
 public function getConsistent()
 {
     return \PhpOption\Option::fromValue($this->consistent);
 }
Esempio n. 20
0
 /**
  * @return Option [string] Name of environment variable capturing name of user
  * performing `git push`
  * @throws \Bart\Configuration\ConfigurationException
  */
 public function envVarNameForPushUser()
 {
     return Option::fromValue($this->getValue('env_vars', 'push_user_name', null, false));
 }
Esempio n. 21
0
 protected function ensure($value, $noneValue = null)
 {
     $option = Option::ensure($value, $noneValue);
     $this->assertInstanceOf('PhpOption\\Option', $option);
     return $option;
 }
Esempio n. 22
0
 /**
  * Get "type" value
  * @return \PhpOption\Option of type (string)
  *
  *
  */
 public function getType()
 {
     return \PhpOption\Option::fromValue($this->type);
 }
Esempio n. 23
0
 /**
  * Get "name" value
  * @return \PhpOption\Option of type (string)
  *
  *
  */
 public function getName()
 {
     return \PhpOption\Option::fromValue($this->name);
 }
Esempio n. 24
0
 /**
  * Get "include_context" value
  * @return \PhpOption\Option of type (boolean)
  *
  *
  */
 public function getIncludeContext()
 {
     return \PhpOption\Option::fromValue($this->include_context);
 }
Esempio n. 25
0
 /**
  * Get "increment" value
  * @return \PhpOption\Option of type (int)
  *
  *
  */
 public function getIncrement()
 {
     return \PhpOption\Option::fromValue($this->increment);
 }
Esempio n. 26
0
 public function getOptionResult($hydrationMode = null)
 {
     return Option::fromReturn(array($this, 'getOneOrNullResult'), array($hydrationMode));
 }
 /**
  * Get "done" value
  * @return \PhpOption\Option of type (boolean)
  *
  *
  */
 public function getDone()
 {
     return \PhpOption\Option::fromValue($this->done);
 }
Esempio n. 28
0
 /**
  * Get "pagination_sort" value
  * @return \PhpOption\Option of type (boolean)
  *
  *
  */
 public function getPaginationSort()
 {
     return \PhpOption\Option::fromValue($this->pagination_sort);
 }
 /**
  * @param Event  $event
  * @param string $email
  *
  * @return Option
  */
 public function getRegistrationForEmail(Event $event, $email)
 {
     return Option::fromValue($this->createQueryBuilder('r')->andWhere('r.event = :event')->setParameter('event', $event)->andWhere('r.email = :email')->setParameter('email', $email)->andWhere('r.confirmed = 1')->orderBy('r.created', 'DESC')->setMaxResults(1)->getQuery()->getOneOrNullResult());
 }
Esempio n. 30
0
 /**
  * Option factory, which creates new option based on passed value.
  * If value is already an option, it simply returns
  * If value is a \Closure, LazyOption with passed callback created and returned. If Option returned from callback,
  * it returns directly (flatMap-like behaviour)
  * On other case value passed to Option::fromValue() method
  *
  * @param Option|\Closure|mixed $value
  * @param null $noneValue used when $value is mixed or Closure, for None-check
  *
  * @return Option
  */
 public static function ensure($value, $noneValue = null)
 {
     if ($value instanceof Option) {
         return $value;
     } elseif ($value instanceof \Closure) {
         return new LazyOption(function () use($value, $noneValue) {
             $return = $value();
             if ($return instanceof Option) {
                 return $return;
             } else {
                 return Option::fromValue($return, $noneValue);
             }
         });
     } else {
         return Option::fromValue($value, $noneValue);
     }
 }