<commit_before><?php

/**
 * Alfred Bundler Icon and Color API file
 *
 * Interface for downloading, loading, and manipulating image resources to
 * be used with the PHP implementation of the Alfred Bundler.
 *
 * This file is part of the Alfred Bundler, released under the MIT licence.
 * Copyright (c) 2014 The Alfred Bundler Team
 * See https://github.com/shawnrice/alfred-bundler for more information
 *
 * @copyright  The Alfred Bundler Team 2014
 * @license    http://opensource.org/licenses/MIT  MIT
 * @version    Taurus 1
 * @link       http://shawnrice.github.io/alfred-bundler
 * @package    AlfredBundler
 * @since      File available since Taurus 1
 */

if ( ! class_exists( 'AlfredBundlerIcon' ) ) :
/**
 *
 * A class used to get / manipulate icons...
 *
 * @package AlfredBundler
 * @since   Class available since Taurus 1
 * @TODO document further
 */
class AlfredBundlerIcon {

  public  $background;
  public  $data;
  public  $cache;


  /**
   * Sets the variables to deal with icons
   *
   * @todo decide exactly where the cache is going to live
   *
   * @since Taurus 1
   *
   * @param  object  $bundler   the bundler object that instantiates this
   */
  public function __construct( $bundler ) {

    $this->mime       = finfo_open( FILEINFO_MIME_TYPE );
    $this->bundler    = $bundler; // in case we need any of the variables...
    $this->data       = $this->bundler->data;
    // $this->cache      = $cache;
    $this->colors     = array();
    $this->fallback   = $this->data . '/bundler/meta/icons/default.png';

    $this->setBackground();

    $this->cache = $bundler->cache . '/color';

  }



/*****************************************************************************
 * BEGIN SETUP FUNCTIONS
 ****************************************************************************/

  /**
   * Creates necessary folders for icons
   *
   * @since Taurus 1
   *
   */
  private function setup() {

    if ( ! file_exists( $this->data . '/data' ) )
      mkdir( $this->data . '/data' );

    if ( ! file_exists( $this->cache ) )
      mkdir( $this->cache, 0775, TRUE );

  }


  /**
   * Set the 'background' variable to either 'light' or 'dark'
   *
   * As of Alfred v2.4 Build 277, environmental variables are available that
   * expose the color of the theme background as sRGBa. If those variables
   * are accessible, then we set the background with them.
   *
   * Otherwise, we fallback to a utility that comes with the bundler called
   * 'LightOrDark' that reads the NSColor Object in the plist that Alfred
   * uses to store the themes, and then it returns the value 'light' or 'dark'.
   *
   * @link [http://www.alfredforum.com/topic/4716-some-new-alfred-script-environment-variables-coming-in-alfred-24/] [Alfred 2.4 Environmental Variables]
   *
   * @since Taurus 1
   *
   */
  private function setBackground() {

    if ( isset( $_ENV[ 'alfred_version' ] ) ) {
      // Current Version >= v2.4:277
      $this->setBackgroundFromEnv();
    } else {
      // Current Version < v2.4:277 -- or -- no env vars are set. Maybe
      // you're running this outside of Alfred, eh?
      $this->setBackgroundFromUtil();
    }
    // Make sure we've set the background
    $this->validateBackground();

  }

  /**
   * Sets the background to 'light' or 'dark' based on environmental variables
   * based on a luminance calculation
   *
   * @see setBackground()
   * @see setBackgroundFromUtil()
   * @see getLuminance()
   *
   * @since Taurus 1
   *
   */
  private function setBackgroundFromEnv() {
    $pattern = "/rgba\(([0-9]{3}),([0-9]{3}),([0-9]{3}),([0-9.]{4,})\)/";
    preg_match_all( $pattern, $_ENV[ 'alfred_theme_background' ], $matches );

    $this->background = $this->getLuminance(  array( 'r' => $matches[1][0],
                                                     'g' => $matches[2][0],
                                                     'b' => $matches[3][0] ) );

  }
<commit_msg>fixed regex for rgb values for background<commit_after><?php

/**
 * Alfred Bundler Icon and Color API file
 *
 * Interface for downloading, loading, and manipulating image resources to
 * be used with the PHP implementation of the Alfred Bundler.
 *
 * This file is part of the Alfred Bundler, released under the MIT licence.
 * Copyright (c) 2014 The Alfred Bundler Team
 * See https://github.com/shawnrice/alfred-bundler for more information
 *
 * @copyright  The Alfred Bundler Team 2014
 * @license    http://opensource.org/licenses/MIT  MIT
 * @version    Taurus 1
 * @link       http://shawnrice.github.io/alfred-bundler
 * @package    AlfredBundler
 * @since      File available since Taurus 1
 */

if ( ! class_exists( 'AlfredBundlerIcon' ) ) :
/**
 *
 * A class used to get / manipulate icons...
 *
 * @package AlfredBundler
 * @since   Class available since Taurus 1
 * @TODO document further
 */
class AlfredBundlerIcon {

