Laravel Daily: Taylor Otwell: “Thin” Controllers, “Fat” Models Approach

I was listening to recent podcast by Taylor Otwell, Laravel Snippet episode 11, where he touched on the debate in Laravel community on where you should put your code logic - in Controllers, Models, or Services. Here's what he said.
The post Taylor Otwell: “Thin” Controllers, “FatâÂ...

Webslesson: How to Join Multiple Table in Laravel 5.8

This is one more tutorial on Laravel 5.8 framework and in this post you can find how to join multiple table in Laravel 5.8 framework. Here we will take example of fetch data from two or more table by using inner join in Laravel 5.8 and display on web page. If you are looking for learn how to make in...

422 Unprocessable Entity

The 422 Unprocessable Entity status-code does not appear in the base HTTP specification. Like 102 and 207 it’s part of the WebDAV specification, which is an extension to HTTP.

Unlike the other two, the 422 code has a good general use-case, and is often used in Web API’s.

The 422 code implies that the server understood the general syntax of the request, but the contents were incorrect. For example, a server might expect POST requests that uses the application/json format. If the request is broken JSON, it might be more appropriate to send back the 400 status code, but if the request is valid JSON but the request doesn’t pass validation (via for example json-schema) returning 422 might be better.

If there was something wrong with the request body, you can use the following rules to figure out what to send back:

  • If the Content-Type was not supported, use 415.
  • Else: If the request was not parsable (broken JSON, XML), use 400 Bad Request.
  • Else: If the request was parsable but the specific contents of the payload were wrong (due to validation or otherwise), use 422

Example

POST /new-article HTTP/1.1
Content-Type: application/json

{ "title": "Hello world!"}
HTTP/1.1 422 Unprocessable Entity
Content-Type: application/problem+json

{
  "type" : "https://example/errors/missing-property",
  "status": 422,
  "title": "Missing property: body"
}

References

Community News: Latest PECL Releases (04.23.2019)

