Category Archives: PHP

YAML

YAML stands for “Yet Another Markup Language”. It’s a strict superset of JSON, which means that YAML can do everything JSON can and more.

  • Configuration files: YAML is a popular choice for creating configuration files because it’s human-readable and works with any programming language. YAML files are often used in Kubernetes to configure pods, services, and deployments.
  • Data serialization: YAML is a data serialization language that can be used to convert data to and from other formats, such as JSON. YAML is a good choice when human readability is important.
  • Documentation: YAML’s human-readable format makes it a good choice for documentation.
  • Log files: YAML can be used to create clean, intuitive log files.
  • API and web services: YAML can be used to write API definitions for popular API specifications, such as OpenAPI and AsyncAPI.
  • Metadata: YAML can be used to store and organize metadata and content structure.
  • Machine learning: YAML can be used to define and orchestrate the steps involved in the machine learning lifecycle, such as data ingestion, model training, and evaluation.

Install Elasticsearch

Import the Elasticsearch GPG key:
# wget -qO – https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg –dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg

Add the Elasticsearch repository:
# echo “deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main” | sudo tee /etc/apt/sources.list.d/elastic-8.x.list

Update the apt package manager and install Elasticsearch:
# apt update && apt install elasticsearch

Start and enable the Elasticsearch service:
# systemctl start elasticsearch
# systemctl enable elasticsearch

Open the elasticsearch.yml file for editing:

sudo nano /etc/elasticsearch/elasticsearch.yml

Replace the following setting with ‘false’ to disable Magento security features:
# Enable security features
xpack.security.enabled: false
Save the changes to the elasticsearch.yml file.

Restart the Elasticsearch service to apply the configuration:

# systemctl restart elasticsearch.service

Verify that Elasticsearch runs correctly using the curl command:

# curl -X GET “localhost:9200/”
If Elasticsearch is working correctly, you’ll receive an output like this:
{
“name” : “ubuntu”,
“cluster_name” : “elasticsearch”,
“cluster_uuid” : “KPbFKCVLT9uu-RFxzxH_Bw”,
“version” : {
“number” : “8.6.2”,
“build_flavor” : “default”,
“build_type” : “deb”,
“build_hash” : “2d58d0f136141f03239816a4e360a8d17b6d8f29”,
“build_date” : “2023-02-13T09:35:20.314882762Z”,
“build_snapshot” : false,
“lucene_version” : “9.4.2”,
“minimum_wire_compatibility_version” : “7.17.0”,
“minimum_index_compatibility_version” : “7.0.0”
},
“tagline” : “You Know, for Search”
}

Data fixture

A data fixture is a PHP script that sets data you want to reuse in your test. The script can be defined in a separate file or as a local test case method.

Use data fixtures to prepare a database for tests. The Integration Testing Framework (ITF) reverts the database to its initial state automatically. To set up a date fixture, use the @magentoDataFixture annotation.

Constructor Property Promotion

Constructor Property Promotion is a simple shorthand syntax to declare and assign class properties from the constructor. It basically tells the way data has to be treated in code. Constructor Property Promotion is a new syntax provided in the newer version of PHP 8 that allows class property declaration and constructor assignment, variable assignment right from the constructor without getting in the condition of boilerplate code. This avoids having to type the class property name and property type from many to just once. It also avoids using repeated types. Promoted properties can only be used in constructors. Properties will be assigned before the rest of the constructor code is executed.

Named Arguments

Named arguments is a new feature introduced in PHP 8.0, which allows you to pass arguments to a function or method by specifying the parameter name along with the value. This feature provides developers with more flexibility and improves code readability.

Traditionally, in PHP, function parameters are passed by position, which means the order in which arguments are passed to a function must match the order of the parameters in the function signature. In contrast, named arguments allow you to specify which parameter you are passing the argument to, without being constrained by the order.

AMQP

Advanced Message Queuing Protocol (AMQP) is created as an open standard protocol that allows messaging interoperability between systems, regardless of message broker vendor or platform used; With AMQP, you can use whatever AMQP-compliant client library you want, and any AMQP-compliant broker you want. Message clients using AMQP are completely agnostic.

AMQP is an application layer protocol that lets client applications talk to the server and interact. However, AMQP should not just be considered a protocol used for over-the-wire communication; AMQP defines both the network layer protocol and a high-level architecture for message brokers.

It defines a set of messages capabilities which must be made available by an AMQP compliant server implementation (like RabbitMQ). Including rules of how messages must be routed and stored within the broker to follow the AMQ Model.