IMG-LOGO

Tutorial

IMG
CodeIgniter 4 : Services
31 Dec-2021

Introduction

All of the core classes within CodeIgniter are provided as “services”. This simply means that, instead of hard-coding a class name to load, the classes to call are defined within a very simple configuration file. This file acts as a type of factory to create new instances of the required class.

A quick example will probably make things clearer, so imagine that you need to pull in an instance of the Timer class. The simplest method would simply be to create a new instance of that class:

$timer = new \CodeIgniter\Debug\Timer();

And this works great. Until you decide that you want to use a different timer class in its place. Maybe this one has some advanced reporting the default timer does not provide. In order to do this, you now have to locate all of the locations in your application that you have used the timer class. Since you might have left them in place to keep a performance log of your application constantly running, this might be a time-consuming and error-prone way to handle this. That’s where services come in handy.

Instead of creating the instance ourself, we let a central class create an instance of the class for us. This class is kept very simple. It only contains a method for each class that we want to use as a service. The method typically returns a shared instance of that class, passing any dependencies it might have into it. Then, we would replace our timer creation code with code that calls this new class:

$timer = \Config\Services::timer();

When you need to change the implementation used, you can modify the services configuration file, and the change happens automatically throughout your application without you having to do anything. Now you just need to take advantage of any new functionality and you’re good to go. Very simple and error-resistant.

Note

It is recommended to only create services within controllers. Other files, like models and libraries should have the dependencies either passed into the constructor or through a setter method.

Convenience Functions

Two functions have been provided for getting a service. These functions are always available.

The first is service() which returns a new instance of the requested service. The only required parameter is the service name. This is the same as the method name within the Services file always returns a SHARED instance of the class, so calling the function multiple times should always return the same instance:

$logger = service('logger');

If the creation method requires additional parameters, they can be passed after the service name:

$renderer = service('renderer', APPPATH . 'views/');

The second function, single_service() works just like service() but returns a new instance of the class:

$logger = single_service('logger');

Defining Services

To make services work well, you have to be able to rely on each class having a constant API, or interface, to use. Almost all of CodeIgniter’s classes provide an interface that they adhere to. When you want to extend or replace core classes, you only need to ensure you meet the requirements of the interface and you know that the classes are compatible.

For example, the RouterCollection class implements the RouterCollectionInterface. When you want to create a replacement that provides a different way to create routes, you just need to create a new class that implements the RouterCollectionInterface:

class MyRouter implements \CodeIgniter\Router\RouteCollectionInterface
{
    // Implement required methods here.
}

Finally, modify /app/Config/Services.php to create a new instance of MyRouter instead of CodeIgniter\Router\RouterCollection:

public static function routes()
{
    return new \App\Router\MyRouter();
}

Allowing Parameters

In some instances, you will want the option to pass a setting to the class during instantiation. Since the services file is a very simple class, it is easy to make this work.

A good example is the renderer service. By default, we want this class to be able to find the views at APPPATH.views/. We want the developer to have the option of changing that path, though, if their needs require it. So the class accepts the $viewPath as a constructor parameter. The service method looks like this:

public static function renderer($viewPath=APPPATH.'views/')
{
    return new \CodeIgniter\View\View($viewPath);
}

This sets the default path in the constructor method, but allows for easily changing the path it uses:

$renderer = \Config\Services::renderer('/shared/views');

Shared Classes

There are occasions where you need to require that only a single instance of a service is created. This is easily handled with the getSharedInstance() method that is called from within the factory method. This handles checking if an instance has been created and saved within the class, and, if not, creates a new one. All of the factory methods provide a $getShared = true value as the last parameter. You should stick to the method also:

class Services
{
    public static function routes($getShared = false)
    {
        if (! $getShared)
        {
            return new \CodeIgniter\Router\RouteCollection();
        }

        return static::getSharedInstance('routes');
    }
}

Service Discovery

CodeIgniter can automatically discover any Config\Services.php files you may have created within any defined namespaces. This allows simple use of any module Services files. In order for custom Services files to be discovered, they must meet these requirements:

  • Its namespace must be defined in Config\Autoload.php
  • Inside the namespace, the file must be found at Config\Services.php
  • It must extend CodeIgniter\Config\BaseService

A small example should clarify this.

