NotionCommotion
Members-
Posts
2,446 -
Joined
-
Last visited
-
Days Won
10
Everything posted by NotionCommotion
-
Thanks both, @requinix You mean a "stupid simple cache" is just a flat text file which contains the mime on the first line? @kicken Looked a little into Apache proxies. "Reverse" proxy, right? Probably would be both simpler and more robust. Do you recall if you were able to dynamically change the URL by the path as well as modify the css/js/image links so they don't get blocked? @Both What do you think the weird output is all about? The response header says it is text/html but PHP says it is application/octet-stream. Maybe compressed? A�G�C�9=�K�Z���4�:��8��F^�� AU��ۦ|��)U��BZ7;R����9rH�;%>RrFfE��iҙ� >}��a-���p�������:8�)U�I� R�n�MVU�h��d}��L�>TWU��`��hצ�����`�['Q�O���|���B^��JWS�bvO�ۚr�`��
-
How come I knew you were going to ask me this? Maybe "proxy" wasn't the right word. IT department arbitrarily restricts some sites which I need to access and it is a pain every time to contact them and get them to change it, so created a small site on my server which accepts a URL, makes a request to it using cURL, modifies the response body HTML to change resource urls to point to my server, modifies a couple of headers, and returns the response. If the request is for a js, css, png, etc resource, I first check if I have a copy and if not make a curl request to get it and save it for future requests. Works sometimes but other times get application/octet-stream. Maybe not worth the trouble... ��o���??_�L������n�ے��֗!J,��#�ԧ�5�i�Z![)ɘ3��`w&��� }8@�����q��!�: e������� "��ش���.��X;q��3��_F(����\�Vfc���e�DI�ey��v!����e���͛�y�����Tv_���$���Փ�;�t��������S��~�B1�;�m��Ѻ��+�6�9��\���z�[�s�z0�A��H����ym�!���e9&�{IvidFjqɊ*zw��X4-,BB`�H�4���(4�)B=��{���.�x�E��V:|���\�[~}�w����r�s���|�?u=�n���i�d������j�m�Df����dX:�d3��_��y0��0`AȂ��"K�@s%cy���d�p@0K}218lu���e�8���� ��JH��/�LyϮlAۦ��Ғ�*ʊF&E�ȦQ A�G�C�9=�K�Z���4�:��8��F^�� AU��ۦ|��)U��BZ7;R����9rH�;%>RrFfE��iҙ� >}��a-���p�������:8�)U�I� R�n�MVU�h��d}��L�>TWU��`��hצ�����`�['Q�O���|���B^��JWS�bvO�ۚr�`��9&���8aX9O����I*��ч�iD��j���VH�3 F�a�`��,lѧ���C�x@���?��l����=22������h\�@�ď�i ��s�iy�0���j���pZ �b&E�d��d�����AO���s����������F������zA��]��np�N|�����)b}|(�ŜNr���7��rw�����P�1����J�(��[�KA���Z,�m�oNЎ���L� ��~A�gS֮A��c@� �0<瀂�����$�_�����}��Vw��sQ�w�;-R�j�� Rmq�v���- d0����_��~�����h�� ve7���jE*}��~�'��d'��;)B�:��v����I��\}xm�e͑v�}2�PM��8&��n�d���{���.�[�|.���u|o�3U@v��0�y�~k��&N�9�I_���2PF;l!e��w|7����A�}�l\W�+,6���쪪l{%�$��x@5Wiw�n����=k^'*%��N � H�'��+Lc��t}��c����S'ɶ9�𧋆H�s?Y�]ђ'F�z �}���D�����]S�����vw<3jz�O9:���iL',�X�ׄ�����z�V֣Qc� R�-�\�\�3�0;�A���Ҁ��Q/�Ftlh�V<�e�,qOw0 ��.I�iT�|���� Z"�B@u�Oz�Щ�=lݹ��&�������{�4�MZq�� �Ryx2����A2��D��b���Js��J:�>7�W��Y�åy=�-��~�.�δ�Zg��w�y0���� R�%�I�&� �`�����44U7w�4۰���>�G����y�Uv"{��<7����'�pR��f�h<,6>.4y�Fr�IÑM0�E��Rθ:�Y@��4�.sq�V;U����y��ɸuV���o�j/�M�=��ֵ�����G�wo�}�;��]�q�=DA5�|�g)�
-
Never used file before. man says it does in order filesystem tests, magic tests, and language tests. Works on the CLI. Don't know whether it got to magic tests. For magic tests, does it also use /usr/share/misc/magic, and were these support files installed specifically for file? If so, maybe uninstall and reinstall file? Is magic.mime described by mime_content_type a different file? It works on my system so maybe it has to be? My php.ini has no reference to magic as described by this post and maybe add it? Use case is cache for a simple proxy. Primary reason was to know which content-type header to include in the response and secondary to validate before saving to disk. mime_content_type doesn't work for the header part unless I add some custom logic for JS/CSS/etc files which come across as text/plain or sometimes text/html.
-
You mean mime_content_type()? As far as I know, doesn't detect JS/CSS/etc and says is plain text. Maybe not a big deal. Maybe not worry about it?
-
Already tried and no luck. <b>Fatal error</b>: Uncaught Exception: finfo::__construct(): offset `�����' invalid in /var/www/filetest/src/MediaType.php:104 I also thought that maybe it was a module but no longer think so. The following are not installed but I don't think the issue. Agree? Even if not a module issue, could it be a repo issue? I tried file_get_contents() on the file so don't think a permission issue. If it was corrupted, I would have expected some different message such as this one. Do you know how these files original were installed? Maybe uninstall and reinstall it? php-magickwand.x86_64 1.0.9-7.el7 epel php-magickwand-debuginfo.x86_64 1.0.9.2-19.el7.remi.5.4 remi-safe-debuginfo php-pecl-gmagick.x86_64 2.0.6~RC1-1.el7.remi.8.0 php-pecl-gmagick-debuginfo.x86_64 2.0.6~RC1-1.el7.remi.8.0 php-pecl-imagick.x86_64 3.4.4-17.el7.remi.8.0 remi-php80 php-pecl-imagick-debuginfo.x86_64 3.4.4-17.el7.remi.8.0 remi-php80-debuginfo php-pecl-imagick-devel.x86_64 3.4.4-17.el7.remi.8.0 remi-php80 php-pecl-imagick-im6.x86_64 3.5.1-1.el7.remi.8.0 remi-php80 php-pecl-imagick-im6-debuginfo.x86_64 3.5.1-1.el7.remi.8.0 remi-php80-debuginfo php-pecl-imagick-im6-devel.x86_64 3.5.1-1.el7.remi.8.0 remi-php80 php-pecl-imagick-im7.x86_64 3.5.1-1.el7.remi.8.0 remi-php80 php-pecl-imagick-im7-debuginfo.x86_64 3.5.1-1.el7.remi.8.0 remi-php80-debuginfo php-pecl-imagick-im7-devel.x86_64 3.5.1-1.el7.remi.8.0 remi-php80
-
I am attempting to execute the following script on Centos 7 running Remi's PHP 8.0.9 using FPM, and get the following results. While not positive, it looks like it has something to do with failing to load magic database at "/usr/share/misc/magic" (see at the very end of this post for some relevant content). Any thoughts? Thanks <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $finfo = finfo_open(FILEINFO_MIME, "/usr/share/misc/magic"); // return mime type ala mimetype extension $finfo = new finfo(FILEINFO_MIME, "/usr/share/misc/magic"); // return mime type ala mimetype extension Warning: finfo_open(): Printf format is too long for type `belong' in description `%ld x' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `%ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `%ld x' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `%ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Current entry does not yet have a description for adding a MIME type in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Current entry does not yet have a description for adding a MIME type in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Current entry does not yet have a description for adding a MIME type in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Current entry does not yet have a description for adding a MIME type in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Current entry does not yet have a description for adding a MIME type in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Current entry does not yet have a description for adding a MIME type in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Current entry does not yet have a description for adding a MIME type in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Current entry does not yet have a description for adding a MIME type in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `, version %hhd' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `beshort' in description `, system %hd' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `, version %hhd' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `leshort' in description `, system %hd' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Current entry does not yet have a description for adding a MIME type in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `long' in description `, original size: %ld bytes' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `beshort' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `beshort' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Current entry does not yet have a description for adding a MIME type in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `Mach-O fat file with %ld architectures' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): New continuation level 2 is more than one larger than current level 0 in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `, %ld records' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `short' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `short' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Current entry does not yet have a description for adding a MIME type in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): New continuation level 2 is more than one larger than current level 0 in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `Volume %ld,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `Volume %ld,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `Volume %ld,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `Volume %ld,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `leshort' in description `Volume %ld,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `Volume %ld,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `Volume %ld,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `Universal EFI binary with %ld architectures' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `short' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `short' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `long' in description `start cyl %ld,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `long' in description `%ld blocks' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `pending inodes to free %ld,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `pending inodes to free %ld,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `pending inodes to free %ld,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `pending inodes to free %ld,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `size %lu' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `edition %lu,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `%lu blocks,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `%lu files' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `size %lu' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `edition %lu,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `%lu blocks,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `%lu files' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description ` fblock size = %ld,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description ` block size = %ld,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `long' in description `%lu skin(s),' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `long' in description `(%lu x' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `long' in description `%lu),' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `long' in description `%lu frame(s),' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `long' in description `Frame size %lu bytes,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `long' in description `%lu vertices/frame,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `long' in description `%lu texture coordinates,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `long' in description `%lu triangles/frame' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `version %lu' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `%lu x' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `%lu,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `, crypto type %hhu (unknown)' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `, hash type %hhu (unknown)' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `beshort' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `beshort' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `long' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `long' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `long' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `beshort' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `beshort' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `beshort' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `beshort' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `beshort' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `beshort' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `beshort' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `beshort' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `leshort' in description `%hd x' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `leshort' in description `%hd' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `leshort' in description `%hd x' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `leshort' in description `%hd' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `leshort' in description `%hd x' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `leshort' in description `%hd' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `, %ld x' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `%ld,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `leshort' in description `%hd x' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `leshort' in description `%hd' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `leshort' in description `bounding box [%hd,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `leshort' in description `%hd] -' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `leshort' in description `[%hd,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `leshort' in description `%hd],' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `%hhd-bit' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `leshort' in description `%hd x' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `leshort' in description `%hd dpi,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `volume %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `, %ld x' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `%ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `leshort' in description `%hd x' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `leshort' in description `%hd,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `leshort' in description `%hd images in file' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `leshort' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `%lu' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `filetype=%ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `architecture=%ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `architecture=%ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `filetype=%ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `architecture=%ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `architecture=%ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): New continuation level 3 is more than one larger than current level 1 in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `.%ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `.%ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `.%ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `.%ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `.%ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `.%ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `.%ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `.%ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `.%ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `.%ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `.%ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `.%ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `.%ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `(txt=%ld,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `dat=%ld,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `bss=%ld,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `sym=%ld)' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `(txt=%ld,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `dat=%ld,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `bss=%ld,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `sym=%ld)' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `text len %lu,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `data len %lu,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `BSS len %lu,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `symboltab len %lu,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `flags: 0x%lX,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `beshort' in description `(version %04lx)' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Current entry does not yet have a description for adding a MIME type in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `(%ld records)' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `(%ld records)' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Overflow for numeric type `leshort' value 0x223e9f78 in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `%hd x' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `%hd,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `beshort' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `beshort' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `beshort' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `beshort' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `beshort' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `beshort' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `beshort' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `, %lu x' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `%lu,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): New continuation level 3 is more than one larger than current level 1 in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `log volume #%ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `leshort' in description `, %hd sections' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `size: %ld bytes' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `byte' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `long' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `leshort' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `leshort' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `UNKNOWN VERSION %lu,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `%lu Hz' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `<%lu' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `~%lu' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `>%lu' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `, %ld pages' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `- data length 0x%lx' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `long' in description `- version %ld' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `long' in description `- [%ld -' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `long' in description `%ldx' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `long' in description `%ldx' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `leshort' in description `version %hd' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `leshort' in description `.%hd' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `version %lu,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `belong' in description `type: UNKNOWN (%lu),' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `version %lu,' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Printf format is too long for type `lelong' in description `type: UNKNOWN (%lu),' in /var/www/filetest/public/index.php on line 5 Warning: finfo_open(): Failed to load magic database at "/usr/share/misc/magic" in /var/www/filetest/public/index.php on line 5 Fatal error: Uncaught Exception: finfo::__construct(): Printf format is too long for type `belong' in description `%ld x' in /var/www/filetest/public/index.php:6 Stack trace: #0 /var/www/filetest/public/index.php(6): finfo->__construct() #1 {main} thrown in /var/www/filetest/public/index.php on line 6 [michael@devserver ~]$ ls -la /usr/share/misc total 2856 drwxr-xr-x. 2 root root 34 Jan 19 2021 . drwxr-xr-x. 134 root root 4096 Aug 4 15:08 .. -rw-r--r-- 1 root root 624579 Sep 30 2020 magic -rw-r--r-- 1 root root 2285896 Sep 30 2020 magic.mgc [michael@devserver ~]$ ls -la /usr/share/file total 8 drwxr-xr-x. 2 root root 18 Jan 19 2021 . drwxr-xr-x. 134 root root 4096 Aug 4 15:08 .. lrwxrwxrwx 1 root root 8 Jan 19 2021 magic -> ../magic [michael@devserver ~]$ ls -la /usr/share/file/magic lrwxrwxrwx 1 root root 8 Jan 19 2021 /usr/share/file/magic -> ../magic [michael@devserver ~]$ cat /etc/magic # Magic local data for file(1) command. # Insert here your local magic data. Format is described in magic(5). [michael@devserver ~]$ whereis magic magic: /etc/magic /usr/share/magic /usr/share/man/man5/magic.5.gz [michael@devserver ~]$ whereis libmagic libmagic:[michael@devserver ~]$
-
I want to validate my PHP files to ensure that I didn't forget to import all the classes assigned to attributes. I will be using ReflectionClass to do so and need the FQCN's and not the filenames. Originally, I tried get_declared_classes(), however, ran into issues where a class was already declared. I came up with the following which appears to work, however, it was created based on trial and error and suspect there might be edge cases where it will not provide the desired results (and it is pretty damn ugly as well). How would you recommend doing so? A couple thoughts are: Use composer to come up with the classes based on filename and use either vendor/Composer autoload_classmap.php or autoload_static.php. I don't really like this approach as it requires me to update composer to add any new files. Use composer but figure out how it generates the class map and use a similar approach. Appears that it is using phpstan or some other utility but I haven't really investigated. Use some third party script to generate the class maps. If so, please provide recommendations. Use some more modern approach other than PhpToken. If so, please provide recommendations. Use get_declared_classes() to get a base line and then require the PHP file to find the added class names and somehow deal with issues related to classes already being declared. Use tokens and my parseFile() method. If so, any recommendations on changing? PS. I originally wasn't 100% that attributes in traits and abstract classes would be propagated to the concrete class, but I should have known it to be true and this was confirmed by testing. At this time, I really just need the concrete classes, however, maybe in the future I will use the script to do some analysis on interfaces, traits, etc. private function parseFile(string $filename):array { $getNext=null; $getNextNamespace=false; $skipNext=false; $isAbstract = false; $rs = ['namespace'=>null, 'class'=>[], 'trait'=>[], 'interface'=>[], 'abstract'=>[]]; foreach (\PhpToken::tokenize(file_get_contents($filename)) as $token) { if(!$token->isIgnorable()) { $name = $token->getTokenName(); switch($name){ case 'T_NAMESPACE': $getNextNamespace=true; break; case 'T_EXTENDS': case 'T_USE': case 'T_IMPLEMENTS': //case 'T_ATTRIBUTE': $skipNext = true; break; case 'T_ABSTRACT': $isAbstract = true; break; case 'T_CLASS': case 'T_TRAIT': case 'T_INTERFACE': if($skipNext) { $skipNext=false; } else { $getNext = strtolower(substr($name, 2)); } break; case 'T_NAME_QUALIFIED': case 'T_STRING': if($getNextNamespace) { if(array_filter($rs)) { throw new \Exception(sprintf('Namespace mus be defined first in %s', $filename)); } else { $rs['namespace'] = $token->text; } $getNextNamespace=false; } elseif($skipNext) { $skipNext=false; } elseif($getNext) { if(in_array($token->text, $rs[$getNext])) { throw new \Exception(sprintf('%s %s has already been found in %s', $rs[$getNext], $token->text, $filename)); } if($isAbstract) { $isAbstract=false; $getNext = 'abstract'; } $rs[$getNext][]=$token->text; $getNext=null; } break; default: $getNext=null; } } } $rs['filename'] = $filename; return $rs; }
-
is your concern that you will potentially be creating a resource without a POST HTTP request, deleting a record without a DELETE HTTP request, etc? Not sure what the RESTful people would say. If the client that creates the request is out of your hands, I would just get the current state from the DB, use the various array intersect and diff functions to find the changes, adds, deletes, and update the DB. Be sure to use a transaction.
-
Can inheritance be used with PHP 8 attributes?
NotionCommotion replied to NotionCommotion's topic in PHP Coding Help
Thanks requinix, Yes, that was my backup plan and it works as desired. I incorrectly thought that the annotation class would magically work with attributes if modified appropriately, but now I see other code must be able to apply the appropriate logic based on the attributes. A little off topic, but one annoyance of using attributes instead of annotations is I don't get an error if I failed to import the attribute class. For instance, this would have thrown a class not found error: <?php declare(strict_types=1); namespace App\Entity; //use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity() */ class MyEntity{} But this will not: <?php declare(strict_types=1); namespace App\Entity; //use Doctrine\ORM\Mapping\Entity; #[Entity] class MyEntity{} I suspect this is the case because an actual class is not needed per the docs, and when an actual class isn't used, maybe a standard class is used which obviously will not provide the desired results but unfortunately doesn't provide any warning. -
Can inheritance be used with PHP 8 attributes?
NotionCommotion replied to NotionCommotion's topic in PHP Coding Help
Okay, I did understand your suggestion correctly. I did copy and paste the whatsits and changed it as shown previously but evidently need to make more changes. PS. Just learned a new word. -
Can inheritance be used with PHP 8 attributes?
NotionCommotion replied to NotionCommotion's topic in PHP Coding Help
Maybe I don't understand what you are suggesting. Copy attributes and not annotations since it appears that both can be used at the same time, right? And just don't extend the few classes which will have a collection in Tenant and duplicate the properties and methods? PS My expectation to simply create a new attribute class might have been a little naïve. <?php /* * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This software consists of voluntary contributions made by many individuals * and is licensed under the MIT license. For more information, see * <http://www.doctrine-project.org>. */ namespace App\Mapping; use Attribute; use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\ORM\Mapping\Annotation; /** * This annotation is used to override association mapping of property for an entity relationship. * * @Annotation * @NamedArgumentConstructor() * @Target("ANNOTATION") */ #[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] final class AssociationOverride implements Annotation { /** * The name of the relationship property whose mapping is being overridden. * * @var string */ public $name; /** * The join column that is being mapped to the persistent attribute. * * @var array<\Doctrine\ORM\Mapping\JoinColumn> */ public $joinColumns; /** * The join table that maps the relationship. * * @var \Doctrine\ORM\Mapping\JoinTable */ public $joinTable; /** * The name of the association-field on the inverse-side. * * @var string */ public $inversedBy; /** * The fetching strategy to use for the association. * * @var string * @Enum({"LAZY", "EAGER", "EXTRA_LAZY"}) */ public $fetch; public function __construct( ?string $name = null, ?array $joinColumns = null, ?string $joinTable = null, ?string $inversedBy = null, ?string $fetch = null ) { $this->name = $name; $this->joinColumns = $joinColumns; $this->joinTable = $joinTable; $this->inversedBy = $inversedBy; $this->fetch = $fetch; //$this->debug('__construct',); } private function debug(string $message, string $file='test.json', ?int $options = null) { $content = file_exists($file)?json_decode(file_get_contents($file), true):[]; $content[] = ['message'=>$message, 'object_vars'=>get_object_vars($this), 'debug_backtrace'=>debug_backtrace($options)]; file_put_contents($file, json_encode($content, JSON_PRETTY_PRINT)); } } -
Can inheritance be used with PHP 8 attributes?
NotionCommotion replied to NotionCommotion's topic in PHP Coding Help
My plan was to copy (or maybe extend it but probably not) the existing annotation class and put it in my space app/Attribute/BlaAossociation.pho and edit it similar to the others. This reflects your thoughts. Thanks -
Can inheritance be used with PHP 8 attributes?
NotionCommotion replied to NotionCommotion's topic in PHP Coding Help
Was just hoping that one could redefine a property without really redefining the property... Yeah, agree it doesn't make sense but was just hoping. EDIT. On a whim, just looked for a parent::addAttribute() method but no such luck. After I better understand attributes, would it be that difficult to make my own? I believe this commit implemented most of the attributes used by Doctrine. Doesn't look like too overwhelming but that is always what I initially think... -
Context. Class AbstractTenantEntity's purpose is to restrict access to data to the tenant (i.e. account, owner, etc) that owns the data. Any entity which extends it will have the TenantId added when created and the TenantId in the WHERE clause for all other requests. Tenant typically does not have collections of the various entities which extend AbstractTenantEntity, but does for a few of them do. When using annotation, I handled it by applying Doctrine's AssociationOverride annotation to the extended classes which should have a collection in Tenant. use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity() */ class Tenant { /** * @ORM\OneToMany(targetEntity=Asset::class, mappedBy="tenant") */ private $assets; // Other properties and typical getters and setters } use Doctrine\ORM\Mapping as ORM; abstract class AbstractTenantEntity implements TenantInterface { /** * inversedBy performed in child where required * @ORM\ManyToOne(targetEntity=Tenant::class) * @ORM\JoinColumn(nullable=false) */ protected ?Tenant $tenant = null; // Typical getters and setters } use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity() * @ORM\AssociationOverrides({ * @ORM\AssociationOverride(name="tenant", inversedBy="assets") * }) */ class Asset extends PublicIdTenantEntity { // Various properties and typical getters and setters } So, now I am changing from annotations to attributes, and modified AbstractTenantEntity as follows: use Doctrine\ORM\Mapping\ManyToOne; use Doctrine\ORM\Mapping\JoinColumn; abstract class AbstractTenantEntity implements TenantInterface { /** * inversedBy performed in child where required */ #[ManyToOne(targetEntity: Tenant::class)] #[JoinColumn(nullable: false)] protected ?Tenant $tenant = null; // Typical getters and setters } Next I went to modify Asset and realized that there didn't appear to be an attribute for AssociationOverride. I found a little discussion on the topic on github but couldn't find any resolution. Question Can inheritance be used with PHP 8 attributes where the property is defined in the parent class and the attribute is applied in the child class? Googling php 8 attributes inheritance didn't provide anything and thus I expect the answer is no but thought I'd ask. Thanks EDIT. Maybe Doctrine does have an attribute version: https://github.com/doctrine/orm/blob/2.9.x/lib/Doctrine/ORM/Mapping/AttributeOverride.php EDIT2. Actually don't think so
-
Okay, I got it working but it seems like a hack. The following file creates a connection first without using Symfony and then with using Symfony. <?php use Doctrine\ORM\Tools\Setup; use Doctrine\ORM\EntityManager; use App\Kernel; use Symfony\Component\Dotenv\Dotenv; use Symfony\Component\ErrorHandler\Debug; use Doctrine\Common\Persistence\ObjectManager; use Doctrine\DBAL\Connection; ini_set('display_errors', 1); require dirname(__DIR__).'/vendor/autoload.php'; function getPdowithoutSymfony():Connection { $setup = Setup::createAnnotationMetadataConfiguration([__DIR__."/../src"], true, null, null, false); $em = EntityManager::create(['driver' => 'pdo_pgsql','dbname' => 'testing'], $setup); return $em->getConnection(); } function getPdowithSymfony():Connection { (new Dotenv())->bootEnv(dirname(__DIR__).'/.env'); if ($_SERVER['APP_DEBUG']) { umask(0000); Debug::enable(); } $kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']); $kernel->boot(); $em = $kernel->getContainer()->get('doctrine.orm.entity_manager'); return $em->getConnection(); } function test(Connection $pdo):int { $stmt = $pdo->executeQuery('SELECT COUNT(*) FROM public.user'); return $stmt->fetchColumn(); } echo('count without symfony: '.test(getPdowithoutSymfony()).PHP_EOL); echo('count with symfony: '.test(getPdowithSymfony()).PHP_EOL); Then in the following class I added the echo and var_dump lines: <?php namespace Doctrine\DBAL\Driver; class PDOConnection extends PDO implements ConnectionInterface, ServerInfoAwareConnection { public function __construct($dsn, $user = null, $password = null, ?array $options = null) { try { echo(get_class($this).PHP_EOL); var_dump(['$dsn'=>$dsn, '$user'=>$user, '$password'=>$password, '$options'=>$options, ]); parent::__construct($dsn, (string) $user, (string) $password, (array) $options); $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, [Statement::class, []]); $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $exception) { throw Exception::new($exception); } } } If I configure Symfony to use doctrine.dbal as {driver: pdo_pgsql,dbname: testing, server_version: 13}, I get: \Doctrine\DBAL\Driver\__construct Doctrine\DBAL\Driver\PDO\Connection array(4) { ["$dsn"]=> string(21) "pgsql:dbname=testing;" ["$user"]=> NULL ["$password"]=> NULL ["$options"]=> array(0) { } } count without symfony: 10 Doctrine\DBAL\Driver\PDO\Connection array(4) { ["$dsn"]=> string(36) "pgsql:host=localhost;dbname=testing;" ["$user"]=> string(4) "root" ["$password"]=> NULL ["$options"]=> array(0) { } } <!-- An exception occurred in driver: SQLSTATE[08006] [7] fe_sendauth: no password supplied (500 Internal Server Error) --> So, then I configured Symfony to use doctrine.dbal as {driver: pdo_pgsql,dbname: testing, server_version: 13, user: null, host: null}, and no errors. Doctrine\DBAL\Driver\PDO\Connection array(4) { ["$dsn"]=> string(21) "pgsql:dbname=testing;" ["$user"]=> NULL ["$password"]=> NULL ["$options"]=> array(0) { } } count without symfony: 10 Doctrine\DBAL\Driver\PDO\Connection array(4) { ["$dsn"]=> string(21) "pgsql:dbname=testing;" ["$user"]=> NULL ["$password"]=> NULL ["$options"]=> array(0) { } } count with symfony: 10 Zero documentation describing this as far as I could tell. Anyone know whether there is a more proper way to do this?
-
MYSQL Insert: Whatever's inside JSON array?
NotionCommotion replied to ChenXiu's topic in PHP Coding Help
Necessary, maybe not, but you will live a happier life if you use json_decode() and deal with arrays or objects of your choosing. If you use the default json_decode($var), as you discovered, it is returned as a standard class and not an array, thus you cannot access it as an array. JavaScript is obj.property as PHP is $obj->property. -
MYSQL Insert: Whatever's inside JSON array?
NotionCommotion replied to ChenXiu's topic in PHP Coding Help
First of all, definitely do not use strpos and preg_match but convert your JSON string to an array using json_decode($all_items_sold, true). Alternatively, you can convert to an object by I prefer an array. Recommend standard json_decode error checking as well. Regarding multiple inserts, sure you can do it; INSERT INTO your_table(product , item, price) VALUES (7777,'hammer',4.99), (8888,'nail',1.99); But don't do direct inserts like this and instead use a prepared statement. Your place holders can either be something like :product or a question mark (?). Go with the question mark format and use functions such as implode(', ', $array) and rtrim(str_repeat('?,',count($arr), ',') to build your prepared statement. -
@Abrar If only your friends are using your application and they will not mind if their identity gets stolen and their bank accounts emptied, I guess it is okay to do it as you are, but if you developing your application for others, please do what Barand suggested and use PDO and prepared statements.
-
Run the following script and spend time to understand it. If you don't understand <<<EOL, see https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc. If you don't understand how the functions work, look them up on php.net. <?php ini_set('display_errors', 1); $json = <<<EOL { "CONCACT_ID": 123, "shipping_data": [{ "SER_NO": 312, "BLA": 123 }, { "SER_NO": 112, "BLA": 223 } ] } EOL; echo($json.PHP_EOL); // Turn the JSON string into either an array or object (I use an array) $arr = json_decode($json, true); print_r($arr); $obj = json_decode($json, false); print_r($obj); printf('array: %s object: %s'.PHP_EOL, $arr['CONCACT_ID'], $obj->CONCACT_ID); foreach($arr['shipping_data'] as $item) { print_r($item); } foreach($obj->shipping_data as $item) { print_r($item); }
-
When you see something happening which seems impossible, make you script as small as possible, and every time you will find it was impossible not to happen
-
Okay, $textAr includes URLs for www.google.com\r and www.yahoo.com. Do you really want the \r with Google? Then I see $line: www.google.com being echoed, but don't see the results being echoed. Replace print_r with var_dump as it likely is returning NULL. Then I see $line: www.yahoo.com followed by the error message. I would have expected a line break but not a big deal. Then I see the $results array with the first element being empty and the second being the error response. Isn't this what you were expecting? Consider changing $result[] = $r; to $result[$line] = $r; to make it more clear.
-
I meant something like the following: if (isset($_POST['submit'])) { printf('$textAr: %s'.PHP_EOL, json_encode($textAr)); $result = array(); foreach ($textAr as $line) { $url = "https://example.com/api/domains/blah.xml?domain-name={$line}"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true ); curl_setopt($ch, CURLOPT_ENCODING, "gzip,deflate"); printf('$line: %s'.PHP_EOL, $line); $r = curl_exec ($ch); print_r($r); $result[] = $r; curl_close ($ch); } print_r($result); }
-
Well, it will be specific to whatever database you are using, but after that is known, I expect google could tell you.