Jump to content

ignace

Moderators
  • Posts

    6,448
  • Joined

  • Last visited

  • Days Won

    25

Community Answers

  1. ignace's post in Implications of changing an object from the inside? was marked as the answer   
    This design has no cohesion. If you look at ClientCollection and UnregisteredClient you see they are both aware of the internals of your clientList, that it has a property Client and that it is a stdClass.
     
    Every class involved is made aware of a LengthPrefixStream.
     
    Do not branch out of your code until it is absolutely necessary. Keep the clientList and connStream and all of that inside $server.
     
    With your Client class you are on the right track.
  2. ignace's post in API json redirecting to login was marked as the answer   
    You need to programmatically log in. Something like this:
     

    function getSessionCookie($username, $password) { $context = [ 'http' => [ 'method' => 'POST', 'content' => http_build_query(['username_formfield' => $username, 'password_formfield' => $password]), ] ]; $contents = file_get_contents('http://apiwebsite.com/login', false, $context); if (false === $contents) { return false; } foreach ($http_response_header as $header) { if (0 === strpos($header, 'Set-Cookie')) { return explode(':', $header)[1]; } } return false; } function queryApi($sessionCookie, $apiCall) { $context = [ 'http' => [ 'header' => ["Cookie: $sessionCookie"], ] ]; $contents = file_get_contents('http://apiwebsite.com/blah?latest', false, $context); // your code } You'll still need to handle if the cookie expires etc.. and probably also need to parse the set-cookie header instead of simply copy-pasting. But this should get you started.
  3. ignace's post in Symfony and FormTypes was marked as the answer   
    Yes. Your field name should explain it's value:
    public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add( 'game', EntityType::class, [ 'class' => 'AppBundle:Game', 'choice_label' => 'name', 'label' => 'name' ] ) ->add( 'type', EntityType::class, [ 'class' => 'AppBundle:Type', 'choice_label' => 'name', 'multiple' => false, 'expanded' => false ] ); } Afterwards you can access these fields like:
    $form->get('game') // and $form->get('type')
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.