Imagine that you’ve created a new directory, Blog in your root directory. This will hold a blog module with controllers, models, etc, and you’d like to make some of the classes available as a service. The first step is to create a new file: Blog\Config\Services.php. The skeleton of the file should be:

<?php

namespace Blog\Config;

use CodeIgniter\Config\BaseService;

class Services extends BaseService
{
    public static function postManager()
    {
        // ...
    }
}

Now you can use this file as described above. When you want to grab the posts service from any controller, you would simply use the framework’s Config\Services class to grab your service:

$postManager = Config\Services::postManager();

News

IMG
Google Investment in Africa
News 23 Apr-2022

Tech monster Google has declared that it'll construct it’s to begin with item improvement middle in Africa in Kenya's capital, Nairobi In 2018 the company reported a $1bn (£770m) venture arrange for Africa to capitalize on the developing number of web clients on the continent.

 

“By 2030, Africa will have 800 million web users… and Google is committed to quickening Africa’s computerized change through empowering human capital,” said Nitin Gajria, Overseeing Executive for Google in Africa.

Earlier this year, installments innovation firm Visa and computer program mammoth Microsoft moreover opened development centers in Nairobi. The centers will see work openings for program engineers, analysts and originators.

IMG
15.8″ Portable Display
News

The InnoView 15.8″ portable monitor is one of the latest entries in the China-based manufacturer’s growing inventory of affordable, lightweight monitors.

Carry-around monitors can be a frustrating accessory. Too many variables risk product dissatisfaction. Performance and features can be lacking, and they might be compatible with only some of your devices.

The growing use of smartphones and tablets is driving a need for mobile solutions, and portable monitors like this add more screen real estate and ramp up productivity when on the go.

This is the company’s biggest screen offering. Three other models vary in size and configurations at 14″ and 15.6″.

The biggest drawback with the 15.8″ unit is the lack of a touchscreen. But its inviting price and the overall stellar performance make this model a can’t-pass-it-up deal.

Checks Most Boxes

This capable portable panel costs $189.99 on Amazon and $179.99 on the manufacturer’s website. It is a plug and play USB-C portable monitor with a display capability of Full High Definition (FHD) with 1920 x 1080 resolution and 300 nits brightness. It produces 16:9 aspect ratio with a 60Hz refresh rate.

This makes the device a very suitable secondary monitor attached to much smaller devices with tiny screens. Its display capabilities are pleasant on the eyes.

The 15.8″ model is an ultra-slim IPS display with a 178° viewing angle.

 

 

 

It has dual speakers (make unknown) and comes with three cables that connect most devices. These are one Mini-HDMI to HDMI cable, one USB-C to USB-C cable, and one USB-C to USB-A cable.

This unit requires AC power. An 18W wall socket adapter and USB cable to power the monitor are included. It has no batteries and cannot be powered by the attached computer or tablet, even when they are not running on their own battery supply.

The monitor has high dynamic range, or HDR — a new display technology that enhances color presentation. Also built in are FreeSync and low blue light technology for a better viewing experience.

Monitor Build

The monitor has a sturdy metal construction with very thin bezels on the top and two sides. The bottom bezel is 1.25″. The case is 0.212″ wide, 14.37″ x 9″, and weighs 1.5 lbs.

The fully black metal case is firm and has no flex when held. Thicker casing at the base houses the additional circuitry and components that make the portable panel plug and play. The base also houses the dual hi-fi speakers.

There is no MicroSD slot. On the lower left edge of the base is a 3.5mm headphone jack, a wheel button to access settings, and the on/off button.

On the right side’s bottom edge of the base, viewed from the front, are one mini-HDMI port, one USB-C port, and a micro-USB port. One of those ports must have the power connection.

Using It

Other than adjusting the screen to your specific needs, no hardware and software configurations are needed. If attached to a computer, the only thing you need to do is open the computer’s display settings to select how you want the panel to respond.

The standard computer settings usually allow the secondary monitor to either mirror the primary display or show whatever window content you drag from the primary monitor to the external panel.

Pushing the panel’s wheel button opens a popup window in the lower left corner. Use the wheel to select the settings you want to adjust. These include picture brightness, color elements, and audio.

Compatibility Matters

This InnoView monitor works with a wide array of computers and mobile devices. Typically, Microsoft Windows and Apple computers work with the included cables. However, some Apple-specific cables or adapters may be needed.

