예제 #1
0
파일: Main.php 프로젝트: luijar/fp-php
 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);
 }
예제 #3
0
파일: CodeFreezeTest.php 프로젝트: box/bart
 /**
  * @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);
 }
예제 #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);
 }
예제 #5
0
파일: Base.php 프로젝트: Ravetracer/www
 /**
  * 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);
 }
예제 #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);
 }
예제 #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);
 }
예제 #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());
 }
예제 #9
0
 /**
  * Get "n_val" value
  * @return \PhpOption\Option of type (int)
  *
  *
  */
 public function getNVal()
 {
     return \PhpOption\Option::fromValue($this->n_val);
 }
예제 #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);
 }
예제 #12
0
파일: Context.php 프로젝트: rostmefpoter/bh
 /**
  *
  * @param type $value
  * @param type $noneValue
  * @return type
  */
 public function fromValue($value, $noneValue = null)
 {
     return \PhpOption\Option::fromValue($value, $noneValue);
 }
예제 #13
0
파일: System.php 프로젝트: 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);
 }
예제 #15
0
 /**
  * Get "counter_value" value
  * @return \PhpOption\Option of type (int)
  *
  *
  */
 public function getCounterValue()
 {
     return \PhpOption\Option::fromValue($this->counter_value);
 }
예제 #16
0
 /**
  * Get "map_op" value
  * @return \PhpOption\Option of type (MapOp)
  *
  *
  */
 public function getMapOp()
 {
     return \PhpOption\Option::fromValue($this->map_op);
 }
예제 #17
0
파일: String.php 프로젝트: 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);
     });
 }
예제 #18
0
 /**
  * Get "tag" value
  * @return \PhpOption\Option of type (string)
  *
  *
  */
 public function getTag()
 {
     return \PhpOption\Option::fromValue($this->tag);
 }
예제 #19
0
 /**
  * Get "consistent" value
  * @return \PhpOption\Option of type (boolean)
  *
  *
  */
 public function getConsistent()
 {
     return \PhpOption\Option::fromValue($this->consistent);
 }
예제 #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));
 }
예제 #21
0
 protected function ensure($value, $noneValue = null)
 {
     $option = Option::ensure($value, $noneValue);
     $this->assertInstanceOf('PhpOption\\Option', $option);
     return $option;
 }
예제 #22
0
 /**
  * Get "type" value
  * @return \PhpOption\Option of type (string)
  *
  *
  */
 public function getType()
 {
     return \PhpOption\Option::fromValue($this->type);
 }
예제 #23
0
 /**
  * Get "name" value
  * @return \PhpOption\Option of type (string)
  *
  *
  */
 public function getName()
 {
     return \PhpOption\Option::fromValue($this->name);
 }
예제 #24
0
 /**
  * Get "include_context" value
  * @return \PhpOption\Option of type (boolean)
  *
  *
  */
 public function getIncludeContext()
 {
     return \PhpOption\Option::fromValue($this->include_context);
 }
예제 #25
0
 /**
  * Get "increment" value
  * @return \PhpOption\Option of type (int)
  *
  *
  */
 public function getIncrement()
 {
     return \PhpOption\Option::fromValue($this->increment);
 }
예제 #26
0
 public function getOptionResult($hydrationMode = null)
 {
     return Option::fromReturn(array($this, 'getOneOrNullResult'), array($hydrationMode));
 }
예제 #27
0
 /**
  * Get "done" value
  * @return \PhpOption\Option of type (boolean)
  *
  *
  */
 public function getDone()
 {
     return \PhpOption\Option::fromValue($this->done);
 }
예제 #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());
 }
예제 #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);
     }
 }