Skip to content

Commit

Permalink
Including the parent class manually to allow non-composer usage. Upda…
Browse files Browse the repository at this point in the history
…ting CDN link to fontawesomecdn.com and version 4.7.0
  • Loading branch information
kevinkhill committed Mar 14, 2017
1 parent 9491764 commit 550e061
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 59 deletions.
51 changes: 27 additions & 24 deletions src/FontAwesome.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

namespace Khill\FontAwesome;

require __DIR__.'/FontAwesomeHtmlEntity.php';

use InvalidArgumentException;
use Khill\FontAwesome\FontAwesomeList;
use Khill\FontAwesome\FontAwesomeStack;
use Khill\FontAwesome\FontAwesomeHtmlEntity;
use Khill\FontAwesome\Support\Psr4Autoloader;
use Khill\FontAwesome\Exceptions\BadLabelException;
use Khill\FontAwesome\Exceptions\CollectionIconException;
Expand All @@ -26,12 +29,12 @@ class FontAwesome extends FontAwesomeHtmlEntity
/**
* FontAwesomePHP version
*/
const VERSION = '1.1.0';
const VERSION = '1.1.3';

/**
* FontAwesome Icon version
*/
const FA_VERSION = '4.4.0';
const FA_VERSION = '4.7.0';

/**
* Html string template to build the icon
Expand All @@ -58,9 +61,9 @@ class FontAwesome extends FontAwesomeHtmlEntity
*/
public static function css()
{
return '<link href="//netdna.bootstrapcdn.com/font-awesome/' .
return '<link rel="stylesheet" href="https://opensource.keycdn.com/fontawesome/' .
self::FA_VERSION .
'/css/font-awesome.min.css" rel="stylesheet">';
'/font-awesome.min.css" integrity="sha384-dNpIIXE8U05kAbPhy3G1cz+yZmTzA6CY8Vg/u2L9xRnHjJiAK76m2BIEaSEV+/aU" crossorigin="anonymous">';
}

/**
Expand All @@ -76,32 +79,13 @@ public function __construct($icon = null)

$loader = new Psr4Autoloader;
$loader->register();
$loader->addNamespace(__NAMESPACE__, __DIR__);
$loader->addNamespace('Khill\FontAwesome', __DIR__);
}

if ($icon !== null) {
$this->setIcon($icon);
}
}

/**
* Checks if running in composer environment
*
* This will true if the folder 'composer' is within the path to FontAwesomePHP.
*
* @codeCoverageIgnore
* @access private
* @since 1.1.0
* @return boolean
*/
private function usingComposer()
{
if (strpos(realpath(__FILE__), 'composer') !== false) {
return true;
} else {
return false;
}
}

/**
* Sets which icon to use
Expand Down Expand Up @@ -290,4 +274,23 @@ protected function output()

return sprintf(self::ICON_HTML, $classes, $attrs);
}

/**
* Checks if running in composer environment
*
* This will true if the folder 'composer' is within the path to FontAwesomePHP.
*
* @codeCoverageIgnore
* @access private
* @since 1.1.0
* @return boolean
*/
private function usingComposer()
{
if (strpos(realpath(__FILE__), 'composer') !== false) {
return true;
} else {
return false;
}
}
}
70 changes: 35 additions & 35 deletions src/FontAwesomeHtmlEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ class FontAwesomeHtmlEntity
*/
protected $CLASS_MAP = array(
'lg' => 'fa-lg',
'x2' => 'fa-2x',
'x3' => 'fa-3x',
'x4' => 'fa-4x',
'x5' => 'fa-5x',
'fixedWidth' => 'fa-fw',
'x2' => 'fa-2x', // Alias
'x3' => 'fa-3x', // Alias
'x4' => 'fa-4x', // Alias
'x5' => 'fa-5x', // Alias
'fw' => 'fa-fw',
'fixed' => 'fa-fw', // Alias
'fw' => 'fa-fw', // Alias
'fixedWidth' => 'fa-fw', // Alias
'spin' => 'fa-spin',
's' => 'fa-spin', // Alias
'border' => 'fa-border',
Expand Down Expand Up @@ -79,6 +79,35 @@ class FontAwesomeHtmlEntity
'r' => 'pull-right' // Alias
);

/**
* Magic method to assign transformation classes to the stack
*
* @param string $name Method called
* @param array $arguments
* @return self
* @throws InvalidTransformationClass
*/
public function __call($name, $arguments)
{
$this->classes[] = $this->classMapper($name);

if (isset($arguments[0])) {
$this->icon = $arguments[0];
}

return $this;
}

/**
* Outputs the FontAwesome object as an HTML string
*
* @return string HTML string of icon, stack, or list
*/
public function __toString()
{
return (string) $this->output();
}

/**
* Sets icon label
*
Expand Down Expand Up @@ -117,35 +146,6 @@ protected function classMapper($class)
throw new InvalidTransformationClass($class);
}

/**
* Magic method to assign transformation classes to the stack
*
* @param string $name Method called
* @param array $arguments
* @return self
* @throws InvalidTransformationClass
*/
public function __call($name, $arguments)
{
if (isset($arguments[0])) {
$this->icon = $arguments[0];
}

$this->classes[] = $this->classMapper($name);

return $this;
}

/**
* Outputs the FontAwesome object as an HTML string
*
* @return string HTML string of icon, stack, or list
*/
public function __toString()
{
return (string) $this->output();
}

/**
* Adds an attribute to the icon, useful for title or id
*
Expand Down

0 comments on commit 550e061

Please sign in to comment.