Apple iPhones need an adapter. Some Android smartphones will connect, but not all Android manufacturers provide a signal through the USB-C or USB-A port to drive the monitor. That could be an issue with some Android tablets as well.

The monitor also connects to Xbox, PS3 /PS4 /PS5, Switches, etc via the USB-C or mini-HDMI ports.

Linux Too, Mostly

Product information does not list this monitor’s compatibility with Linux. However, I found that in most cases the portable panel was fully functional with Linux devices.

Interfering factors are the hardware standards in the computer and the absence of supporting code in the particular Linux kernel driving the distribution you use.

For instance, when I attached the portable panel to a laptop running the KDE Neon distribution, it recognized the external monitor but would only display the screen when the settings configured it as enabled. But that automatically disabled the laptop’s screen.

Once connected, the portable panel had a distorted display. The Chrome OS device also threw a display fit. Mouse actions became sluggish, and opened windows only partially displayed.

Chrome OS, the operating system bundled with the Chrome web browser to drive the Chromebook’s operation, does not have system settings related to dual monitor display functions. So, while I could drag windows from one screen to the other on some of the Chromebook models, I could not navigate the mouse pointer beyond the Chromebook’s internal display on other models.

This phenomenon also occurred with other portable monitors attached to my Chromebooks.

The portable panel maker never claimed that the InnoView portable monitor was certified to work with either the Linux OS or with Chromebooks. Perhaps now the Linux certification can be stated.

 

Collected from : Jack M. Germain  at technewsworld

IMG
Stops Selling Products in Russia : Apple
News

Apple said Tuesday that it's ceased selling its products in Russia, following the country's attack on Ukraine. The tech giant said it's halting online transactions and exports to its partners in Russia in addition to other measures, including limiting Apple Pay transactions in the country. Apple also said it's disabled some features of Apple Maps in Ukraine to protect civilians.

"We are deeply concerned about the Russian invasion of Ukraine and stand with all of the people who are suffering as a result of the violence," Apple said in an e-mailed statement. "We are supporting humanitarian efforts, providing aid for the unfolding refugee crisis, and doing all we can to support our teams in the region.

Apple joins a growing list of tech companies responding to Russia's invasion of Ukraine last week. Others, including Meta's Facebook, TikTok and YouTube, have responded by cracking down on disinformation and reducing the online presence of Russian state-owned media outlets like RT News and Sputnik News. 

Apple CEO Tim Cook, who's increasingly spoken out on political issues over the years, tweeted his concerns about the violence shortly after Russia's invasion began last week.

The tech giant didn't say how long its efforts will remain in place. "We will continue to evaluate the situation and are in communication with relevant governments on the actions we are taking," the company said. "We join all those around the world who are calling for peace."

 

Apple's actions include pulling RT News and Sputnik News from the App Store outside Russia, which stops short of blocking Russian access to the App Store entirely within the country, as Ukraine's top tech minister asked Cook to do on Friday. But that could prevent people in Russia from coordinating potential anti-war actions and staying informed, says David Kaye, UC Irvine law professor and former UN special rapporteur for free speech.

"I'd be really worried that if they cut off the App Store, it's going to make it much more difficult for individuals to ensure that their devices are updating and specific apps are secure," Kaye said. "It would discourage people from using Apple products, which are among the most secure devices that people have in Russia. It would be a problem for activists and journalists and others."

Instead, Kaye explains, Apple's current actions thread the needle by ensuring iPhone owners can still connect in Russia and Ukraine while the company follows US sanctions in restricting sales of products. 

 

Collected From CNET

 

 

Course

IMG
CCNA2 Chapter 2
Course - 10 Apr-2022

Chapter 2 - Objectives

  § Explain the purpose of Cisco IOS.

  § Explain how to access and navigate Cisco IOS to configure
      network devices.

  § Describe the command structure of Cisco IOS software.

  § Configure hostnames on a Cisco IOS device using the CLI.

  § Use Cisco IOS commands to limit access to device
     configurations.

  § Use Cisco IOS commands to save the running configuration.

  § Explain how devices communicate across network media.

  § Configure a host device with an IP address.

  § Verify connectivity between two end devices.
 
PPT : Click Here
 
Thank you
Chapter 3 will be soon

Projects