  public  $background;
  public  $data;
  public  $cache;


  /**
   * Sets the variables to deal with icons
   *
   * @todo decide exactly where the cache is going to live
   *
   * @since Taurus 1
   *
   * @param  object  $bundler   the bundler object that instantiates this
   */
  public function __construct( $bundler ) {

    $this->mime       = finfo_open( FILEINFO_MIME_TYPE );
    $this->bundler    = $bundler; // in case we need any of the variables...
    $this->data       = $this->bundler->data;
    // $this->cache      = $cache;
    $this->colors     = array();
    $this->fallback   = $this->data . '/bundler/meta/icons/default.png';

    $this->setBackground();

    $this->cache = $bundler->cache . '/color';

  }



/*****************************************************************************
 * BEGIN SETUP FUNCTIONS
 ****************************************************************************/

  /**
   * Creates necessary folders for icons
   *
   * @since Taurus 1
   *
   */
  private function setup() {

    if ( ! file_exists( $this->data . '/data' ) )
      mkdir( $this->data . '/data' );

    if ( ! file_exists( $this->cache ) )
      mkdir( $this->cache, 0775, TRUE );

  }


  /**
   * Set the 'background' variable to either 'light' or 'dark'
   *
   * As of Alfred v2.4 Build 277, environmental variables are available that
   * expose the color of the theme background as sRGBa. If those variables
   * are accessible, then we set the background with them.
   *
   * Otherwise, we fallback to a utility that comes with the bundler called
   * 'LightOrDark' that reads the NSColor Object in the plist that Alfred
   * uses to store the themes, and then it returns the value 'light' or 'dark'.
   *
   * @link [http://www.alfredforum.com/topic/4716-some-new-alfred-script-environment-variables-coming-in-alfred-24/] [Alfred 2.4 Environmental Variables]
   *
   * @since Taurus 1
   *
   */
  private function setBackground() {

    if ( isset( $_ENV[ 'alfred_version' ] ) ) {
      // Current Version >= v2.4:277
      $this->setBackgroundFromEnv();
    } else {
      // Current Version < v2.4:277 -- or -- no env vars are set. Maybe
      // you're running this outside of Alfred, eh?
      $this->setBackgroundFromUtil();
    }
    // Make sure we've set the background
    $this->validateBackground();

  }

  /**
   * Sets the background to 'light' or 'dark' based on environmental variables
   * based on a luminance calculation
   *
   * @see setBackground()
   * @see setBackgroundFromUtil()
   * @see getLuminance()
   *
   * @since Taurus 1
   *
   */
  private function setBackgroundFromEnv() {
    $pattern = "/rgba\(([0-9]{1,3}),([0-9]{1,3}),([0-9]{1,3}),([0-9.]{4,})\)/";
    preg_match_all( $pattern, $_ENV[ 'alfred_theme_background' ], $matches );

    $this->background = $this->getLuminance(  array( 'r' => $matches[1][0],
                                                     'g' => $matches[2][0],
                                                     'b' => $matches[3][0] ) );

  }

{'fraction_non_alphanumeric': 0.16435068216270843, 'fraction_numerical': 0.015538150581101567, 'mean_word_length': 2.6333180357962367, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 53, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2884710', 'n_tokens_mistral': 2482, 'n_tokens_neox': 2332, 'n_words': 722}