src/Splitter.php
public function split($css = null, $part = 1, $maxSelectors = self::MAX_SELECTORS_DEFAULT)
	{
		if (empty($css) && empty($this->css)) {
			return null;
		}

		if (!empty($css) && $this->css !== $css) {
			$this->css = $css;
		}

		$charset = $this->extractCharset($this->css);
		isset($charset) && $this->css = str_replace($charset, '', $this->css);
		if (empty($this->css)) {
			return null;
		}

		$this->parsedCss = $this->splitIntoBlocks($this->css);
		if (empty($this->parsedCss)) {
			return null;
		}

		$output    = $charset ? : '';
		$count     = 0;
		$partCount = 1;
		foreach ($this->parsedCss as $block) {
			$appliedMedia = false;
			foreach ($block['rules'] as $rule) {
				$tmpCount = $rule['count'];

				// we have a new part so let's reset and increase
				if (($count + $tmpCount) > $maxSelectors) {
					$partCount++;
					$count = 0;
				}

				$count += $tmpCount;
				if ($partCount < $part) {
					continue;
				}
				if ($partCount > $part) {
					break;
				}

				if (!$appliedMedia && isset($block['at-rule'])) {
					$output .= $block['at-rule'] . ' {';
					$appliedMedia = true;
				}
				$output .= $rule['rule'];
			}
			$appliedMedia && $output .= '}';
		}

		return $output;
	}
public function split($css = null, $part = 1, $maxSelectors = self::MAX_SELECTORS_DEFAULT)
	{
		if (empty($css) && empty($this->css)) {
			return null;
		}

		if (!empty($css) && $this->css !== $css) {
			$this->css = $css;
		}

		$charset = $this->extractCharset($this->css);
		isset($charset) && $this->css = str_replace($charset, '', $this->css);
		if (empty($this->css)) {
			return null;
		}

		$this->parsedCss = $this->splitIntoBlocks($this->css);
		if (empty($this->parsedCss)) {
			return null;
		}

		$output    = $charset ? : '';
		$count     = 0;
		$partCount = 1;
		foreach ($this->parsedCss as $block) {
			$appliedMedia = false;
			foreach ($block['rules'] as $rule) {
				$tmpCount = $rule['count'];

				// we have a new part so let's reset and increase
				if (($count + $tmpCount) > $maxSelectors) {
					$partCount++;
					$count = 0;
				}

				$count += $tmpCount;
				if ($partCount < $part) {
					continue;
				}
				if ($partCount > $part) {
					break;
				}

				if (!$appliedMedia && isset($block['at-rule'])) {
					$output .= $block['at-rule'] . ' {';
					$appliedMedia = true;
				}
				$output .= $rule['rule'];
			}
			$appliedMedia && $output .= '}';
		}

		return $output;
	}
public function split ( $ css = null , $ part = 1 , $ maxSelectors = self :: MAX_SELECTORS_DEFAULT ) { if ( empty ( $ css ) && empty ( $ this -> css ) ) { return null ; } if ( ! empty ( $ css ) && $ this -> css !== $ css ) { $ this -> css = $ css ; } $ charset = $ this -> extractCharset ( $ this -> css ) ; isset ( $ charset ) && $ this -> css = str_replace ( $ charset , '' , $ this -> css ) ; if ( empty ( $ this -> css ) ) { return null ; } $ this -> parsedCss = $ this -> splitIntoBlocks ( $ this -> css ) ; if ( empty ( $ this -> parsedCss ) ) { return null ; } $ output = $ charset ? : '' ; $ count = 0 ; $ partCount = 1 ; foreach ( $ this -> parsedCss as $ block ) { $ appliedMedia = false ; foreach ( $ block [ 'rules' ] as $ rule ) { $ tmpCount = $ rule [ 'count' ] ; // we have a new part so let's reset and increase if ( ( $ count + $ tmpCount ) > $ maxSelectors ) { $ partCount ++ ; $ count = 0 ; } $ count += $ tmpCount ; if ( $ partCount < $ part ) { continue ; } if ( $ partCount > $ part ) { break ; } if ( ! $ appliedMedia && isset ( $ block [ 'at-rule' ] ) ) { $ output .= $ block [ 'at-rule' ] . ' {' ; $ appliedMedia = true ; } $ output .= $ rule [ 'rule' ] ; } $ appliedMedia && $ output .= '}' ; } return $ output ; }
Returns the requested part of the split css

@param string $css
@param int    $part
@param int    $maxSelectors
@return null|string
Returns the requested part of the split css