Latest PECL Releases:

  • swoole 4.3.3
    Fixed


    • Fixed Http2 ping frame bug (0f074a61) (371d0b86) (e28ed13c) (@twose) (@shiguangqi)
    • Fixed OSX signal bug (6d06a2c2) (6b66f56c) (@twose)
    • Fixed CoroutineHttpClient->setData (53d9d1ac) (@twose)
    • Remove HAVE_IPV6 (3effad3c) (@matyhtf)
    • PHP7.4 compatibility (#2506) (@twose)
  • event 2.4.4
    Fixed issue #53: EventBase::__construct now throws EventException if the features specified via the EventConfig parameter are not supported on the current platform.
  • runkit7 2.0.3
    - Add missing Reflection parameter information of runkit_import(). - Remove php_runkit_sandbox.h from installed headers on Windows.
  • rdkafka 3.1.0
    * Added timestamp support (@mariam-japaridze) * Added headers support (@martynaszaliaduonis, @dariuskasiulevicius) * Added RdkafkaConf::setConsumeCb(), RdKafkaConf::setOffsetCommitCb() (@tPl0ch) * Added RdKafkaKafkaConsumer::getCommittedOffsets() (@dariuskasiulevicius) * Fixed RdKafkaMessage::errstr() (@JustBlackBird) * Fixed reflection (@carusogabriel) * Allow null key and null message (@awons) * Dropped official PHP 5.4 / 5.5 support (@tPl0ch) * Improved examples (@dbakiu, @Steveb-p)
  • dbase 7.0.0
    Backward Incompatible Changes
    • database link identifiers are now proper resources instead of integers
    • logical values are now retrieved as booleans instead of integers

    New Features

    • FoxPro datetime fields ('T') are now supported as "YYYYMMDDhhmmss.uuu"
    • Uninitialized logical fields are now supported as NULL
    • base_create() now supports an optional $type parameter (either DBASE_TYPE_DBASE or DBASE_TYPE_FOXPRO) to define the type of database to be created
    • FoxPro nullable fields are now transparently supported
    • The $mode of dbase_open() can now be specified as DBASE_RDONLY or DBASE_RDWR
    • The version of the dbase extension is now available as DBASE_VERSION
    • Basic database locking has been implemented
    • Internally the Zend memory manager is now used
    • Error reporting has been improved; e.g. unsupported field type now raise a warning

    Bug Fixes

    • Fixed #39305 (Use of decimal point in different countries)
    • Fixed #52112 (dbase_get_record() returns integer instead of decimal values)
    • Fixed #68289 (wrong strlcpy call)
    • Fixed #72812 (dbase_create does not close the FD on failure)
    • Fixed #72815 (zend_get_parameters_ex() is deprecated)
    • Fixed #73391 (Writing of floats can cause OOB reads)
    • Fixed #73395 (failing dbase_create() may leak memory)
    • Fixed #73411 (dbase_pack() returns TRUE on failure)
    • Fixed #73414 (Unsupported field types may cause dbase_open() to leak memory)
    • Fixed #73442 (Float fields always have precision 0)
    • Fixed #73447 (Floats written to character fields are truncated to integer)
    • Fixed #74983 (SIGABRT when function put_dbf_field is called)
  • imagick 3.4.4RC2
    - The 3.4.4 release is intended to be the last release (other than small bug fixes) that will support either PHP 5.x, or ImageMagick 6.x. The next planned release will be PHP > 7.0 and ImageMagick > 7.0 at least, if not higher. - Added: * function Imagick::optimizeImageTransparency() * METRIC_STRUCTURAL_SIMILARITY_ERROR * METRIC_STRUCTURAL_DISSIMILARITY_ERROR * COMPRESSION_ZSTD - https://github.com/facebook/zstd * COMPRESSION_WEBP * CHANNEL_COMPOSITE_MASK * FILTER_CUBIC_SPLINE - "Define the lobes with the -define filter:lobes={2,3,4} (reference https://imagemagick.org/discourse-server/viewtopic.php?f=2&t=32506)." * Imagick now explicitly conflicts with the Gmagick extension. - Fixes: * Bug 77128 - Imagick::setImageInterpolateMethod() not available on Windows * Prevent memory leak when ImagickPixel::__construct called after object instantiation. * Prevent segfault when ImagickPixel internal constructor not called. * Imagick::setResourceLimit support for values larger than 2GB (2^31) on 32bit platforms. * Corrected memory overwrite in Imagick::colorDecisionListImage() * Bug 77791 - ImagickKernel::fromMatrix() out of bounds write. - Deprecated: * The following functions have been deprecated: ImagickDraw, matte Imagick::averageimages Imagick::colorfloodfillimage Imagick::filter Imagick::flattenimages Imagick::getimageattribute Imagick::getimagechannelextrema Imagick::getimageclipmask Imagick::getimageextrema Imagick::getimageindex Imagick::getimagematte Imagick::getimagemattecolor Imagick::getimagesize Imagick::mapimage Imagick::mattefloodfillimage Imagick::medianfilterimage Imagick::mosaicimages Imagick::orderedposterizeimage Imagick::paintfloodfillimage Imagick::paintopaqueimage Imagick::painttransparentimage Imagick::radialblurimage Imagick::recolorimage Imagick::reducenoiseimage Imagick::roundcornersimage Imagick::roundcorners Imagick::setimageattribute Imagick::setimagebias Imagick::setimageclipmask Imagick::setimageindex Imagick::setimagemattecolor Imagick::setimagebiasquantum Imagick::setimageopacity Imagick::transformimage

Significant Symbols

Significant Symbols

Last week a person on the #php IRC channel on freenode, mentioned that he had problems loading some extensions with his self-compiled PHP binary. For example, trying to activate the timezonedb PECL extension failed with:

sapi/cli/php:
        symbol lookup error: /usr/local/php/extensions/debug-non-zts-20180731/timezonedb.so:
        undefined symbol: php_date_set_tzdb

Which is odd, as the php_date_set_tzdb is a symbol that PHP has made available since Date/Time support was added. I asked the user to check whether his PHP binary exported the symbol by using nm, and the answer was:

$ nm sapi/cli/php | grep php_date_set_tzdb
000000000018bc75 t php_date_set_tzdb

The small letter t refers to a local only text (code) section: the symbol was not made available to shared libraries to use. In other words, extensions that make use of the symbol, such as the timezonedb extension can not find it, and hence fail to load.

In PHP, the php_date_set_tzdb function is defined with the PHPAPI prefix, which explicitly should mark the symbol as a global symbol, so that shared libraries can find it:

PHPAPI void php_date_set_tzdb(timelib_tzdb *tzdb)

The PHPAPI macro is used, because on Windows it is required to explicitly make symbols available:

#ifdef PHP_WIN32
#       define PHPAPI __declspec(dllexport)

On Linux (with GCC) symbols are made available unless marked differently (through for example the static keyword).

When looking into this, we discovered that his PHP binary had no exported symbols at all.

After doing a bit more research, I found that more recent GCC versions support a specific compiler flag that changes the default behaviour of symbol visibility: -fvisibility=hidden. In recent versions of PHP, we enable this flag if it is supported by the installed GCC version through a check in the configure system:

dnl Mark symbols hidden by default if the compiler (for example, gcc >= 4)
dnl supports it. This can help reduce the binary size and startup time.
AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],
                      [CFLAGS="$CFLAGS -fvisibility=hidden"])

As this makes all symbols hidden by default, the same commit also made sure that when the PHPAPI moniker is used, we set the visibility of these specific symbols back to visible:

#   if defined(__GNUC__) && __GNUC__ >= 4
#       define PHPAPI __attribute__ ((visibility("default")))
#   else
#       define PHPAPI
#   endif

When the original reporter saw this, he mentioned that was using an older GCC version: 3.4, and that he could see the -fvisibility=hidden flag when running make, just like here:

… cc -Iext/date/lib … -fvisibility=hidden … -c ext/date/php_date.c -o ext/date/php_date.lo

Because his GCC supported the -fvisibility=hidden flag, the check in the configure script enabled this feature, but because his GCC version was older than version 4, the counter-acting ((visbility("default"))) attribute was not set for symbols that are explicitly marked with the PHPAPI specifier. Which means that no symbols were be made available for shared PHP extensions to use.

The user created a bug report for this issue, but as GCC 3.4 is a really old version, it seems unlikely that this issue will get fixed, unless somebody contributes a patch. In the end, it was quite a fun detective story and to get to the bottom of this!

FormOne (New)

Package:
Summary:
Generate HTML form composed programatically
Groups:
Author:
Description:
This class can generate HTML form composed programatically...

Read more at https://www.phpclasses.org/package/11175-PHP-Generate-HTML-form-composed-programatically.html

FormOne

Package:
Summary:
Generate HTML form composed programatically
Groups:
Author:
Description:
This class can generate HTML form composed programatically...

Read more at https://www.phpclasses.org/package/11175-PHP-Generate-HTML-form-composed-programatically.html#2019-04-22-22:00:38
Powered by Gewgley