i want to run server to symfony

composer require server –dev
./composer.json has been updated
Running composer update symfony/web-server-bundle
Loading composer repositories with package information
Info from https://repo.packagist.org: #StandWithUkraine
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

Problem 1
– Root composer.json requires symfony/web-server-bundle 6.1.*, found symfony/web-server-bundle[v3.3.0-BETA1, …, 3.4.x-dev, v4.0.0-BETA1, …, 4.4.x-dev] but it does not match the constraint.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

PHP remove wrapping DIV

I have this structure

<div class="col">
  <div id="wrap">
    <div class="inner_wrap">
      Content
    </div>
  </div>
</div>

I would like to remove the div with id wrap but keep the contentlike this

<div class="col">
  <div class="inner_wrap">
    Content
  </div>
</div>

I’ve tried a few regular expressions but withour sucess

$content = preg_replace('/<div[^>]+id="[^>]*wrap[^>]*"[^>]*>.*?</div>/i', '', $content);

or

$content = preg_replace('/<div id="wrap">(.+?)</div>', '', $content);

Shortcode – Display product price by product SKU in Woocomerce

I need to display the price of a given product by using sku , trying to do it with few shortcodes i have found but not much luck – would like to view the price on the page after entering a product’s sku into the shortcode, like this
[woocommerce_price sku=”sku123″]
[woocommerce_price sku=”sku345″]

anyone would be able to advise how to achieve that?

see here for an example code i tried but doesnt work

    extract( shortcode_atts( array(
        'sku' => null,
    ), $atts, 'woocommerce_price' ) );
    
    if( intval( $sku ) > 0 && function_exists( 'wc_get_product' ) ){
          $product = wc_get_product_id_by_sku( $sku );
          
          if ( $product->get_price() > 0 ) {
              return $product->get_price_html();
          } else {
              return __( "Price unavailable", "woocommerce" );
          }
     }
}
add_shortcode( 'woocommerce_price', 'wc_price_shortcode_callback' );``` 

unwrite if statements with switch and case, php gilded rose

im doing the gilded rose refactoring kata fo php right now. I have written some unittests and they all work with the standard GildedRose.php code. Now i wanted to refactory the 40 line of if statements to do the code easier to read, but somewhere a mistake has crept in and idk where and how.

my unittest are like (for each item):

public function testAgedBrieAtBeginning(): void          //  +1 quality till sell_in = 0 than +2 quality
{
    $items = [new Item('Aged Brie', 2, 0)];
    $gildedRose = new GildedRose($items);
    $gildedRose->updateQuality();
    $this->assertEquals($items[0]->sell_in, 1);
    $this->assertEquals($items[0]->quality, 1);
}

public function testAgedBrieWhenSellInZero(): void
{
    $items = [new Item('Aged Brie', 0, 2)];
    $gildedRose = new GildedRose($items);
    $gildedRose->updateQuality();
    $this->assertEquals($items[0]->sell_in, -1);
    $this->assertEquals($items[0]->quality, 4);
}

public function testAgedBrieDontIncreaseMaximum(): void       // stand at 50 quality
{
    $items = [new Item('Aged Brie', -28, 50)];
    $gildedRose = new GildedRose($items);
    $gildedRose->updateQuality();
    $this->assertEquals($items[0]->sell_in, -29);
    $this->assertEquals($items[0]->quality, 50);
}

and my GildedRose.php is:

<?php

declare(strict_types=1);

namespace GildedRose;

final class GildedRose
{
/**
 * @var Item[]
 */
private $items;

public function __construct(array $items)
{
    $this->items = $items;

}

public function updateQuality(): void
{
    switch ($this->items) {
        case 'Normal':
            $this->tickNormal();
            return;
        case 'Aged Brie':
            $this->tickAgedBrie();
            return;
        case 'Sulfaras, Hand of Ragnaros':
            $this->tickSulfuras();
            return;
        case 'Backstage passes to a TAFKAL80ETC concert':
            $this->tickBackstage();
            return;
    }

}

private function tickNormal(): void  // for Dexterity, Elixir & Conjured
{
    $this->sell_in--;

    if($this->quality == 0) {
        return;
    }

    $this->quality--;
    if ($this->sell_in <= 0) {
        $this->quality--;
    }
}
private function tickAgedBrie()
{
    $this->sell_in -= 1;

    if($this->quality >= 50) {
        return;
    }

    $this->quality += 1;
    if ($this->sell_in <= 0) {
        $this->quality += 1;
    }
}

private function tickSulfuras() : void
{

}

private function tickBackstage() : void
{
    $this->sell_in -= 1;

    if ($this->quality >= 50) {
        return;
    }
    if ($this->sell_in < 0) {
        $this->quality = 0;
        return;
    }

    $this->quality += 1;
    if ($this->sell_in < 10) {
        $this->quality += 1;
    }
    if ($this->sell_in < 5) {
        $this->quality += 1;
    }
}

}

How could I use a submit button to redirect a user to a specific page?

I’m pretty new to HTML, and I’m working on a button that should redirect the user to a page.

This is my current code, housed in the page: details.php?id=?<php echo $student['id'] ?> this allows me to use php from a previous page to redirect the admin into individual users’ pages in the form of the link mentioned above. (basically the <php echo $student['id'] ?> changes the page based on the info in the database.)

Once in the page, I want to add a button which allows me to submit information and then redirect back into the same page/just refresh the page. This is my current code for it:


       $add_point = '';
       $errors = array('points' => '');
        <label>Add Points: </label> 
        <input type="text" name="add_point" value="<?php echo $add_point ?>"> 
        <div class="red-text"><?php echo $errors['points']?></div>



        <form action="details.php" method="POST">
            <input type="submit" name="add" value="Submit" class="btn brand z-depth-0"> 
        </form>



    if (isset($_POST['add'])) {
        $add_point = mysqli_real_escape_string($conn, $_POST['add_point']);
        $id = mysqli_real_escape_string($conn, $_GET['id']);
        header('Location: details.php?id=$id');
    }


instead of redirecting to the same page/refreshing, the page redirects to: details.php?id=$id, which is not what I want. How could I make it so that the submit button redirects/refreshes properly so the user can see the added points to the same user?

so to give some context to this page:
I have a section where I show the users current number of points (drawn from a database)
I then want to have an input feel where the admin can select the number of points to add, and then a submit button to add to the existing number of points into the database(basically what my code above is trying)
I then want to be able to use that button to refresh the page at the same time, so the admin can see the new number of points that the user has
Obviously the “inserting into SQL” bit hasn’t been done yet, so its a WIP.
(HTML and PHP tags also not in the code dump because this is ripped from a file. For those interested in the entire file, attachment is below. There are some stuff laying around though, been trying to solve this issue and im stumped)

Any help is appreciated, and thanks in advance!!!

Unable to signed JWT from keys openssl_sign param not considered private key

I generated JWT tokens using an online tool and details are as below

  $keyDATA = [
        
        "p" => "ABC......DEF",
        "kty"=>  "RSA",
        "q"=>  "Keoa......ABCD",
        "d"=>  "adEEDS.....32234",
        "e"=>  "AQAB",
        "kid"=>  "ABDEFCD",
        "qi"=>  "ABC....DEF",
        "dp"=>  "ABC....DEF",
        "alg"=>  "RS256",
        "dq"=>  "ABC...DEF",
        "n"=>  "ABC...DEF" ];

I am using Firebase JWT above credentials to generate a signed JWT

$jwt = JWT::encode($jwtPayload, $keyDATA[‘d’], ‘RS256’);

However I am receiving this error

openssl_sign(): supplied key param cannot be coerced into a private
key

What am I doing wrong.

Modify guestbook to add Ellipsis in pagination

I have this guestbook on my website https://github.com/taufik-nurrohman/flat-file-guestbook , but if there too much comments, there are lots of pages in pagination too. So I wrote to author on this guestbook, he sent me one of the solution (here https://github.com/taufik-nurrohman/flat-file-guestbook/issues/2 ) , that the guestbook need to be modified with his php pager function.

But I don’t know how to do that. PHP is not my field and what I see, pagination and Ellipsis feature is very hard to learn.

Can anybody help me with modify this guestbook to have better pagination?

For example:

1 ... 8 9 [10] 11 12 ... 20

Thank you in advance.

Docker Image Installation fails: “executor failed running [/bin/sh -c docker-php-ext-install ctype exif gd iconv simplexml zip] […]

Hello stackOverflow Community,

i have some issue with installing a existing dockerfile.
I have Docker Version 4.9.0 (80466) and also with the new Version: 4.11.
I am Using WSL2 on a Windows 10 System.

I got these error:

    executor failed running [/bin/sh -c docker-php-ext-install ctype exif gd iconv simplexml zip]: exit code: 2
make: *** [Makefile:35: build] Error 1

i think here is some important stuff fromt the installing process:

    #5 48.54 mkdir .libs
#5 48.55  cc -I/usr/include -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I. -I/usr/src/php/ext/iconv -DPHP_ATOM_INC -I/usr/src/php/ext/iconv/include -I/usr/src/php/ext/iconv/main -I/usr/src/php/ext/iconv -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CONFIG_H -I/usr/include -fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -c /usr/src/php/ext/iconv/iconv.c  -fPIC -DPIC -o .libs/iconv.o
#5 48.56 In file included from /usr/local/include/php/Zend/zend_config.h:1,
#5 48.56                  from /usr/local/include/php/Zend/zend_portability.h:43,
#5 48.56                  from /usr/local/include/php/Zend/zend_types.h:25,
#5 48.56                  from /usr/local/include/php/Zend/zend.h:27,
#5 48.56                  from /usr/local/include/php/main/php.h:33,
#5 48.56                  from /usr/src/php/ext/iconv/iconv.c:25:
#5 48.56 /usr/local/include/php/main/../main/php_config.h:1976: warning: "ICONV_BROKEN_IGNORE" redefined
#5 48.56  1976 | #define ICONV_BROKEN_IGNORE 0
#5 48.56       |
#5 48.56 In file included from /usr/src/php/ext/iconv/iconv.c:22:
#5 48.56 /usr/src/php/ext/iconv/config.h:59: note: this is the location of the previous definition
#5 48.56    59 | #define ICONV_BROKEN_IGNORE 1
#5 48.56       |
#5 48.71 /usr/src/php/ext/iconv/iconv.c: In function 'zm_startup_miconv':
#5 48.71 /usr/src/php/ext/iconv/iconv.c:284:25: error: '_libiconv_version' undeclared (first use in this function)
#5 48.71   284 |                         _libiconv_version >> 8, _libiconv_version & 0xff);
#5 48.71       |                         ^~~~~~~~~~~~~~~~~
#5 48.71 /usr/src/php/ext/iconv/iconv.c:284:25: note: each undeclared identifier is reported only once for each function it appears in
#5 48.72 /usr/src/php/ext/iconv/iconv.c: In function '_php_iconv_appendl':
#5 48.72 /usr/src/php/ext/iconv/iconv.c:181:15: warning: implicit declaration of function 'libiconv'; did you mean 'iconv'? [-Wimplicit-function-declaration]
#5 48.72   181 | #define iconv libiconv
#5 48.72       |               ^~~~~~~~
#5 48.72 /usr/src/php/ext/iconv/iconv.c:453:29: note: in expansion of macro 'iconv'
#5 48.72   453 |                         if (iconv(cd, (char **)&in_p, &in_left, (char **) &out_p, &out_left) == (size_t)-1) {
#5 48.72       |                             ^~~~~
#5 48.76 make: *** [Makefile:192: iconv.lo] Error 1
------
executor failed running [/bin/sh -c docker-php-ext-install ctype exif gd iconv simplexml zip]: exit code: 2
make: *** [Makefile:35: build] Error 1

this is the content from the Dockerfile:

    ARG PHP_VERSION=7.4

FROM php:${PHP_VERSION}-cli-alpine AS betl
RUN apk add --no-cache 
        zip 
        zlib-dev 
        openssh 
        rsync 
        freetype-dev 
        libjpeg-turbo-dev 
        libpng-dev 
        libxml2-dev 
        libzip-dev 
        git 
    ;

#Test: delet iconv im next line
RUN docker-php-ext-install ctype exif gd iconv simplexml zip 
#Test: new from Rollexpert 20 and 21:
#Test:  RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.13/community/ gnu-libiconv=1.15-r3
#Test: ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php

RUN apk add --no-cache libssh2-dev autoconf build-base
RUN pecl install ssh2-1.3.1 && docker-php-ext-enable ssh2
RUN apk add jpeg-dev libpng-dev 
    && docker-php-ext-configure gd --with-jpeg 
    && docker-php-ext-install -j$(nproc) gd

ENV COMPOSER_HOME /composer
ENV COMPOSER_ALLOW_SUPERUSER 1
ENV PATH /composer/vendor/bin:$PATH
ENV PHP_CONF_DIR=/usr/local/etc/php/conf.d

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

RUN echo "memory_limit=-1" > $PHP_CONF_DIR/99_memory-limit.ini

WORKDIR /betl

ENTRYPOINT ["sh", "./bin/lconsole"]

Laravel accessing route parameter in service provider

I have a route in laravel

Route::get('{company}/dashboard', [DashboardController::class, 'company'])->name('dashboard');

and I got a new Service-Provider. In that Service-Provider I want to access the variable company from the route.

I can access the request with

request()
// OR
$request = app(IlluminateHttpRequest::class);

but the Parameter is not present. The request dump look like this:

^ IlluminateHttpRequest {#42 ▼
  +attributes: SymfonyComponentHttpFoundationParameterBag {#44 ▼
    #parameters: []
  }
  +request: SymfonyComponentHttpFoundationInputBag {#43 ▶}
  +query: SymfonyComponentHttpFoundationInputBag {#50 ▶}
  +server: SymfonyComponentHttpFoundationServerBag {#46 ▶}
  +files: SymfonyComponentHttpFoundationFileBag {#47 ▶}
  +cookies: SymfonyComponentHttpFoundationInputBag {#45 ▶}
  +headers: SymfonyComponentHttpFoundationHeaderBag {#48 ▶}
  #content: null
  #languages: null
  #charsets: null
  #encodings: null
  #acceptableContentTypes: null
  #pathInfo: "/test/dashboard"
  #requestUri: "/test/dashboard"
  #baseUrl: ""
  #basePath: null
  #method: null
  #format: null
  #session: null
  #locale: null
  #defaultLocale: "en"
  -preferredFormat: null
  -isHostValid: true
  -isForwardedValid: true
  #json: null
  #convertedFiles: null
  #userResolver: null
  #routeResolver: null
  basePath: ""
  method: "GET"
  format: "html"
}

any idea how I can access the parameter company?

Greetings
C14r

Dynamically populating HTML Form at scale, using SQL values in PHP

This question is more related to process / logic of what I am hoping to achieve in terms of SCALE rather than how to code it.

In WordPress, I have several forms in html that are loaded when a user creates a custom post (essentially a new database entry for those not familiar with the CMS) for a new “incident” to be logged. I don’t want to have to map everything manually as this is using update_post_meta() to set the names and value for the database entry / post – so I am using the php loop foreach ($_POST as $name => $value) { when the form is submitted to populate all database table for this incident.

This works great, but now if the user saves the form and comes back to edit it later, I would like to echo the value if it exists like so:

<label for="reported_by">Reporting individual (full name)</label>
<?php $reported_by = get_post_meta($incident_id, 'reported_by', true); ?>
<input type="text" name="reported_by" value="<?php echo $reported_by; ?>">

Again this works just fine, but I have almost 500 fields across forms on this page so setting the unique variable (in this case $reported_by) for each manually is going to take me forever and will essentially increase the codebase by almost 50%, make this difficult to maintain and will not be efficient .

Any thoughts on how to approach this? Understandably I could construct the forms via php and echo in the HTML, but that also feels like a very manual process. PHP is server side, so I cant easily get the name values from the labels / inputs client side without using AJAX, which I feel is also going to be quiet manual.

So either way I am faced with a lot of monotony unless there is some way of approaching this that would make it easier to scale across all 500 fields without me having to set the variable names manually.

Thank you for your time!

Best way to obtain prefix and last part of url in Laravel

I have a group route like this

PHP LARAVEL 9

/**
 * ACCOMODATIONS
 */
Route::controller(AccomodationsController::class)->group(function () {

        Route::prefix('accomodations')->group(function () {

            Route::GET('/', 'index');

            Route::GET('/italy', 'index');
    
            Route::GET('/greece', 'index');

        });

});

In the controller side I want to obtain the accomodations part and the italy greece part without slashes. I’m doing like this

PHP LARAVEL 9

class AccomodationsController extends Controller
{

    public function index(request $request){

        $listType = [
            'type' => trim($request->route()->getPrefix(), '/'),
            'route' => request()->segment(count(request()->segments()))
        ];

     dd($listType);
    
    );
}

/*
http://example.com/accomodations outputs
array [
  "type" => "accomodations"
  "route" => ""
]
/*

/*
http://example.com/accomodations/italy outputs
array [
  "type" => "accomodations"
  "route" => "italy"
]
*/

/*
http://example.com/accomodations/greece outputs
array [
  "type" => "accomodations"
  "route" => "greece"
]
*/

This works but the way I’m manipulating the request in $listType seems a little bloated to me, is there a cleaner way in laravel?

Missing detail page on hosting/server laravel

I’ve laravel app that sign to domain url https://brandztory.me/blog, so the app is uploaded to folder /blog on server that can be only access at that url..

For show list of the article it’s good, there’s no problem.. but when i go for detail of the article, it’s shows this error

enter image description here

I don’t know where’s the problem, because on local, it’s fine.. but when on server, this problem showed up..

Here’s my Detail Method on Controller

public function detail(Request $request, $blogDetail)
    {
        $json = "json/blog.json";
        $blog = file_get_contents($json);
        $blog = json_decode($blog, true);
        $blog = array_filter($blog);
        $blog = collect($blog);
        $blogDetail = collect($blog)->where('judul_rtikel_slug', "{$blogDetail}");
        $results = collect($blog)->all();

        return view('pages/detailblog', compact('results', 'blogDetail'));
    }

Here’s my route

Route::get('blog', 'BlogController@index');
Route::get('blog/{blogDetail}', 'BlogController@detail')->name('blog.view');

And here’s my href route in blog view for go to detail page

{{ route('blog.view', ['blogDetail' => $row['judul_rtikel_slug']]) }}

I’ve looking for the problem, but no find a way out..